Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

textfile_evaluation.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           textfile_evaluation.h  -  description
00003                              -------------------
00004     begin                : Thu Oct 06 2002
00005     copyright            : (C) 2002 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00014 /***************************************************************************
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef textfile_evaluationH
00024 #define textfile_evaluationH
00025 
00026 #include <vector>
00027 #include "ascstring.h"
00028 #include "errors.h"
00029 #include "textfileparser.h"
00030 #include "typen.h"
00031 
00032 #ifdef ParserLoadImages
00033 #include "graphics/surface.h"
00034 #endif
00035 
00036 
00037 class PropertyContainer {
00038          bool reading;
00039          // ASCString filename;
00040       protected:
00041          int levelDepth;
00042          typedef list<ASCString> Level;
00043          Level level;
00044 
00045          typedef map< ASCString, pair<int, Level> > StoredContext;
00046          StoredContext storedContext;
00047 
00048          TextPropertyGroup* textPropertyGroup;
00049       public:
00050 
00051          class Property {
00052             protected:
00053                ASCString name;
00054                ASCString lastName;
00055                PropertyContainer* propertyContainer;
00056                TextPropertyGroup::Entry* entry;
00057                virtual ASCString toString ( ) const = 0;
00058                void findEntry ();
00059 
00060                bool defaultValueAvail;
00061                virtual bool hasDefault() { return defaultValueAvail; };
00062                void writeProperty( );
00063                Property( bool defaultValueAvail_ ) : propertyContainer ( NULL ), entry ( NULL ), defaultValueAvail (defaultValueAvail_), evaluated(false) {};
00064 
00065              public:
00066                virtual ~Property() {};
00067                bool evaluated;
00068                virtual void evaluate ( ) = 0;
00069                void setName ( const ASCString& name_, const ASCString& lastName_ );
00070                const ASCString& getLastName() { return lastName; };
00071                void setPropertyContainer ( PropertyContainer* propertyContainer_ ) {  propertyContainer = propertyContainer_; };
00072           };
00073           friend class Property;
00074 
00075 
00076 
00077          typedef PointerList<Property*> Properties;
00078          Properties properties;
00079 
00080          virtual void openBracket( const ASCString& name );
00081          virtual void closeBracket();
00082          ASCString getNameStack();
00083 
00084          void addString ( const ASCString& name, ASCString& property );
00085          void addString ( const ASCString& name, ASCString& property, const ASCString& defaultValue );
00086          void addStringArray ( const ASCString& name, vector<ASCString>& property );
00087          void addInteger ( const ASCString& name, int& property );
00088          void addInteger ( const ASCString& name, int& property, int defaultValue );
00089          void addDFloat ( const ASCString& name, double& property );
00090          void addDFloat ( const ASCString& name, double& property, double defaultValue );
00091          void addIntegerArray ( const ASCString& name, vector<int>& property, bool required = true );
00092          void addDFloatArray ( const ASCString& name, vector<double>& property );
00093          void addDFloatArray ( const ASCString& name, vector<int>& property ); // still higher internal resolution than int
00094          void addIntRangeArray ( const ASCString& name, vector<IntRange>& property, bool required = true );
00095          void addTagArray ( const ASCString& name, BitSet& property, int tagNum, const char** tags, bool inverted = false );
00096          void addTagInteger ( const ASCString& name, int& property, int tagNum, const char** tags, bool inverted = false );
00097          void addTagInteger ( const ASCString& name, int& property, int tagNum, const char** tags, int defaultValue, bool inverted = false );
00098          void addNamedInteger ( const ASCString& name, int& property, int tagNum, const char** tags );
00099          void addNamedInteger ( const ASCString& name, int& property, int tagNum, const char** tags, int defaultValue );
00100          void addBreakpoint();
00101         #ifdef ParserLoadImages
00102          // void addImage ( const ASCString& name, void* &property, const ASCString& fileName );
00103          void addImage ( const ASCString& name, Surface& property, const ASCString& fileName, bool applyFieldMask );
00104          // void addImageArray ( const ASCString& name, vector<void*> &property, const ASCString& fileName );
00105          void addImageArray ( const ASCString& name, vector<Surface> &property, const ASCString& fileName );
00106         #endif
00107          void addBool  ( const ASCString& name, bool &property );
00108          void addBool  ( const ASCString& name, bool &property, bool defaultValue  );
00109 
00110          void storeContext( const ASCString& label );
00111          bool restoreContext( const ASCString& label );
00112 
00113          // void run ( );
00114          bool isReading() { return reading; };
00115          void warning ( const ASCString& errmsg );
00116          void error ( const ASCString& errmsg );
00117          bool find ( const ASCString& name );
00118          virtual ASCString getFileName (  ) = 0;
00119          virtual ~PropertyContainer ( ) { };
00120       protected:
00121          PropertyContainer ( const ASCString& baseName, TextPropertyGroup* tpg, bool reading_ ) : reading( reading_ ), levelDepth ( 0 ), textPropertyGroup( tpg ) { };
00122          virtual ASCString getLocation() = 0;
00123       private:
00124          virtual void writeProperty ( Property& p, const ASCString& value ) = 0;
00125          void setup ( Property* p, const ASCString& name );
00126 
00127 };
00128 
00129 class PropertyReadingContainer : public PropertyContainer {
00130    protected:
00131          virtual ASCString getLocation() { return textPropertyGroup->location; };
00132    public:
00133          virtual ASCString getFileName (  ) { return textPropertyGroup->fileName; };
00134          PropertyReadingContainer ( const ASCString& baseName, TextPropertyGroup* tpg );
00135          ~PropertyReadingContainer (  );
00136          void writeProperty ( Property& p, const ASCString& value );
00137 };
00138 
00139 class PropertyWritingContainer : public PropertyContainer {
00140          tnstream& stream;
00141    protected:
00142          virtual ASCString getLocation() { return stream.getLocation(); };
00143    public:
00144          virtual ASCString getFileName (  ) { return stream.getDeviceName(); };
00145          PropertyWritingContainer ( const ASCString& baseName, tnstream& stream );
00146          ~PropertyWritingContainer();
00147 
00148          void writeProperty ( Property& p, const ASCString& value );
00149          virtual void openBracket( const ASCString& name );
00150          virtual void closeBracket();
00151 };
00152 
00153 #endif

Generated on Tue Jun 24 01:27:53 2008 for Advanced Strategic Command by  doxygen 1.4.2