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 "DictionaryEntry.hpp" 00023 #include "Dictionary.hpp" 00024 #include "../schema/all.hpp" 00025 #include "util/error/Log.hpp" 00026 #include <cstring> 00027 00028 namespace se_core { 00029 00030 DictionaryEntry 00031 ::DictionaryEntry(short type, short id, const char* name, bool doCopyName) { 00032 type_ = type; 00033 id_ = id; 00034 if(doCopyName) { 00035 char* n = new char[ strlen(name) + 1 ]; 00036 strcpy(n, name); 00037 name_ = n; 00038 doDelete_ = true; 00039 } 00040 else { 00041 name_ = name; 00042 doDelete_ = false; 00043 } 00044 addToDictionary(); 00045 } 00046 00047 00048 DictionaryEntry 00049 ::DictionaryEntry(short type, short id, char* name, bool doCopyName) { 00050 type_ = type; 00051 id_ = id; 00052 if(doCopyName) { 00053 char* n = new char[ strlen(name) + 1 ]; 00054 strcpy(n, name); 00055 name_ = n; 00056 doDelete_ = true; 00057 } 00058 else { 00059 name_ = name; 00060 doDelete_ = true; 00061 } 00062 addToDictionary(); 00063 } 00064 00065 00066 DictionaryEntry 00067 ::DictionaryEntry(short type, const char* name, bool doCopyName) { 00068 type_ = type; 00069 id_ = Dictionary::hash(name); 00070 if(SimSchema::dictionary().hasId(type, id_)) { 00071 Assert(strcmp(name, SimSchema::dictionary().name(type, id_)) == 0) 00072 } 00073 00074 if(doCopyName) { 00075 char* n = new char[ strlen(name) + 1 ]; 00076 strcpy(n, name); 00077 name_ = n; 00078 doDelete_ = true; 00079 } 00080 else { 00081 name_ = name; 00082 doDelete_ = true; 00083 } 00084 addToDictionary(); 00085 } 00086 00087 00088 DictionaryEntry 00089 ::~DictionaryEntry() { 00090 SimSchema::dictionary().remove(this); 00091 if(doDelete_) delete name_; 00092 } 00093 00094 00095 void DictionaryEntry 00096 ::addToDictionary() { 00097 SimSchema::dictionary().add(this); 00098 } 00099 00100 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.