Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

SymbolMap.h

00001 // See the file LICENSE in the some directory as this file for legal
00002 // notices about this software.
00003 #ifndef DEV_W3_ORG__2001_BLINDFOLD_SRC_SYMBOLMAP_H
00004 #define DEV_W3_ORG__2001_BLINDFOLD_SRC_SYMBOLMAP_H
00005 // $Id: SymbolMap_8h-source.html,v 1.2 2001/10/10 20:40:58 sandro Exp $
00006 #include "config.h"
00007 #include "Symbol.h"
00008 
00028 class SymbolMap {
00029       
00030 public:
00031 
00032     // STANDARD MEMBER FUNCTIONS
00036     SymbolMap(SymbolTable* table) 
00037     : hungry(false), table(table), data(table->size()) { }
00038 
00043     SymbolMap() : hungry(true) { }
00044     //  member-by-member should work!
00045     //SymbolMap(const SymbolMap& other);
00046     //const SymbolMap& operator=(const SymbolMap& other);
00047     //bool operator==(const SymbolMap& other) const;
00048     //bool operator<(const SymbolMap& other) const;
00049     size_t hash() const;
00050     friend std::ostream& operator<<(std::ostream& s, const SymbolMap& me);
00051     std::ostream& print_to(std::ostream& stream) const; 
00052     ~SymbolMap();       
00053 
00054     // (RE)IMPLEMENTATION OF INHERITED MEMBERS
00055 
00056     // CLASS-SPECIFIC PUBLIC INTERFACE
00057     
00058     Symbol get(Symbol var) const {
00059     if (hungry && var) const_cast<SymbolMap*>(this)->setTable(&var.table());
00060     assert(&var.table() == table);
00061     if (var.index() >= data.size()) return Symbol();
00062     return data[var.index()];
00063     }
00064 
00065     void set(Symbol var, Symbol value) {
00066     if (hungry && var) setTable(&var.table());
00067     assert(&var.table() == table);
00068     if (var.index() >= data.size()) data.resize(var.index()+1);
00069     data[var.index()] = value;
00070     }
00071 
00072     size_t count() {
00073     size_t result = 0;
00074     for (size_t i=0; i<data.size(); i++) {
00075         if (data[i]) result++;
00076     }
00077     return result;
00078     }
00079 
00080 private:
00081     bool hungry;
00082     SymbolTable* table;
00083     std::vector<Symbol> data;
00084 
00085     void setTable(SymbolTable* table) {
00086     hungry = false;
00087         this->table = table;
00088     }
00089 };     
00090 
00091 STANDARD_EXTERNAL(SymbolMap)
00092 
00093 #endif  /* DEV_W3_ORG__2001_BLINDFOLD_SRC_SYMBOLMAP_H */   // -*-C++-*-

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.