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

# Tools/PotentialFields/PfcParser.h

Go to the documentation of this file.

    00001 /**
    00002 * @file PfcParser.h
    00003 *
    00004 * Definition of class Parser
    00005 * This parser is used to parse pfc-files for potential fields
    00006 *
    00007 * @author <a href="mailto:timlaue@informatik.uni-bremen.de">Tim Laue</a>
    00008 */
    00009
    00010 #ifndef PFC_PARSER_H_
    00011 #define PFC_PARSER_H_
    00012
    00013 #include "PfieldConfig.h"
    00014 #include <string>
    00015 #include <vector>
    00016 #ifdef POTENTIALFIELDS_FOR_GT2004_
    00017 #include "Tools/Streams/InStreams.h"
    00018 #else
    00019 #include <fstream>
    00020 #endif //POTENTIALFIELDS_FOR_GT2004_
    00021 #include "PotentialfieldComposition.h"
    00022
    00023 class PotentialFieldsObject;
    00024 class FormationObject;
    00025 class SingleFormation;
    00026 class Action;
    00027 class Potentialfield;
    00028 class PotentialfieldTransformation;
    00029 class PotentialfieldFunction;
    00030 class PfPose;
    00031 class PfVec;
    00032 class PfieldGeometricObject;
    00033
    00034
    00035 /**
    00036 * @class InstanceGroup
    00037 *
    00038 * A container for temporary storage of
    00039 * a group of object instances
    00040 */
    00041 class InstanceGroup
    00042 {
    00043 public:
    00044   /** The name of the group*/
    00045   std::string name;
    00046   /** The objects belonging to the group*/
    00047   std::vector<PotentialFieldsObject*> objects;
    00048 };
    00049
    00050
    00051 /**
    00052 * @class Parser
    00053 *
    00054 * The parser for PotentialfieldComposition
    00055 */
    00056 class Parser
    00057 {
    00058 public:
    00059   /** Destructor */
    00060   ~Parser();
    00061
    00062   /** Executes the parser
    00063   * @param composition The calling PotentialfieldComposition
    00064   * @param filename The file to open and parse
    00065   */
    00066   void parse(PotentialfieldComposition* composition, std::string filename);
    00067
    00068 private:
    00069 #ifdef POTENTIALFIELDS_FOR_GT2004_
    00070   /** A file object */
    00071   InBinaryFile* file;
    00072 #else
    00073   /** A file object */
    00074   std::ifstream file;
    00075 #endif //POTENTIALFIELDS_FOR_GT2004_
    00076   /** The last parsed token*/
    00077   std::string currentToken;
    00078   /** Parsed objects*/
    00079   std::vector<PotentialFieldsObject*> objects;
    00080   /** Fast mapping from name to index*/
    00081   NameToIndexMap objectMap;
    00082   /** The cached instance groups*/
    00083   std::vector<InstanceGroup> instanceGroups;
    00084   /** The calling PotentialfieldComposition*/
    00085   PotentialfieldComposition* composition;
    00086
    00087   /** Returns the next token from file
    00088   * @return A Token
    00089   */
    00090   std::string nextToken();
    00091
    00092   /** Returns one character from file
    00093   * @return A character
    00094   */
    00095   char nextChar();
    00096
    00097   /** Tests for the end of the file
    00098   * @return true, if the end of the file has been reached
    00099   */
    00100   bool endOfFile();
    00101
    00102   /** Parses an angle
    00103   * @return The angle in radian
    00104   */
    00105   double parseAngle();
    00106
    00107   /** Parses parameters for PotentialfieldComposition*/
    00108   void parseComposition();
    00109
    00110   /** Parses an object
    00111   * @return A pointer to the parsed object
    00112   */
    00113   PotentialFieldsObject* parseObject();
    00114
    00115   /** Parses an object and inserts it in the object list */
    00116   void parseAndInsertObject();
    00117
    00118   /** Parses an ObjectStateSymbol*/
    00119   void parseObjectStateSymbol();
    00120
    00121   /** Parses a group of instances*/
    00122   void parseInstanceGroup();
    00123
    00124   /** Parses the instance of an object*/
    00125   void parseInstance();
    00126
    00127   /** Parses a formation object*/
    00128   void parseFormationObject();
    00129
    00130   /** Parses and creates single formation rule for a formation
    00131   * @param formation The single formation
    00132   * @param formationToken Tehe first token to parse
    00133   */
    00134   void parseSingleFormation(SingleFormation*& formation, const std::string& formationToken);
    00135
    00136   /** Parses a Motionfield*/
    00137   void parseMotionfield();
    00138
    00139   /** Parses and creates a transformation
    00140   * @param transformation The transformation
    00141   * @param typeToken The first token (indicates the type)
    00142   */
    00143   void parseTransformation(PotentialfieldTransformation*& transformation,
    00144                            const std::string& typeToken);
    00145
    00146   /** Parses an Action for an Actionfield
    00147   * @param action The action
    00148   */
    00149   void parseAction(Action& action);
    00150
    00151   /** Parses an Actionfield*/
    00152   void parseActionfield();
    00153
    00154   /** Parses and creates a function
    00155   * @param function The function to parse
    00156   */
    00157   void parseFunction(PotentialfieldFunction*& function);
    00158
    00159   /** Parses and creates a geometric object
    00160   * @param geometricObject A pointer to a geometric object
    00161   * @param preparsedToken The first token to parse
    00162   */
    00163   void parseGeometricObject(PfieldGeometricObject*& geometricObject,
    00164                             const std::string& preparsedToken = "");
    00165
    00166   /** Parses a list of object references
    00167   * @param nameOfFirst The name of the first object
    00168   * @param field The field to which the objects will be assigned
    00169   */
    00170   void parseObjectsForField(const std::string& nameOfFirst, Potentialfield* field);
    00171
    00172   /** Parses some timing variables for a field
    00173   * @param field The field
    00174   */
    00175   void parseTimeConstraintsForField(Potentialfield* field);
    00176
    00177   /** Adds the elements of an object group to a field
    00178   * @param groupName The name of the group
    00179   * @param field The field to which the group is assigned
    00180   */
    00181   void addGroupToField(const std::string& groupName, Potentialfield* field);
    00182
    00183   /** Finds an object given its name
    00184   * @param name The name
    00185   * @return A pointer to the object
    00186   */
    00187   PotentialFieldsObject* getObject(const std::string& name);
    00188
    00189   /** Finds an object given its name and creates an instance
    00190   * @param name The name
    00191   * @return A pointer to the object
    00192   */
    00193   PotentialFieldsObject* getInstance(const std::string& name);
    00194 };
    00195
    00196
    00197 #endif  //PFC_PARSER_H_