00001 /* Copyright (C) 2004-2008 Oliver Lemke <olemke@core-dump.info> 00002 00003 This program is free software; you can redistribute it and/or 00004 modify it under the terms of the GNU General Public License as 00005 published by the Free Software Foundation; either version 2 of the 00006 License, or (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00016 USA. */ 00017 00019 // File description 00021 00032 #ifndef WORKSPACE_NG_INCLUDED 00033 #define WORKSPACE_NG_INCLUDED 00034 00035 #include <stack> 00036 #include <map> 00037 00038 #include "array.h" 00039 #include "wsv_aux.h" 00040 00042 00045 class Workspace { 00046 private: 00047 typedef struct { 00048 void *wsv; 00049 bool initialized; 00050 bool auto_allocated; 00051 } WsvStruct; 00052 00054 Array< stack<WsvStruct *> > ws; 00055 00056 public: 00057 static Array<WsvRecord> wsv_data; 00058 00060 static map<String, Index> WsvMap; 00061 00062 Workspace (); 00063 Workspace (const Workspace& workspace); 00064 virtual ~Workspace (); 00065 00066 static void define_wsv_data(); 00067 static void define_wsv_map(); 00068 static Index add_wsv (const WsvRecord& wsv); 00069 00070 void del (Index i); 00071 00072 void duplicate (Index i); 00073 00074 void initialize (); 00075 00077 bool is_initialized (Index i) { 00078 return ((ws[i].size () != 0) 00079 && (ws[i].top()->initialized == true)); } 00080 00081 void *pop (Index i); 00082 00083 void pop_free (Index i); 00084 00085 void push (Index i, void *wsv); 00086 00087 void push_uninitialized (Index i, void *wsv); 00088 00089 Index nelem () {return ws.nelem ();} 00090 00091 void *operator[](Index i); 00092 }; 00093 00094 00096 00102 template <typename OutputStream> void 00103 PrintWsvName (OutputStream& outstream, Index i) 00104 { 00105 outstream << Workspace::wsv_data[i].Name () << "(" << i << ") "; 00106 } 00107 00108 00109 #endif /* WORKSPACE_NG_INCLUDED */ 00110