libraries / Mitov / Mitov_LogicGates.hon commit Added link to project report (97a3ba0)
   1////////////////////////////////////////////////////////////////////////////////
   2//                                                                            //
   3//     This software is supplied under the terms of a license agreement or    //
   4//     nondisclosure agreement with Mitov Software and may not be copied      //
   5//     or disclosed except in accordance with the terms of that agreement.    //
   6//         Copyright(c) 2002-2016 Mitov Software. All Rights Reserved.        //
   7//                                                                            //
   8////////////////////////////////////////////////////////////////////////////////
   9
  10#ifndef _MITOV_LOGIC_GATES_h
  11#define _MITOV_LOGIC_GATES_h
  12
  13#include <Mitov.h>
  14
  15namespace Mitov
  16{
  17        template<int C_NUM_INPUTS> class BooleanOr : public CommonMultiInput<bool, C_NUM_INPUTS>
  18        {
  19                typedef CommonMultiInput<bool, C_NUM_INPUTS> inherited;
  20
  21        protected:
  22                virtual bool CalculateOutput() override
  23                {
  24                        bool AValue = false;
  25                        for ( int i = 0; i < C_NUM_INPUTS; ++i )
  26                                AValue |= inherited::InputPins[ i ].Value;
  27
  28                        return AValue;
  29                }
  30
  31        };
  32//---------------------------------------------------------------------------
  33        template<int C_NUM_INPUTS> class BooleanAnd : public CommonMultiInput<bool, C_NUM_INPUTS>
  34        {
  35                typedef CommonMultiInput<bool, C_NUM_INPUTS> inherited;
  36
  37        protected:
  38                virtual bool CalculateOutput() override
  39                {
  40                        bool AValue = (C_NUM_INPUTS > 0);
  41                        for ( int i = 0; i < C_NUM_INPUTS; ++i )
  42                                AValue &= inherited::InputPins[ i ].Value;
  43
  44                        return AValue;
  45                }
  46
  47        };
  48//---------------------------------------------------------------------------
  49        template<int C_NUM_INPUTS> class BooleanXor : public CommonMultiInput<bool, C_NUM_INPUTS>
  50        {
  51                typedef CommonMultiInput<bool, C_NUM_INPUTS> inherited;
  52
  53        protected:
  54                virtual bool CalculateOutput() override
  55                {
  56                        bool AValue = false;
  57                        for ( int i = 0; i < C_NUM_INPUTS; ++i )
  58                                AValue ^= inherited::InputPins[ i ].Value;
  59
  60                        return AValue;
  61                }
  62
  63        };
  64//---------------------------------------------------------------------------
  65        class BooleanInverter : public CommonTypedFilter<bool>
  66        {
  67        protected:
  68                virtual bool FilterValue(bool AValue) override
  69                {
  70                        return ! AValue;
  71                }
  72        };
  73//---------------------------------------------------------------------------
  74
  75}
  76
  77#endif