PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_factories_VariableBlock_h_ 00017 #define polybori_factories_VariableBlock_h_ 00018 00019 // include basic definitions 00020 #include <polybori/pbori_defs.h> 00021 #include <polybori/factories/VariableFactory.h> 00022 00023 BEGIN_NAMESPACE_PBORI 00024 00025 class VariableIndexException{ 00026 00027 }; 00028 00035 class VariableBlock: 00036 protected VariableFactory{ 00037 00039 typedef VariableBlock self; 00040 00041 public: 00042 typedef VariableFactory base; 00043 typedef base::value_type var_type; 00044 00045 typedef var_type::ring_type ring_type; 00046 typedef var_type::idx_type idx_type; 00047 00049 VariableBlock(idx_type size, idx_type start_index, idx_type offset, 00050 bool reverse, const ring_type& ring): 00051 base(ring), 00052 m_start_index(start_index), 00053 m_last (start_index + size - 1), m_offset(offset), m_reverse(reverse) { } 00054 00056 VariableBlock(const self& rhs): 00057 base(rhs), 00058 m_start_index(rhs.m_start_index), 00059 m_last(rhs.m_last), m_offset(rhs.m_offset), m_reverse(rhs.m_reverse) { } 00060 00062 ~VariableBlock() {} 00063 00065 var_type operator()(idx_type i){ 00066 if PBORI_UNLIKELY( (i > m_last) || (i < m_start_index) ){ 00067 throw VariableIndexException(); 00068 } 00069 return 00070 base::operator()(m_offset + (m_reverse? m_last - i: i - m_start_index)); 00071 } 00072 00073 protected: 00074 const idx_type m_start_index; 00075 const idx_type m_last; 00076 const idx_type m_offset; 00077 const bool m_reverse; 00078 }; 00079 00080 END_NAMESPACE_PBORI 00081 00082 #endif /* polybori_factories_VariableBlock_h_*/