PolyBoRi
CVariableNames.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
42 //*****************************************************************************
43 
44 // include basic definitions
45 #include "pbori_defs.h"
46 
47 // get standard vector functionality
48 #include <vector>
49 
50 // get standard string functionalities
51 #include <string>
52 #include <sstream>
53 
54 
55 #ifndef CVariableNames_h_
56 #define CVariableNames_h_
57 
59 
61 public:
62 
64 
68 
71 
73  typedef std::string varname_type;
74 
76  typedef std::vector<varname_type> storage_type;
77 
79  typedef storage_type::reference reference;
80 
83 
85  typedef CVariableNames self;
86 
88  CVariableNames(size_type nvars): m_data(nvars) { reset(); }
89 
91  CVariableNames(const self& rhs): m_data(rhs.m_data) { }
92 
94  void reset(idx_type idx = 0);
95 
98 
99  if UNLIKELY(size_type(idx) >= m_data.size())
100  return undefName();
101  return m_data[idx].c_str();
102  }
103 
105  void set(idx_type idx, const varname_type& varname) {
106 
107  size_type nlen = m_data.size();
108 
109  if UNLIKELY((size_type)idx >= nlen) {
110  m_data.resize((size_type)idx + 1);
111  reset((idx_type)nlen);
112  }
113 
114  m_data[idx] = varname;
115  }
116 
117 protected:
118  static const_reference undefName() { return "UNDEF"; }
119 
120 private:
121  storage_type m_data;
122 };
123 
124 inline
125 void CVariableNames::reset(idx_type idx) {
126 
127  idx_type nlen = (idx_type)m_data.size();
128 
129  for (; idx < nlen; ++idx){
130  std::ostringstream sstrg;
131  sstrg << "x(" << idx << ')';
132  m_data[idx] = sstrg.str();
133  }
134 }
135 
136 
138 
139 #endif