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