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 Object;
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<Object*> 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<Object*> 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   Object* 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   Object* 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   Object* getInstance(const std::string& name);
00194 };
00195 
00196 
00197 #endif  //PFC_PARSER_H_
00198 
00199 
00200 
00201 /*
00202 * $Log: PfcParser.h,v $
00203 * Revision 1.1.1.1  2004/05/22 17:37:29  cvsadm
00204 * created new repository GT2004_WM
00205 *
00206 * Revision 1.1  2004/01/20 15:42:19  tim
00207 * Added potential fields implementation
00208 *
00209 * Revision 1.7  2003/06/13 14:27:58  tim
00210 * added random generator and tangential fields
00211 *
00212 * Revision 1.6  2003/05/22 14:23:47  tim
00213 * Changed representation of transformations
00214 *
00215 * Revision 1.5  2003/04/22 14:35:17  tim
00216 * Merged changes from GO
00217 *
00218 * Revision 1.5  2003/04/09 19:03:06  tim
00219 * Last commit before GermanOpen
00220 *
00221 * Revision 1.4  2003/04/03 15:47:32  tim
00222 * Added modelling for teammates
00223 *
00224 * Revision 1.3  2003/03/25 15:37:59  timrie
00225 * Doxygen-comments corrected
00226 *
00227 * Revision 1.2  2003/03/23 20:32:37  loetzsch
00228 * removed green compiler warning: no newline at end of file
00229 *
00230 * Revision 1.1  2003/03/23 17:51:27  tim
00231 * Added potentialfields
00232 *
00233 */

Generated on Thu Sep 23 19:57:41 2004 for GT2004 by doxygen 1.3.6