Advanced Strategic Command
textfileparser.h
Go to the documentation of this file.
1 /***************************************************************************
2  textfileparser.h - description
3  -------------------
4  begin : Thu Jul 26 2001
5  copyright : (C) 2001 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 textfileparserH
24 #define textfileparserH
25 
26 #include <vector>
27 #include <map>
28 #include "basictypes.h"
29 #include "ascstring.h"
30 #include "errors.h"
31 #include "basestreaminterface.h"
32 
33 
34 class ParsingError : public ASCmsgException {
35  public:
36  ParsingError ( const ASCString& msg ) : ASCmsgException ( msg ) {};
37 };
38 
39 class TextPropertyGroup;
40 
41 class TextPropertyList : public PointerList<TextPropertyGroup*> {
42  typedef map<int,TextPropertyGroup*> IdentCache;
43  IdentCache identCache;
44  public:
45  void buildIDs();
46  TextPropertyGroup* get ( int id );
47 };
48 
53  bool inheritanceBuild;
54  bool abstract;
55  int id;
56  public:
57  TextPropertyGroup() : inheritanceBuild ( false ), abstract ( false ), id ( -1 ) {};
58 
59  class Entry {
60  public:
65  Entry ( const ASCString& propertyName_, Operator op_, const ASCString& value_ ) : propertyName ( propertyName_ ), op ( op_ ), value ( value_ ), parent ( NULL ) { propertyName.toLower(); };
66  ASCString toString() const;
67  };
68 
69  private:
70  typedef map<ASCString, Entry*> EntryCache;
71  EntryCache entryCache;
72  typedef list<Entry> Entries;
73  Entries entries;
74 
75  typedef list<Entry*> EntryPointerList;
76 
77  protected:
78  void error ( const ASCString& msg, bool printInheritance = true );
79  bool processAlias( Entry& e, Entries& entriesToAdd, EntryPointerList& markAsResolved );
80  int findGeneration ( Entry* e );
82  public:
83  void addEntry( const Entry& entry );
84  Entry* find( const ASCString& n );
85  typedef vector<Entry*> Matches;
86  void findMatches( const ASCString& name, const ASCString& name_without_dot, Matches& matches );
87 
88  typedef list<TextPropertyGroup*> Parents;
90 
94 
97 
98  int evalID();
99 
100  void buildInheritance( TextPropertyList& tpl );
101  void resolveAllAlias( );
102  bool isAbstract() { return abstract; };
103  void print( int indent = 0 );
104 };
105 
106 
109  tnstream *stream;
110  typedef list<ASCString> Level;
111  Level level;
112  ASCString s1, s2, s3;
113  int levelDepth;
114  ASCString primaryName;
115 
116  TextPropertyGroup* textPropertyGroup;
117 
118  public:
119  TextFormatParser( tnstream* stream_, const ASCString& primaryName_ = "" ) : stream ( stream_ ), levelDepth ( 0 ), primaryName ( primaryName_ ), textPropertyGroup ( NULL ) {};
120  TextPropertyGroup* run ( );
121  ASCString readLine ( );
122 
123  static const int operationsNum;
124  static const char* operations[];
125  static const char* whiteSpace;
126 
127  protected:
128  void startLevel ( const ASCString& levelName );
129  void parseLine ( const ASCString& line );
130  void error ( const ASCString& errmsg );
131 };
132 
133 
134 #endif
TextFormatParser(tnstream *stream_, const ASCString &primaryName_="")
void findMatches(const ASCString &name, const ASCString &name_without_dot, Matches &matches)
The (base-) classes which are thrown as exceptions.
list< TextPropertyGroup * > Parents
ASCString & toLower()
Definition: ascstring.cpp:36
TextPropertyGroup * run()
enum TextPropertyGroup::Entry::Operator op
static const char * whiteSpace
ASCString toString() const
static const int operationsNum
The interface for all kinds of IO stream.
A list that stores pointers, but deletes the objects (and not only the pointers) on destruction...
Definition: basictypes.h:39
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
Operator
ASCString readLine()
Entry * find(const ASCString &n)
bool processAlias(Entry &e, Entries &entriesToAdd, EntryPointerList &markAsResolved)
void parseLine(const ASCString &line)
void buildInheritance(TextPropertyList &tpl)
ASCString value
int findGeneration(Entry *e)
Entry * parent
void print(int indent=0)
void error(const ASCString &errmsg)
Parses a .ASCTXT file and returns a TextPropertyGroup.
ASCString listInheritanceFilenames()
Class that stores all the (preparsed) entries of an .ASCTXT file.
ParsingError(const ASCString &msg)
Entry(const ASCString &propertyName_, Operator op_, const ASCString &value_)
static const char * operations[]
vector< Entry * > Matches
void error(const ASCString &msg, bool printInheritance=true)
ASCString propertyName
ASCString typeName
the name of the structure. For example "VehicleType"
void addEntry(const Entry &entry)
The standard interface for ASC streams. This is the parent class for all kinds of streams: normal fil...
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
void startLevel(const ASCString &levelName)