1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #if !defined(__INCLUDE_LandscapeDefinitionsItemh_INCLUDE__)
22 #define __INCLUDE_LandscapeDefinitionsItemh_INCLUDE__
24 #include <common/Defines.h>
25 #include <XML/XMLFile.h>
29 class LandscapeDefinitions
;
32 class LandscapeDefinitionsItem
35 LandscapeDefinitionsItem(const char *typeName
) :
42 typename
std::map
<std::string
, T
*>::iterator itor
;
43 for (itor
= items_
.begin();
47 T
*item
= (*itor
).second
;
53 T
*getItem(LandscapeDefinitions
*defns
,
54 const char *fileName
, bool load
, bool cache
)
57 typename
std::map
<std::string
, T
*>::iterator itor
;
58 itor
= items_
.find(fileName
);
59 if (itor
!= items_
.end())
61 item
= (*itor
).second
;
65 std::string dataFile
= S3D::getDataFile(fileName
);
66 if (!S3D::fileExists(dataFile
.c_str()))
68 S3D::dialogMessage("Scorched Landscape",
69 S3D::formatStringBuffer("Failed to find file \"%s\"\n"
70 "When loading %s file",
77 if (!file
.readFile(dataFile
.c_str()) ||
80 S3D::dialogMessage("Scorched Landscape",
81 S3D::formatStringBuffer("Failed to parse \"%s\"\n"
84 file
.getParserError()));
89 if (!item
->readXML(defns
, file
.getRootNode()))
91 S3D::dialogMessage("Scorched Landscape",
92 S3D::formatStringBuffer("Failed to parse \"%s\"",
99 items_
[fileName
] = item
;
107 std::map
<std::string
, T
*> items_
;
108 std::string typeName_
;