00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _bddSymTab_h_
00032 #define _bddSymTab_h_
00033
00034 #include "reprNUMBER.h"
00035 #include "relObject.h"
00036
00037 #include <string>
00038 #include <map>
00039 #include <set>
00040 #include <vector>
00041 #include <cassert>
00042 using namespace std;
00043
00044
00060 class bddSymTab : private relObject
00061 {
00062 private:
00063
00067 unsigned mBitNr;
00068
00072 map<string, unsigned> mAttributes;
00074 map<unsigned, string> mPositions;
00075
00080 map<string, unsigned> mAttributeNumbers;
00082 vector<string> mAttributeValues;
00083
00085 set<string> mIsQuoted;
00086
00087 private:
00089 void operator,(const bddSymTab&);
00090 void operator=(const bddSymTab&);
00091 bddSymTab(const bddSymTab&);
00092
00093 public:
00094
00095 bddSymTab()
00096 {}
00097
00098 ~bddSymTab()
00099 {}
00100
00101
00102 public:
00103
00106 void
00107 initValueUniverse(set<string>& pValueUniverse)
00108 {
00109 if (pValueUniverse.size() <= 1) {
00110 mBitNr = 1;
00111 }
00112 else {
00113
00114 mBitNr = 0;
00115 unsigned lMaxValueCopy = pValueUniverse.size() - 1;
00116 while (lMaxValueCopy > 0)
00117 {
00118 lMaxValueCopy /= 2;
00119 ++mBitNr;
00120 }
00121 }
00122
00123
00124 mAttributeValues.clear();
00125 for( set<string>::const_iterator
00126 lIt = pValueUniverse.begin();
00127 lIt != pValueUniverse.end();
00128 ++lIt)
00129 {
00130 mAttributeNumbers[*lIt] = mAttributeValues.size();
00131 mAttributeValues.push_back(*lIt);
00132 }
00133 }
00134
00135
00136 public:
00137
00139 unsigned
00140 getBitNr() const
00141 { return mBitNr; }
00142
00144 unsigned
00145 getUniverseSize() const
00146 { return mAttributeValues.size(); }
00147
00148 void
00149 setQuoted(const string pAttribute)
00150 { mIsQuoted.insert(pAttribute); }
00151
00152 bool
00153 isQuoted(const string pAttribute) const
00154 { return mIsQuoted.find(pAttribute) != mIsQuoted.end(); }
00155
00157 bool
00158 isValueGood(const string& pAttributeValue) const
00159 {
00160 return mAttributeNumbers.find(pAttributeValue) != mAttributeNumbers.end();
00161 }
00162
00163 unsigned
00164 getAttributePos(const string& pAttribute) const
00165 {
00166 map<string, unsigned>::const_iterator it = mAttributes.find(pAttribute);
00167
00168 assert(it != mAttributes.end());
00169 return it->second * getBitNr();
00170 }
00171
00174 unsigned
00175 getValueNum(const string& pAttributeValue) const
00176 {
00177 map<string, unsigned>::const_iterator
00178 lIt = mAttributeNumbers.find(pAttributeValue);
00179
00180 assert(lIt != mAttributeNumbers.end());
00181 return lIt->second;
00182 }
00183
00184 string
00185 getAttributeValue(unsigned pNum) const
00186 {
00187 assert(pNum < mAttributeValues.size());
00188 return mAttributeValues[pNum];
00189 }
00190
00191 public:
00192
00195 void
00196 addAttribute(const string& pAttribute)
00197 {
00198 assert(pAttribute != "");
00199
00200 if( mAttributes.find(pAttribute) == mAttributes.end() ) {
00201 unsigned lAttrNum = mAttributes.size();
00202
00203 while (mPositions.find(lAttrNum) != mPositions.end()) {
00204 if (lAttrNum < UINT_MAX) {
00205 ++lAttrNum;
00206 } else {
00207 cerr << "Error: Maximum number of attributes exceeded."
00208 << endl;
00209 exit(EXIT_FAILURE);
00210 }
00211 }
00212 mAttributes[pAttribute] = lAttrNum;
00213 mPositions[lAttrNum] = pAttribute;
00214 }
00215 }
00216
00219 void
00220 removeAttribute(const string& pAttribute)
00221 {
00222 assert(mAttributes.find(pAttribute) != mAttributes.end());
00223 mPositions.erase(mAttributes[pAttribute]);
00224 mAttributes.erase(pAttribute);
00225 }
00226
00230 void
00231 removeUserAttributes(const char pAttributePrefix)
00232 {
00233 vector<string> lToRemove;
00234
00235 for(map<unsigned, string>::const_iterator lIt = mPositions.begin();
00236 lIt != mPositions.end();
00237 ++lIt)
00238 {
00239 if( (lIt->second)[0] != pAttributePrefix )
00240 {
00241 lToRemove.push_back(lIt->second);
00242 }
00243 }
00244
00245 for(vector<string>::const_iterator lIt = lToRemove.begin();
00246 lIt != lToRemove.end();
00247 ++lIt)
00248 {
00249 removeAttribute(*lIt);
00250 }
00251 }
00252
00253 const map<unsigned,string>
00254 computeVariableOrder(const set<string>& pAttributes) const
00255 {
00256 map<unsigned,string> result;
00257 for (set<string>::const_iterator it = pAttributes.begin();
00258 it != pAttributes.end();
00259 ++it)
00260 {
00261 result[getAttributePos(*it)] = *it;
00262 }
00263 return result;
00264 }
00265
00266 public:
00267
00268 void printValueNames(ostream& pS) const
00269 {
00270 pS << "VALUES -> NUMBERS :" << endl
00271 << "{" << endl;
00272 for (map<string, unsigned>::const_iterator
00273 lValueIt = mAttributeNumbers.begin();
00274 lValueIt != mAttributeNumbers.end();
00275 ++lValueIt)
00276 {
00277 pS << "(\"" << lValueIt->first << "\" -> "
00278 << lValueIt->second << "), ";
00279 }
00280 pS << "}" << endl;
00281
00282
00283 pS << "NUMBERS -> VALUES :" << endl
00284 << "{" << endl;
00285 for (vector<string>::const_iterator
00286 lValueIt = mAttributeValues.begin();
00287 lValueIt != mAttributeValues.end();
00288 ++lValueIt)
00289 {
00290 pS << "(" << lValueIt - mAttributeValues.begin() << " -> \""
00291 << *lValueIt << "\"), ";
00292 }
00293 pS << "}" << endl;
00294 }
00295
00296 };
00297
00298 #endif // _bddSymTab_h_