util/symtable.hh
changeset 971 8aee27d46208
parent 951 f53ea4c8621c
child 973 f86d5d6bb04e
equal deleted inserted replaced
970:0ede7ca157e2 971:8aee27d46208
    40 #include <string>
    40 #include <string>
    41 
    41 
    42 
    42 
    43 
    43 
    44 
    44 
    45 template<typename value_type, value_type null_value> class symtable_c {
    45 template<typename value_type> class symtable_c {
    46   /* Case insensitive string compare copied from
    46   /* Case insensitive string compare copied from
    47    * "The C++ Programming Language" - 3rd Edition
    47    * "The C++ Programming Language" - 3rd Edition
    48    * by Bjarne Stroustrup, ISBN 0201889544.
    48    * by Bjarne Stroustrup, ISBN 0201889544.
    49    */
    49    */
    50   class nocase_c {
    50   class nocase_c {
    84     void reset(void); /* clear all entries... */
    84     void reset(void); /* clear all entries... */
    85 
    85 
    86     void push(void); /* create new inner scope */
    86     void push(void); /* create new inner scope */
    87     int  pop(void);  /* clear most inner scope */
    87     int  pop(void);  /* clear most inner scope */
    88 
    88 
    89     void set(const char *identifier_str, value_t value);
    89     void set(const char *identifier_str, value_t value);    // Will change value associated to string if already in map. Will create new entry if string not in map.
    90     void set(const symbol_c *symbol, value_t value);
    90     void set(const symbol_c *symbol, value_t value);        // Will change value associated to string if already in map. Will create new entry if string not in map.
    91     void insert(const char *identifier_str, value_t value);
    91     void insert(const char *identifier_str, value_t value); // insert a new (string,value) pair. Give an error if string already in map associated to different value!
    92     void insert(const symbol_c *symbol, value_t value);
    92     void insert(const symbol_c *symbol, value_t value);     // insert a new (string,value) pair. Give an error if string already in map associated to different value!
    93 
    93 
    94     /* Search for an entry. Will return end_value() if not found */
    94     /* Search for an entry. Will return end() if not found */
    95     value_t end_value(void) {return null_value;}
    95     iterator               end  (void);
    96     value_t find_value(const char *identifier_str);
    96     iterator               find (const char     *identifier_str);
    97     value_t find_value(const symbol_c *symbol);
    97     iterator               find (const symbol_c *symbol        );
    98 
    98 
    99 
    99 
   100   /* iterators ... */
   100   /* iterators ... */
   101   /* NOTE: These member functions are incorrect, as the returned iterator will not iterate through the inner_scopes!! */
   101   /* NOTE: These member functions are incorrect, as the returned iterator will not iterate through the inner_scopes!! */
   102   /*       We simply comment it all out, as they are not currently needed!                                            */
   102   /*       We simply comment it all out, as they are not currently needed!                                            */
   103   #if 0
   103   #if 0
   104     iterator               find (const char *identifier_str) {return _base.find(identifier_str);}
   104     iterator               find (const char *identifier_str)
   105     iterator               begin()                           {return _base.begin();}
   105     iterator               begin()                          
   106     const_iterator         begin()  const                    {return _base.begin();}
   106     const_iterator         begin()  const                   
   107     iterator               end()                             {return _base.end();}
   107     iterator               end()                            
   108     const_iterator         end()    const                    {return _base.end();}
   108     const_iterator         end()    const                   
   109     reverse_iterator       rbegin()                          {return _base.rbegin();}
   109     reverse_iterator       rbegin()                         
   110     const_reverse_iterator rbegin() const                    {return _base.rbegin();}
   110     const_reverse_iterator rbegin() const                   
   111     reverse_iterator       rend()                            {return _base.rend();}
   111     reverse_iterator       rend()                           
   112     const_reverse_iterator rend()   const                    {return _base.rend();}
   112     const_reverse_iterator rend()   const                   
   113   #endif
   113   #endif
   114     /* debuging function... */
   114     /* debuging function... */
   115     void print(void);
   115     void print(void);
   116 };
   116 };
   117 
   117