Advanced Strategic Command
textfile_evaluation.h
Go to the documentation of this file.
1 /***************************************************************************
2  textfile_evaluation.h - description
3  -------------------
4  begin : Thu Oct 06 2002
5  copyright : (C) 2002 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 #ifndef textfile_evaluationH
24 #define textfile_evaluationH
25 
26 #include <vector>
27 #include "ascstring.h"
28 #include "errors.h"
29 #include "textfileparser.h"
30 #include "typen.h"
31 
32 #ifdef ParserLoadImages
33 #include "graphics/surface.h"
34 #endif
35 
36 
38  bool reading;
39  // ASCString filename;
40  protected:
42  typedef list<ASCString> Level;
44 
45  typedef map< ASCString, pair<int, Level> > StoredContext;
47 
49  public:
50 
51  class Property {
52  protected:
57  virtual ASCString toString ( ) const = 0;
58  void findEntry ();
59 
61  virtual bool hasDefault() { return defaultValueAvail; };
62  void writeProperty( );
63  Property( bool defaultValueAvail_ ) : propertyContainer ( NULL ), entry ( NULL ), defaultValueAvail (defaultValueAvail_), evaluated(false) {};
64 
65  public:
66  virtual ~Property() {};
67  bool evaluated;
68  virtual void evaluate ( ) = 0;
69  void setName ( const ASCString& name_, const ASCString& lastName_ );
70  const ASCString& getLastName() { return lastName; };
71  void setPropertyContainer ( PropertyContainer* propertyContainer_ ) { propertyContainer = propertyContainer_; };
72  };
73  friend class Property;
74 
75 
76 
79 
80  virtual void openBracket( const ASCString& name );
81  virtual void closeBracket();
83 
84  void addString ( const ASCString& name, ASCString& property );
85  void addString ( const ASCString& name, ASCString& property, const ASCString& defaultValue );
86  void addStringArray ( const ASCString& name, vector<ASCString>& property );
87  void addInteger ( const ASCString& name, int& property );
88  void addInteger ( const ASCString& name, int& property, int defaultValue );
89  void addDFloat ( const ASCString& name, double& property );
90  void addDFloat ( const ASCString& name, double& property, double defaultValue );
91  void addIntegerArray ( const ASCString& name, vector<int>& property, bool required = true );
92  void addDFloatArray ( const ASCString& name, vector<double>& property );
93  void addDFloatArray ( const ASCString& name, vector<int>& property ); // still higher internal resolution than int
94  void addIntRangeArray ( const ASCString& name, vector<IntRange>& property, bool required = true );
95  void addTagArray ( const ASCString& name, BitSet& property, int tagNum, const char** tags, bool inverted = false );
96  void addTagInteger ( const ASCString& name, int& property, int tagNum, const char** tags, bool inverted = false );
97  void addTagInteger ( const ASCString& name, int& property, int tagNum, const char** tags, int defaultValue, bool inverted = false );
98  void addNamedInteger ( const ASCString& name, int& property, int tagNum, const char** tags );
99  void addNamedInteger ( const ASCString& name, int& property, int tagNum, const char** tags, int defaultValue );
100  void addBreakpoint();
101  #ifdef ParserLoadImages
102  void addImage ( const ASCString& name, Surface& property, ASCString& fileName, bool applyFieldMask );
103  // void addImageArray ( const ASCString& name, vector<void*> &property, const ASCString& fileName );
104  void addImageArray ( const ASCString& name, vector<Surface> &property, ASCString& fileName );
105  #endif
106  void addBool ( const ASCString& name, bool &property );
107  void addBool ( const ASCString& name, bool &property, bool defaultValue );
108 
109  void storeContext( const ASCString& label );
110  bool restoreContext( const ASCString& label );
111 
112  // void run ( );
113  bool isReading() { return reading; };
114  void warning ( const ASCString& errmsg );
115  void error ( const ASCString& errmsg );
116  bool find ( const ASCString& name );
117  virtual ASCString getFileName ( ) = 0;
118  virtual ASCString getArchive ( ) = 0;
119  virtual ~PropertyContainer ( ) { };
120  virtual ASCString getLocation() = 0;
121  protected:
122  PropertyContainer ( const ASCString& baseName, TextPropertyGroup* tpg, bool reading_ ) : reading( reading_ ), levelDepth ( 0 ), textPropertyGroup( tpg ) { };
123  private:
124  virtual void writeProperty ( Property& p, const ASCString& value ) = 0;
125  void setup ( Property* p, const ASCString& name );
126 
127 };
128 
130  public:
134  PropertyReadingContainer ( const ASCString& baseName, TextPropertyGroup* tpg );
136  void writeProperty ( Property& p, const ASCString& value );
137 };
138 
140  tnstream& stream;
141  public:
142  virtual ASCString getLocation() { return stream.getLocation(); };
143  virtual ASCString getFileName() { return stream.getDeviceName(); };
144  virtual ASCString getArchive() { return stream.getArchive(); };
145  PropertyWritingContainer ( const ASCString& baseName, tnstream& stream );
147 
148  void writeProperty ( Property& p, const ASCString& value );
149  virtual void openBracket( const ASCString& name );
150  virtual void closeBracket();
151 };
152 
153 #endif
PropertyContainer * propertyContainer
The (base-) classes which are thrown as exceptions.
virtual ASCString getArchive()
void addBool(const ASCString &name, bool &property)
PropertyContainer(const ASCString &baseName, TextPropertyGroup *tpg, bool reading_)
virtual ASCString toString() const =0
void writeProperty(Property &p, const ASCString &value)
virtual ASCString getLocation()=0
virtual ASCString getLocation()
returns the location of the stream.
Definition: basestrm.cpp:274
virtual ASCString getDeviceName()
returns the name of the stream.
Definition: basestrm.cpp:269
void setPropertyContainer(PropertyContainer *propertyContainer_)
void addImage(const ASCString &name, Surface &property, ASCString &fileName, bool applyFieldMask)
void addIntegerArray(const ASCString &name, vector< int > &property, bool required=true)
PropertyReadingContainer(const ASCString &baseName, TextPropertyGroup *tpg)
void addTagInteger(const ASCString &name, int &property, int tagNum, const char **tags, bool inverted=false)
virtual ASCString getArchive()
The interface for all kinds of IO stream.
virtual ASCString getLocation()
virtual ASCString getFileName()
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
TextPropertyGroup::Entry * entry
void storeContext(const ASCString &label)
void addStringArray(const ASCString &name, vector< ASCString > &property)
virtual ASCString getFileName()=0
void error(const ASCString &errmsg)
void applyFieldMask(Surface &s, int x, int y, bool detecColorKey)
Definition: surface.cpp:593
void warning(const ASCString &errmsg)
PropertyWritingContainer(const ASCString &baseName, tnstream &stream)
void writeProperty(Property &p, const ASCString &value)
virtual void evaluate()=0
const ASCString & getLastName()
void addDFloatArray(const ASCString &name, vector< double > &property)
Property(bool defaultValueAvail_)
StoredContext storedContext
virtual ASCString getLocation()
virtual ASCString getArchive()=0
Class that stores all the (preparsed) entries of an .ASCTXT file.
void addInteger(const ASCString &name, int &property)
virtual void closeBracket()
void addNamedInteger(const ASCString &name, int &property, int tagNum, const char **tags)
void addImageArray(const ASCString &name, vector< Surface > &property, ASCString &fileName)
virtual ASCString getArchive()
returns the archive name if the stream is located inside an archive; or "" if not.
Definition: basestrm.cpp:279
virtual ASCString getFileName()
PointerList< Property * > Properties
virtual void openBracket(const ASCString &name)
void addString(const ASCString &name, ASCString &property)
TextPropertyGroup * textPropertyGroup
void addIntRangeArray(const ASCString &name, vector< IntRange > &property, bool required=true)
bool find(const ASCString &name)
std::bitset< 64 > BitSet
Definition: basictypes.h:48
void addTagArray(const ASCString &name, BitSet &property, int tagNum, const char **tags, bool inverted=false)
bool restoreContext(const ASCString &label)
map< ASCString, pair< int, Level > > StoredContext
list< ASCString > Level
void addDFloat(const ASCString &name, double &property)
void setName(const ASCString &name_, const ASCString &lastName_)
Functions to parse the *.asctxt files.
virtual void openBracket(const ASCString &name)