CVariableNames.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_ring_CVariableNames_h_
#define polybori_ring_CVariableNames_h_
// include basic definitions
#include <polybori/pbori_defs.h>
// get standard vector functionality
#include <vector>
// get standard string functionalities
#include <string>
#include <sstream>
BEGIN_NAMESPACE_PBORI
class CVariableNames {
public:
typedef CTypes::size_type size_type;
typedef CTypes::idx_type idx_type;
typedef CTypes::vartext_type vartext_type;
typedef std::string varname_type;
typedef std::vector<varname_type> storage_type;
typedef storage_type::reference reference;
typedef vartext_type const_reference;
typedef CVariableNames self;
CVariableNames(size_type nvars): m_data(nvars) { reset(); }
CVariableNames(const self& rhs): m_data(rhs.m_data) { }
void reset(idx_type idx = 0);
const_reference operator[](idx_type idx) const {
if PBORI_UNLIKELY(size_type(idx) >= m_data.size())
return undefName();
return m_data[idx].c_str();
}
void set(idx_type idx, const varname_type& varname) {
size_type nlen = m_data.size();
if PBORI_UNLIKELY((size_type)idx >= nlen) {
m_data.resize((size_type)idx + 1);
reset((idx_type)nlen);
}
m_data[idx] = varname;
}
protected:
static const_reference undefName() { return "UNDEF"; }
private:
storage_type m_data;
};
inline
void CVariableNames::reset(idx_type idx) {
idx_type nlen = (idx_type)m_data.size();
for (; idx < nlen; ++idx){
std::ostringstream sstrg;
sstrg << "x(" << idx << ')';
m_data[idx] = sstrg.str();
}
}
END_NAMESPACE_PBORI
#endif