Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

context.h

Go to the documentation of this file.
00001 #ifndef _CONTEXT_H_
00002 #define _CONTEXT_H_ //make idempotent
00003 /* Contextual Exceptions classes for throwing exceptions that know where they
00004    came from.
00005    Copyright (C) 2002 Aaron Bentley
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software Foundation,
00019    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00020 
00021 
00027 #include <vector>
00028 #include <string>
00029 #include <memory>
00030 
00032 namespace context
00033 {
00034    using std::vector;
00035    using std::string;
00036    using std::auto_ptr;
00037 
00042    class Context
00043    {
00044    private:
00046       std::string description;
00047       
00048       // prevent use
00049       Context();
00050       
00051       // prevent use
00052       Context(Context const &);
00053 
00054    public:
00055       Context(const string &argd);
00056 
00057       ~Context();
00058 
00059       const std::string &getDescription() const;
00060 
00061       static void print(const vector<string> &list, size_t start=0, 
00062     size_t end=0);
00063    };
00064 
00068    class ContextStack
00069    {
00070    private:
00072       std::vector<Context *> stack;
00073 
00075       static ContextStack *instance;
00076 
00077    public:
00082       static ContextStack &getInstanceOf()
00083       {
00084     if (instance==NULL) instance=new ContextStack;
00085     if (instance==NULL) throw "Argh!";
00086     return *instance;
00087       }
00088 
00089       void push(Context &cont);
00090 
00091       void pop();
00092 
00093       void pop(Context &cx);
00094       
00095       auto_ptr< vector<string> > makeSVector() const;
00096 
00097       static void print();
00098    };
00099 
00103    class ContException
00104    {
00105    private:
00107       auto_ptr <vector <string> > thrContext;
00108 
00110       string msg;
00111 
00112    public:
00113       ContException();
00114 
00115       ContException(const string &argmsg);
00116       
00117       void print();
00118    };
00119 };
00120 #endif // end idempotent ifdef

Generated on Mon Apr 7 19:41:43 2003 for DuTree by doxygen1.2.18