00001
00002
00042
00043
00044
00045 #include "pbori_defs.h"
00046
00047
00048 #include <vector>
00049
00050
00051 #include <string>
00052 #include <sstream>
00053
00054
00055 #ifndef CVariableNames_h_
00056 #define CVariableNames_h_
00057
00058 BEGIN_NAMESPACE_PBORI
00059
00060 class CVariableNames {
00061 public:
00062
00064
00065 typedef CTypes::size_type size_type;
00066 typedef CTypes::idx_type idx_type;
00068
00070 typedef CTypes::vartext_type vartext_type;
00071
00073 typedef std::string varname_type;
00074
00076 typedef std::vector<varname_type> storage_type;
00077
00079 typedef storage_type::reference reference;
00080
00082 typedef vartext_type const_reference;
00083
00085 typedef CVariableNames self;
00086
00088 CVariableNames(size_type nvars): m_data(nvars) { reset(); }
00089
00091 CVariableNames(const self& rhs): m_data(rhs.m_data) { }
00092
00094 void reset(idx_type idx = 0);
00095
00097 const_reference operator[](idx_type idx) const {
00098
00099 if UNLIKELY(size_type(idx) >= m_data.size())
00100 return undefName();
00101 return m_data[idx].c_str();
00102 }
00103
00105 void set(idx_type idx, const varname_type& varname) {
00106
00107 size_type nlen = m_data.size();
00108
00109 if UNLIKELY((size_type)idx >= nlen) {
00110 m_data.resize((size_type)idx + 1);
00111 reset((idx_type)nlen);
00112 }
00113
00114 m_data[idx] = varname;
00115 }
00116
00117 protected:
00118 static const_reference undefName() { return "UNDEF"; }
00119
00120 private:
00121 storage_type m_data;
00122 };
00123
00124 inline
00125 void CVariableNames::reset(idx_type idx) {
00126
00127 idx_type nlen = (idx_type)m_data.size();
00128
00129 for (; idx < nlen; ++idx){
00130 std::ostringstream sstrg;
00131 sstrg << "x(" << idx << ')';
00132 m_data[idx] = sstrg.str();
00133 }
00134 }
00135
00136
00137 END_NAMESPACE_PBORI
00138
00139 #endif