79 lines
1.6 KiB
C++
79 lines
1.6 KiB
C++
/*
|
|
* 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<typename T, unsigned size>
|
|
class ValueTable : public systemic::IValue<T> {
|
|
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<typename T, unsigned size>
|
|
inline schematic::ValueTable<T, size>::ValueTable( systemic::IStatus * statuses[sts_size] ) {
|
|
|
|
for(Index i = 0; i < sts_size; i++ )
|
|
this->statuses[i] = statuses[i];
|
|
|
|
}
|
|
|
|
template<typename T, unsigned size>
|
|
inline void schematic::ValueTable<T, size>::set( Value value, Index combination_index ) {
|
|
|
|
if( combination_index < val_size )
|
|
values[combination_index] = value;
|
|
|
|
}
|
|
|
|
template<typename T, unsigned size>
|
|
inline schematic::ValueTable<T, size>::operator T() const {
|
|
|
|
return values[ index() ];
|
|
|
|
}
|
|
|
|
template<typename T, unsigned size>
|
|
inline typename schematic::ValueTable<T, size>::Index schematic::ValueTable<T, size>::index() const {
|
|
|
|
Index id = 0;
|
|
|
|
for( Index i = 0; i < sts_size; i++ )
|
|
id += *statuses[i] ? ( static_cast<Index>(1) << i ) : 0;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
#endif /* SOURCE_SCHEMATIC_VALUETABLE_HPP_ */
|