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 "Property.hpp" 00023 00024 namespace se_core { 00025 00026 Property 00027 ::Property(const char* name, short value) 00028 : name_(name, 0), key_(hash(name)), type_(PT_SHORT) { 00029 v.shortValue_ = value; 00030 } 00031 00032 Property 00033 ::Property(const char* name, int value) 00034 : name_(name, 0), key_(hash(name)), type_(PT_INT) { 00035 v.intValue_ = value; 00036 } 00037 00038 Property 00039 ::Property(const char* name, float value) 00040 : name_(name, 0), key_(hash(name)), type_(PT_FLOAT) { 00041 v.floatValue_ = value; 00042 } 00043 00044 Property 00045 ::Property(const char* name, String* value) 00046 : name_(name, 0), key_(hash(name)), type_(PT_STRING) { 00047 v.string_ = value; 00048 if(value) 00049 valueHash_ = hash(value->get()); 00050 else 00051 valueHash_ = 0; 00052 } 00053 00054 Property 00055 ::Property(const char* name, unsigned int count, String* values) 00056 : name_(name, 0), key_(hash(name)), type_(PT_STRING_LIST) { 00057 v.string_ = values; 00058 valueHash_ = count; 00059 } 00060 00061 Property 00062 ::Property(const char* name, const Action* value) 00063 : name_(name, 0), key_(hash(name)), type_(PT_ACTION) { 00064 v.action_ = value; 00065 } 00066 00067 Property 00068 ::Property(const char* name, const Script* value) 00069 : name_(name, 0), key_(hash(name)), type_(PT_SCRIPT) { 00070 v.script_ = value; 00071 } 00072 00073 Property 00074 ::Property(const char* name, Area* value) 00075 : name_(name, 0), key_(hash(name)), type_(PT_AREA) { 00076 v.area_ = value; 00077 } 00078 00079 Property 00080 ::~Property() { 00081 if(type_ == PT_STRING) { 00082 delete v.string_; 00083 } 00084 } 00085 00086 unsigned int Property 00087 ::hash(const char* name) { 00088 unsigned int h = 2166136261; 00089 for(const char* n = name; *n != 0; ++n) { 00090 h *= 16777619 * h; 00091 h ^= *n; 00092 } 00093 h ^= h >> 16; 00094 return (h & 0xffff); 00095 } 00096 00097 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.