Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "map.h"
00036
00037 #include "common/wave_ex.h"
00038 #include "perf/perf.h"
00039
00040
00041 namespace aesop {
00042
00043
00044
00045 MapFormatReader::~MapFormatReader(void) throw() { }
00046
00047 typedef std::vector<smart_ptr<MapFormatReader> > vec_reader_t;
00048
00049 static vec_reader_t s_readers;
00050
00051
00053
00054
00055
00057
00058
00059
00061
00062
00063
00065
00066 void
00067 registerMapFormatReader
00068 (
00069 IN smart_ptr<MapFormatReader>& reader
00070 )
00071 {
00072 ASSERT(reader, "registering a null reader?");
00073
00074 s_readers.push_back(reader);
00075 }
00076
00077
00078
00079 smart_ptr<Map>
00080 loadMap
00081 (
00082 IN const char * id,
00083 IN const char * path
00084 )
00085 {
00086 perf::Timer timer("loadMap");
00087 ASSERT(id, "null");
00088 ASSERT(path, "null");
00089
00090 smart_ptr<Map> map;
00091 for (vec_reader_t::iterator i = s_readers.begin(); i != s_readers.end();
00092 ++i) {
00093 MapFormatReader * reader = *i;
00094 ASSERT(reader, "null map reader in vector?");
00095
00096 bool isFormat = false;
00097 {
00098 perf::Timer timer("loadMap::isMyFormat");
00099 isFormat = reader->isMyFormat(id, path);
00100 }
00101
00102 if (!isFormat)
00103 continue;
00104
00105
00106
00107 DPRINTF("Path '%s' is claimed by reader.", path);
00108 const char * desc = reader->getDescription();
00109 ASSERT(desc, "reader returned a null description?");
00110 DPRINTF(" Reader: '%s'", desc);
00111
00112 std::string timer_name = "loadMap::";
00113 timer_name += id;
00114 try {
00115 perf::Timer timer(timer_name.c_str());
00116 map = reader->loadMap(id, path);
00117 } catch (std::exception& e) {
00118 WAVE_EX(wex);
00119 wex << "Failed to load map " << id << " from " << path;
00120 wex << "\n" << e.what();
00121 }
00122 break;
00123 }
00124
00125 if (!map) {
00126 WAVE_EX(wex);
00127 wex << "Failed to load map at '" << path << "'. No reader found!";
00128 return NULL;
00129 }
00130
00131
00132 return map;
00133 }
00134
00135
00136
00137 };
00138