PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00013 //***************************************************************************** 00014 00015 #ifndef polybori_ring_CVariableNames_h_ 00016 #define polybori_ring_CVariableNames_h_ 00017 00018 // include basic definitions 00019 #include <polybori/pbori_defs.h> 00020 00021 // get standard vector functionality 00022 #include <vector> 00023 00024 // get standard string functionalities 00025 #include <string> 00026 #include <sstream> 00027 00028 BEGIN_NAMESPACE_PBORI 00029 00030 class CVariableNames { 00031 public: 00032 00034 00035 typedef CTypes::size_type size_type; 00036 typedef CTypes::idx_type idx_type; 00038 00040 typedef CTypes::vartext_type vartext_type; 00041 00043 typedef std::string varname_type; 00044 00046 typedef std::vector<varname_type> storage_type; 00047 00049 typedef storage_type::reference reference; 00050 00052 typedef vartext_type const_reference; 00053 00055 typedef CVariableNames self; 00056 00058 CVariableNames(size_type nvars): m_data(nvars) { reset(); } 00059 00061 CVariableNames(const self& rhs): m_data(rhs.m_data) { } 00062 00064 void reset(idx_type idx = 0); 00065 00067 const_reference operator[](idx_type idx) const { 00068 00069 if PBORI_UNLIKELY(size_type(idx) >= m_data.size()) 00070 return undefName(); 00071 return m_data[idx].c_str(); 00072 } 00073 00075 void set(idx_type idx, const varname_type& varname) { 00076 00077 size_type nlen = m_data.size(); 00078 00079 if PBORI_UNLIKELY((size_type)idx >= nlen) { 00080 m_data.resize((size_type)idx + 1); 00081 reset((idx_type)nlen); 00082 } 00083 00084 m_data[idx] = varname; 00085 } 00086 00087 protected: 00088 static const_reference undefName() { return "UNDEF"; } 00089 00090 private: 00091 storage_type m_data; 00092 }; 00093 00094 inline 00095 void CVariableNames::reset(idx_type idx) { 00096 00097 idx_type nlen = (idx_type)m_data.size(); 00098 00099 for (; idx < nlen; ++idx){ 00100 std::ostringstream sstrg; 00101 sstrg << "x(" << idx << ')'; 00102 m_data[idx] = sstrg.str(); 00103 } 00104 } 00105 00106 00107 END_NAMESPACE_PBORI 00108 00109 #endif