Property.hpp

Go to the documentation of this file.
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 #ifndef engine_stat_Property_hpp
00023 #define engine_stat_Property_hpp
00024 
00025 #include "util/error/Log.hpp"
00026 #include "util/type/util_type.hpp"
00027 #include "sim/action/sim_action.hpp"
00028 #include "sim/area/sim_area.hpp"
00029 #include "sim/script/sim_script.hpp"
00030 #include "sim/thing/sim_thing.hpp"
00031 #include "comp/comp.hpp"
00032 
00033 
00034 namespace se_core {
00035     class _SeCoreExport Property {
00036     public:
00037         enum Type {
00038             PT_NONE, PT_SHORT, PT_INT, PT_HASH, PT_FLOAT, PT_SCRIPT, PT_ACTION, PT_AREA, PT_STRING, PT_STRING_LIST, PT_END_OF_TYPES
00039         };
00040         static unsigned int hash(const char* name);
00041 
00042     private:
00044         unsigned int key_;
00046         unsigned int valueHash_; // 
00047         Type type_;
00048         String name_;
00049 
00050         union {
00051             void* value_;
00052             const Action* action_;
00053             const Script* script_;
00054             Area* area_;
00055             String* string_;
00056             short shortValue_;
00057             int intValue_;
00058             float  floatValue_;
00059         } v;
00060 
00061     public:
00062         Property(const char* name, short value);
00063         Property(const char* name, int value);
00064         Property(const char* name, float value);
00065         Property(const char* name, String* value);
00066         Property(const char* name, unsigned int count, String* values);
00067         Property(const char* name, const Action* value);
00068         Property(const char* name, const Script* value);
00069         Property(const char* name, Area* value);
00070         ~Property();
00071 
00072         inline const char* name() const {
00073             return name_.get();
00074         }
00075 
00076         inline Type type() const { 
00077             return type_; 
00078         }
00079         unsigned int key() const {
00080             return key_;
00081         }
00082 
00083         inline short shortValue() const {
00084             Assert(type_ == PT_SHORT);
00085             return v.shortValue_;
00086         }
00087 
00088         inline int intValue() const {
00089             Assert(type_ == PT_INT);
00090             return v.intValue_;
00091         }
00092 
00093         inline unsigned int hashValue() const {
00094             Assert(type_ == PT_STRING);
00095             return valueHash_;
00096         }
00097 
00098         inline float floatValue() const {
00099             Assert(type_ == PT_FLOAT);
00100             return v.floatValue_;
00101         }
00102 
00103         inline const char* string() const {
00104             Assert(type_ == PT_STRING);
00105             return v.string_->get();
00106         }
00107 
00108         inline unsigned int valueCount() const {
00109             if(type_ == PT_STRING) {
00110                 return 1;
00111             }
00112             return valueHash_;
00113         }
00114 
00115         inline const char* string(unsigned int index) const {
00116             Assert(type_ == PT_STRING_LIST || type_ == PT_STRING);
00117             Assert(index < valueCount());
00118             return v.string_[index].get();
00119         }
00120 
00121         inline const Action* action() const {
00122             Assert(type_ == PT_ACTION);
00123             return v.action_;
00124         }
00125 
00126         inline const Script* script() const {
00127             Assert(type_ == PT_SCRIPT);
00128             return v.script_;
00129         }
00130 
00131         inline Area* area() const {
00132             Assert(type_ == PT_AREA);
00133             return v.area_;
00134         }
00135 
00136     };
00137 }
00138 
00139 #endif

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo