Debian Codegraph @

src/data/aslDataWrapper.h

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 #ifndef ASLDATAWRAPPER_H
25 #define ASLDATAWRAPPER_H
26
27 #include "aslBlocks.h"
28 #include "../acl/aclMath/aclVectorOfElementsDef.h"
29 #include <iostream>
30 #include <fstream>
31
32 /**
33 \defgroup DataFields Data Fileds
34 \ingroup Numerics
35 */
36
37 namespace acl
38 {
39 void copy(const vector<Element> & source,
40 VectorOfElements & destination);
41 void copy(const VectorOfElementsData & source,
42 VectorOfElementsData & destination);
43 }
44
45
46 using namespace std;
47
48 namespace asl
49 {
50
51 /// \ingroup DataFields
52 class AbstractData
53 {
54 protected:
55 Block block;
56 inline AbstractData();
57 inline explicit AbstractData(const Block & b);
58 public:
59 virtual const acl::VectorOfElements getEContainer() = 0;
60 virtual const acl::VectorOfElementsData getDContainer() const = 0;
61 inline const Block & getBlock() const;
62 inline void setBlock(const Block & b);
63 };
64
65 typedef shared_ptr<AbstractData> SPAbstractData;
66
67
68 /// Class defines a folding rule into a 1D/2D/3D bulk
69 /**
70 \param V is type of the container
71 \ingroup DataFields
72
73 \todo resolve consistency issue with setBlock()
74
75 */
76 template <typename V> class DataWrapper: public AbstractData
77 {
78 protected:
79 V container;
80 virtual bool checkConsistency() const;
81 public:
82 inline DataWrapper();
83 inline explicit DataWrapper(const Block & b);
84 inline DataWrapper(DataWrapper & d);
85 virtual const acl::VectorOfElements getEContainer();
86 virtual const acl::VectorOfElementsData getDContainer() const;
87 inline V & getContainer();
88 inline void setContainer(const V & cont);
89 };
90
91 typedef DataWrapper<acl::VectorOfElements> DataWrapperACL;
92 typedef DataWrapper<acl::VectorOfElementsData> DataWrapperACLData;
93
94 typedef shared_ptr<DataWrapperACL> SPDataWrapperACL;
95 typedef shared_ptr<DataWrapperACLData> SPDataWrapperACLData;
96
97
98 // ---------------------------- Implementation ---------------------------
99
100 AbstractData::AbstractData()
101 {
102 }
103
104 AbstractData::AbstractData(const Block & b):
105 block(b)
106 {
107 }
108
109 template <typename V> DataWrapper<V>::DataWrapper():
110 AbstractData()
111 {
112 }
113
114 template <typename V> DataWrapper<V>::DataWrapper(const Block & b):
115 AbstractData(b)
116 {
117 }
118
119 template <typename V> DataWrapper<V>::DataWrapper(DataWrapper & d):
120 AbstractData(d.block),
121 container(d.container)
122 {
123 }
124
125 template <typename V> inline V & DataWrapper<V>::getContainer()
126 {
127 return container;
128 }
129
130 template <typename V> inline void DataWrapper<V>::setContainer(const V & cont)
131 {
132 copy(cont, container);
133 }
134
135 inline const Block & AbstractData::getBlock() const
136 {
137 return block;
138 }
139
140 inline void AbstractData::setBlock(const Block & b)
141 {
142 block=b;
143 }
144
145 }
146 #endif
147