MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/schematic/ValueTable.hpp
2024-06-07 11:12:56 +03:00

79 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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_ */