| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @file object.hpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 12:22:29 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Header file for the class VMG::Object.
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifndef OBJECT_HPP_
|
|---|
| 11 | #define OBJECT_HPP_
|
|---|
| 12 |
|
|---|
| 13 | #include <cassert>
|
|---|
| 14 | #include <string>
|
|---|
| 15 |
|
|---|
| 16 | namespace VMG
|
|---|
| 17 | {
|
|---|
| 18 |
|
|---|
| 19 | class Object
|
|---|
| 20 | {
|
|---|
| 21 | public:
|
|---|
| 22 | Object() :
|
|---|
| 23 | registered(false)
|
|---|
| 24 | {
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | Object(std::string name_) :
|
|---|
| 28 | name(name_),
|
|---|
| 29 | registered(true)
|
|---|
| 30 | {
|
|---|
| 31 | ObjectInit();
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | Object(const Object& other) :
|
|---|
| 35 | name(other.name),
|
|---|
| 36 | registered(other.registered)
|
|---|
| 37 | {
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | virtual ~Object() {}
|
|---|
| 41 |
|
|---|
| 42 | void Register(std::string name_);
|
|---|
| 43 |
|
|---|
| 44 | template <class T>
|
|---|
| 45 | T* Cast()
|
|---|
| 46 | {
|
|---|
| 47 | T* casted = dynamic_cast<T*>(this);
|
|---|
| 48 | assert(casted != NULL);
|
|---|
| 49 | return casted;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | std::string Name() {return name;}
|
|---|
| 53 |
|
|---|
| 54 | private:
|
|---|
| 55 | void ObjectInit();
|
|---|
| 56 |
|
|---|
| 57 | std::string name;
|
|---|
| 58 | bool registered;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | template <class T>
|
|---|
| 62 | class ObjectStorage : public Object
|
|---|
| 63 | {
|
|---|
| 64 | public:
|
|---|
| 65 | ObjectStorage(const T& val) :
|
|---|
| 66 | val(val)
|
|---|
| 67 | {}
|
|---|
| 68 |
|
|---|
| 69 | ObjectStorage(std::string name, const T& val) :
|
|---|
| 70 | Object(name),
|
|---|
| 71 | val(val)
|
|---|
| 72 | {}
|
|---|
| 73 |
|
|---|
| 74 | T& Val() {return val;}
|
|---|
| 75 |
|
|---|
| 76 | protected:
|
|---|
| 77 | T val;
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | template <class T>
|
|---|
| 81 | class ObjectStorageArray : public ObjectStorage<T*>
|
|---|
| 82 | {
|
|---|
| 83 | public:
|
|---|
| 84 | ObjectStorageArray(const vmg_int& size) :
|
|---|
| 85 | ObjectStorage<T*>(new T[size])
|
|---|
| 86 | {}
|
|---|
| 87 |
|
|---|
| 88 | ObjectStorageArray(std::string name, const vmg_int& size) :
|
|---|
| 89 | ObjectStorage<T*>(name, new T[size])
|
|---|
| 90 | {}
|
|---|
| 91 |
|
|---|
| 92 | virtual ~ObjectStorageArray()
|
|---|
| 93 | {
|
|---|
| 94 | delete [] this->val;
|
|---|
| 95 | }
|
|---|
| 96 | };
|
|---|
| 97 |
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | #endif /* OBJECT_HPP_ */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.