Back to index

texmacs  1.0.7.15
list_environment.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : list_environment.hpp
00004 * DESCRIPTION: linked lists of several environments
00005 * COPYRIGHT  : (C) 2006  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef LIST_ENVIRONMENT_H
00013 #define LIST_ENVIRONMENT_H
00014 #include "basic_environment.hpp"
00015 
00016 /******************************************************************************
00017 * List environments
00018 ******************************************************************************/
00019 
00020 class list_environment_rep;
00021 class list_environment {
00022   ABSTRACT_NULL(list_environment);
00023   inline list_environment (basic_environment env);
00024   inline list_environment (basic_environment env, list_environment next);
00025   inline friend environment as_environment (const list_environment& env) {
00026     return environment ((environment_rep*) env.rep); }
00027   inline friend list_environment as_list_environment (const environment& env) {
00028     return list_environment ((list_environment_rep*) as_pointer (env)); }
00029 };
00030 
00031 class list_environment_rep: public environment_rep {
00032   static tree uninit;
00033 public:
00034   basic_environment env;  // local environment
00035   list_environment next;  // next environment
00036   int misses;             // count for number of local environment misses
00037 
00038 public:
00039   inline list_environment_rep (basic_environment env2, list_environment next2):
00040     env (env2), next (next2), misses (0) {}
00041 
00042   void compress ();
00043   tree* raw_read (int key);
00044 
00045   inline bool contains (int key) {
00046     return raw_read (key) != 0; }
00047   inline tree read (int key) {
00048     tree* ptr= raw_read (key);
00049     return ptr==NULL? uninit: *ptr; }
00050   inline void write (int key, const tree& val) {
00051     env->write (key, val); }
00052   inline void remove (int key) {
00053     // NOTE: it is not allowed to change next, in the case
00054     // when 'key' does not exist in the local environment 'env'
00055     env->remove (key); }
00056   void print (const string& prefix);
00057 };
00058 
00059 ABSTRACT_NULL_CODE(list_environment);
00060 inline list_environment::list_environment
00061   (basic_environment env):
00062     rep (tm_new<list_environment_rep> (env, list_environment ())) {}
00063 inline list_environment::list_environment
00064   (basic_environment env, list_environment next):
00065     rep (tm_new<list_environment_rep> (env, next)) {}
00066 
00067 int total_size (list_environment l);
00068 basic_environment flatten (list_environment l);
00069 
00070 #endif // defined LIST_ENVIRONMENT_H