Hosting courtesy of Sourceforge

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

ParseAction.h

Go to the documentation of this file.
00001 //
00002 //      Copyright (C) 2002 Robert Renaud
00003 //
00004 //      This program is free software; you can redistribute it and/or
00005 //      modify it under the terms of the GNU General Public License
00006 //      as published by the Free Software Foundation; either version 2
00007 //      of the License, or (at your option) any later version.
00008 //
00009 //      This program is distributed in the hope that it will be useful,
00010 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 //
00013 //      See the GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program; if not, write to the Free Software
00017 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 
00020 #ifndef PARSE_ACTION_H
00021 #define PARSE_ACTION_H
00022 
00023 #include "../Config.h"
00024 #include "ParseDebug.h"
00025 
00026 using namespace std;
00027 
00028 namespace Parse {
00033         class ParseAction {
00034         public:
00038                 virtual void getValue(istream& input)=0;
00043                 virtual void finishingAction() { }
00044                 virtual ~ParseAction() { }
00045         };
00046 
00052         class OptionWasRead: public ParseAction {
00053         public:
00055                 OptionWasRead(bool& val);
00057                 void getValue(std::istream& input);
00058         private:
00059                 bool& trueIfCalled;
00060         };
00061 
00067         template <class T>
00068                 class StdRead: public ParseAction {
00069         public:
00074                 StdRead(T& object);
00079                 virtual void getValue(istream& input);
00080         protected:
00081                 T& obj;
00082         };
00083 
00087         template <class T>
00088                 class  ReadAndCheck: public StdRead<T> {
00089         public:
00094                 ReadAndCheck(T& obj, bool& objectSet_);
00098                 virtual void getValue(istream& input);
00099         protected:
00100                 bool& valueSet;
00101         };
00102 
00106         template <class T>
00107                 class ReadOrDefault: public StdRead<T> {
00108         public:
00114                 ReadOrDefault(T& object, T value);
00115                 virtual ~ReadOrDefault() { }
00116 
00117                 virtual void getValue(istream &input);
00118                 virtual void finishingAction();
00119         private:
00120                 bool valueSet;
00121                 T val;
00122         };
00123 
00124         // Written for Grav Sim originally....
00125         template <class T>
00126                 class ReadAndMult: public StdRead<T> {
00127         public:
00128                 ReadAndMult(T& object, T mult);
00129                 virtual void getValue(istream& input);
00130         protected:
00131                 T multiplier;
00132         };
00133 }; // namespace Parse
00134 
00135 template <class T>
00136 void Parse::StdRead<T>::getValue(istream &input) {
00137         input >> obj;
00138 }
00139 
00140 template <class T>
00141 Parse::StdRead<T>::StdRead(T& object) :
00142 obj(object)
00143 { }
00144 
00145 template <class T>
00146 Parse::ReadAndCheck<T>::ReadAndCheck(T& object, bool& objectSet_) :
00147 Parse::StdRead<T>(object) ,
00148 valueSet(objectSet_)
00149 { }
00150 
00151 template <class T>
00152 void Parse::ReadAndCheck<T>::getValue(istream &input)  {
00153         StdRead<T>::getValue(input);
00154         valueSet = true;
00155 }
00156 
00157 template <class T>
00158 Parse::ReadOrDefault<T>::ReadOrDefault(T& object, T value) :
00159 Parse::StdRead<T>(object),
00160 valueSet(false),
00161 val(value)
00162 { }
00163 
00164 
00165 template <class T>
00166 void Parse::ReadOrDefault<T>::getValue(istream& input) {
00167         StdRead<T>::getValue(input);
00168         valueSet = true;
00169 //      cout << "ReadOrDefault::getValue()" << endl;
00170 }
00171 
00172 template <class T>
00173 void Parse::ReadOrDefault<T>::finishingAction() {
00174         if (!valueSet) {
00175                 obj = val;
00176         }
00177 }
00178 
00179 #endif // ifdef PARSE_ACTION_H
00180 

Generated on Tue May 21 07:26:51 2002 for BomberLAN by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001