00001 #ifndef UMPFILE_H_ 00002 #define UMPFILE_H_ 00003 00004 #include <string> 00005 #include <vector> 00006 #include "UMPTile.h" 00007 #include "UMPAssembly.h" 00008 #include "UMPException.h" 00009 #include "iscriplib.h" 00010 00011 namespace map 00012 { 00013 namespace ump 00014 { 00015 class UMPTileVisitor 00016 { 00017 public: 00018 virtual ~UMPTileVisitor () 00019 { 00020 } 00021 00022 virtual void visit (const UMPTile& tile) = 0; 00023 }; 00024 00030 class UMPFile 00031 { 00032 private: 00033 // the filename of the ump - relative to maps/ 00034 std::string _fileName; 00035 00036 // the base of the ump tile to make the names shorter 00037 std::string _base; 00038 00039 // list of all ump tiles 00040 std::vector<UMPTile> _umpTiles; 00041 typedef std::vector<UMPTile>::iterator UMPTileIterator; 00042 typedef std::vector<UMPTile>::const_iterator UMPTileConstIterator; 00043 00044 // list of all ump assemblies 00045 std::vector<UMPAssembly> _umpAssenblies; 00046 typedef std::vector<UMPAssembly>::iterator UMPAssemblyIterator; 00047 typedef std::vector<UMPAssembly>::const_iterator UMPAssemblyConstIterator; 00048 00049 private: 00050 00054 void parseTile (Tokeniser &tokeniser) throw(UMPException); 00055 void parse (Tokeniser &tokenizer); 00056 00057 public: 00058 00064 UMPFile (const std::string& fileName, const std::string& base = "") throw (UMPException); 00065 00066 virtual ~UMPFile (); 00067 00072 bool load (); 00073 00078 bool save (); 00079 00083 const std::string& getFileName () const; 00084 00088 const std::string& getBase () const; 00089 00094 void addTile (UMPTile& tile); 00095 00100 UMPTile* getTileForMap (const std::string& map); 00101 00106 const std::string getMapName (const std::string& tile) const; 00107 00113 const std::string getTileName (const std::string& map) const; 00114 00119 void forEachTile (UMPTileVisitor& visitor) const 00120 { 00121 for (UMPTileConstIterator i = _umpTiles.begin(); i != _umpTiles.end(); ++i) { 00122 visitor.visit((*i)); 00123 } 00124 } 00125 }; 00126 } 00127 } 00128 00129 #endif /* UMPFILE_H_ */