00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #include "DictionaryParser.hpp" 00023 #include "../stream/InputStream.hpp" 00024 #include "sim/sim.hpp" 00025 #include "sim/schema/SimSchema.hpp" 00026 #include "sim/stat/Dictionary.hpp" 00027 #include "sim/stat/DictionaryEntry.hpp" 00028 #include "sim/config/sim_config.hpp" 00029 #include "util/type/String.hpp" 00030 #include "util/error/Log.hpp" 00031 #include <cstring> 00032 #include <cstdio> 00033 00034 00035 namespace se_core { 00036 00037 00038 DictionaryParser 00039 ::DictionaryParser(ParseManager& parser) 00040 : Parser(parser, Parser::ENGINE, Parser::DICTIONARY, 1) { 00041 } 00042 00043 00044 void DictionaryParser 00045 ::parse(InputStream& in) { 00046 String name; 00047 // Dictionary name 00048 int dict = -1; 00049 int value = DE_FIRST_USER_TYPE; 00050 00051 int code; 00052 while((code = in.readInfoCode()) != 'Q') { 00053 switch(code) { 00054 case 'D': 00055 in.readString(name); 00056 dict = SimSchema::dictionary().id(DE_DICTIONARY_TYPE, name.get()); 00057 value = 0; 00058 break; 00059 00060 case 'A': // Append 00061 value = SimSchema::dictionary().highestId(dict) + 1; 00062 break; 00063 00064 case 'V': // Value 00065 if(dict < 0) { 00066 LogFatal("You must fist specify a dictionary in file " << in.name()); 00067 } 00068 value = in.readShort(); 00069 break; 00070 00071 case 'E': // Enum 00072 if(dict < 0) { 00073 LogFatal("You must fist specify a dictionary in file " << in.name()); 00074 } 00075 in.readString(name); 00076 new DictionaryEntry(dict, value, name.get(), true); 00077 ++value; 00078 break; 00079 00080 default: 00081 LogFatal("Unsupported token " << (char)(code) << " in file " << in.name()); 00082 break; 00083 } 00084 } 00085 } 00086 00087 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.