32 mMyName(
"SymbolTable"),
33 mMaxIndex(std::numeric_limits<
Idx>::max()),
64 mMaxIndex=std::numeric_limits<Idx>::max();
82 if(index <= std::numeric_limits<Idx>::max()) {
86 std::stringstream errstr;
87 errstr <<
"symboltable overflow in \"" <<
mMyName <<
"\"";
88 throw Exception(
"SymbolTable::MaxIndex(inde))", errstr.str(), 40);
98 if(rName==
"")
return false;
99 for(std::size_t cp=0;cp<rName.size();cp++) {
101 if(iscntrl(ch))
return false;
102 if(isspace(ch))
return false;
103 if(ch==
'"')
return false;
104 if(ch==
'#')
return false;
105 if(isdigit(ch))
continue;
106 if(isalpha(ch))
continue;
107 if(isprint(ch))
continue;
115 if(!
Exists(rName))
return (rName);
117 std::string name=rName;
118 std::string bname=rName;
120 std::size_t up = bname.find_last_of(
"_");
121 if(up != std::string::npos) {
123 for(std::size_t dp=up+1;dp<bname.size();dp++)
124 if(!isdigit(bname[dp])) ad=
false;
140 std::stringstream errstr;
141 errstr <<
"symboltable overflow in \"" <<
mMyName <<
"\"";
142 throw Exception(
"SymbolTable::InsEntry(index,name))", errstr.str(), 40);
145 if((nidx!=0) && (nidx!=index)) {
146 std::stringstream errstr;
147 errstr <<
"Name " << rName <<
" allready exists in \"" <<
mMyName <<
"\"";
148 throw Exception(
"SymbolTable::InsEntry(index,name)", errstr.str(), 41);
150 std::string idxname=
Symbol(index);
151 if((idxname !=
"") && (idxname != rName)) {
152 std::stringstream errstr;
153 errstr <<
"Index " << index <<
" allready exists in \"" <<
mMyName <<
"\"";
154 throw Exception(
"SymbolTable::InsEntry(index,name)", errstr.str(), 42);
157 std::stringstream errstr;
158 errstr <<
"Name " << rName <<
" is not a valid symbol";
159 throw Exception(
"SymbolTable::InsEntry(index,name)", errstr.str(), 43);
172 if( index != 0)
return index;
184 if((nidx!=0) && (nidx!=index)) {
185 std::stringstream errstr;
186 errstr <<
"Name " << rName <<
" allready exists in \"" <<
mMyName <<
"\"";
187 throw Exception(
"SymbolTable::SetEntry(index,name)", errstr.str(), 41);
190 std::stringstream errstr;
191 errstr <<
"Name " << rName <<
" is not a valid symbol";
192 throw Exception(
"SymbolTable::SetEntry(index,name)", errstr.str(), 43);
195 std::map<Idx,std::string>::iterator nit =
mNameMap.find(index);
213 std::map<Idx,std::string>::iterator it =
mNameMap.find(index);
221 std::map<std::string,Idx>::iterator it =
mIndexMap.find(rName);
231 if(
Size()==0)
return;
233 std::map<Idx,std::string>::iterator it, oit;
244 std::map<std::string,Idx>::const_iterator it =
mIndexMap.find(rName);
253 std::map<Idx,std::string>::const_iterator it =
mNameMap.find(index);
264 std::map<Idx,std::string>::const_iterator it =
mNameMap.find(index);
270 std::map<std::string,Idx>::const_iterator it =
mIndexMap.find(rName);
287 std::string label=rLabel;
288 if(label==
"") label=
"SymbolTable";
298 std::map< std::string, Idx >::const_iterator sit =
mIndexMap.begin();
316 std::string label=rLabel;
317 if(label==
"") label=
"SymbolTable";
323 while(!rTr.
Eos(label)) {
A SymbolTable associates sybolic names with indices.
void RestrictDomain(const IndexSet &rDomain)
Restrict to specified indicees.
Idx mNextIndex
Largest used index + 1.
std::map< Idx, std::string > mNameMap
Name lookup map.
void SetDefaultSymbol(Idx index)
Set default names ("1", "2", "3", ...) for index.
Idx LastIndex(void) const
Get the largest index in use.
std::map< std::string, Idx > mIndexMap
Index lookup map.
Idx mMaxIndex
Upper limit (incl)
static SymbolTable * GlobalEventSymbolTablep(void)
Get Static Symboltable ref (initialize on first use pattern)
std::string Symbol(Idx index) const
Symbolic name lookup.
void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Symboltable token io.
const std::string & Name(void) const
Return name of SymbolTable.
void Clear(void)
Clear all entries.
static bool ValidSymbol(const std::string &rName)
Test validiy of candidate symbol.
Idx MaxIndex(void) const
Get maximum index which this SymbolTable accepts.
void ClrEntry(Idx index)
Delete entry by index.
void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Symboltable token io.
bool Exists(Idx index) const
Test existence of index.
void DoAssign(const SymbolTable &rSrc)
assign my members
std::string UniqueSymbol(const std::string &rName) const
Create unique symbolic name by adding an underscore and extra digits.
void SetEntry(Idx index, const std::string &rName)
Set symbolic name for existing entry.
SymbolTable(void)
Creates a new SymbolTable.
Idx InsEntry(Idx index, const std::string &rName)
Add new entry (aka symbolic name and index) to symboltable,.
Idx Size(void) const
Size of symboltabel.
std::string mMyName
Name of the SymbolTable.
Idx Index(const std::string &rName) const
Index lookup.
A TokenReader reads sequential tokens from a file or string.
long int ReadInteger(void)
Read integer token.
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
std::string ReadString(void)
Read string token.
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteString(const std::string &rString)
Write string.
void WriteEnd(const std::string &rLabel)
Write end label.
int Columns(void) const
Get number of columns in a line.
void WriteInteger(Idx index)
Write non negative integer.
void WriteBegin(const std::string &rLabel)
Write begin label.
Base class of all libFAUDES objects that participate in the run-time interface.
bool Empty(void) const
Test whether if the TBaseSet is Empty.
bool Exists(const T &rElem) const
Test existence of element.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
std::string ToStringInteger(Int number)
integer to string