/* * ValueTable.hpp * * Created on: 21 окт. 2019 г. * Author: LeonidTitov */ #ifndef SOURCE_SCHEMATIC_VALUETABLE_HPP_ #define SOURCE_SCHEMATIC_VALUETABLE_HPP_ #include "../systemic/IValue.hpp" #include "../systemic/IStatus.hh" namespace schematic { template class ValueTable : public systemic::IValue { public: typedef T Value; typedef unsigned Index; static const Index val_size = 1ul << size; static const Index sts_size = size; ValueTable( systemic::IStatus * statuses[sts_size] ); void set( Value value, Index combination_index ); virtual operator T() const; protected: Value values[val_size]; systemic::IStatus * statuses[sts_size]; Index index() const; }; } template inline schematic::ValueTable::ValueTable( systemic::IStatus * statuses[sts_size] ) { for(Index i = 0; i < sts_size; i++ ) this->statuses[i] = statuses[i]; } template inline void schematic::ValueTable::set( Value value, Index combination_index ) { if( combination_index < val_size ) values[combination_index] = value; } template inline schematic::ValueTable::operator T() const { return values[ index() ]; } template inline typename schematic::ValueTable::Index schematic::ValueTable::index() const { Index id = 0; for( Index i = 0; i < sts_size; i++ ) id += *statuses[i] ? ( static_cast(1) << i ) : 0; return id; } #endif /* SOURCE_SCHEMATIC_VALUETABLE_HPP_ */