source: src/base/object.hpp@ fcf7f6

Last change on this file since fcf7f6 was fcf7f6, checked in by Julian Iseringhausen <isering@…>, 14 years ago

vmg: Added license files and headers (GPLv3).

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1812 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * @file object.hpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 12:22:29 2011
23 *
24 * @brief Header file for the class VMG::Object.
25 *
26 */
27
28#ifndef OBJECT_HPP_
29#define OBJECT_HPP_
30
31#include <cassert>
32#include <string>
33
34namespace VMG
35{
36
37class Object
38{
39public:
40 Object() :
41 registered(false)
42 {
43 }
44
45 Object(std::string name_) :
46 name(name_),
47 registered(true)
48 {
49 ObjectInit();
50 }
51
52 Object(const Object& other) :
53 name(other.name),
54 registered(other.registered)
55 {
56 }
57
58 virtual ~Object() {}
59
60 void Register(std::string name_);
61
62 template <class T>
63 T* Cast()
64 {
65 T* casted = dynamic_cast<T*>(this);
66 assert(casted != NULL);
67 return casted;
68 }
69
70 std::string Name() {return name;}
71
72private:
73 void ObjectInit();
74
75 std::string name;
76 bool registered;
77};
78
79template <class T>
80class ObjectStorage : public Object
81{
82public:
83 ObjectStorage(const T& val) :
84 val(val)
85 {}
86
87 ObjectStorage(std::string name, const T& val) :
88 Object(name),
89 val(val)
90 {}
91
92 T& Val() {return val;}
93
94protected:
95 T val;
96};
97
98template <class T>
99class ObjectStorageArray : public ObjectStorage<T*>
100{
101public:
102 ObjectStorageArray(const vmg_int& size) :
103 ObjectStorage<T*>(new T[size])
104 {}
105
106 ObjectStorageArray(std::string name, const vmg_int& size) :
107 ObjectStorage<T*>(name, new T[size])
108 {}
109
110 virtual ~ObjectStorageArray()
111 {
112 delete [] this->val;
113 }
114};
115
116}
117
118#endif /* OBJECT_HPP_ */
Note: See TracBrowser for help on using the repository browser.