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 "Object.hpp" 00023 #include "comp/list/ObjectRepository.hpp" 00024 #include "comp/schema/CompSchema.hpp" 00025 00026 namespace se_core { 00027 Object 00028 ::Object(int type, const char* name) 00029 : type_(type), name_(name) { 00030 Assert(name); 00031 id_ = hash(type, name); 00032 CompSchema::objectRepository().add(this); 00033 } 00034 00035 Object 00036 ::~Object() { 00037 CompSchema::objectRepository().remove(this); 00038 } 00039 00040 00041 int Object 00042 ::hash(int type, const char* name) { 00043 int h = 2166136261; 00044 h *= 16777619 * type; 00045 h ^= type; 00046 for(const char* n = name; *n != 0; ++n) { 00047 h *= 16777619; 00048 h ^= *n; 00049 } 00050 //h ^= h >> 16; 00051 return (h & 0xffffffff); 00052 } 00053 00054 00055 const Object* Object 00056 ::_lookup(int hash) { 00057 return CompSchema::objectRepository().get(hash); 00058 } 00059 00060 00061 se_err::Log& operator<< (se_err::Log& log, const Object& o) { 00062 log << o.name() << "(" << o.type() << ", " << o.id() << ")"; 00063 return log; 00064 } 00065 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.