Debian Codegraph @

src/acl/aclMath/aclVectorOfElementsDef.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 ACLVECTORELEMENTSDEF_H
25 #define ACLVECTORELEMENTSDEF_H
26
27 #include <memory>
28 #include <vector>
29 #include "../aclTypes.h"
30
31 using namespace std;
32
33 namespace cl
34 {
35 class CommandQueue;
36 }
37
38 namespace acl
39 {
40
41 class ElementBase;
42 class MemBlock;
43
44 typedef std::shared_ptr<ElementBase> Element;
45 typedef std::shared_ptr<MemBlock> ElementData;
46
47 class VectorOfElements;
48 typedef std::shared_ptr<cl::CommandQueue> CommandQueue;
49
50 /// The class represents several ::ElementData
51 /**
52 \ingroup ComplexDataTypes
53 Basicaly the class is identical to the std::vector class. The only
54 difference is the assigment operator and mathematical operations.
55 */
56 class VectorOfElementsData: public std::vector<ElementData>
57 {
58 /// checks whether all Elements have sizes compatible
59 /// with each other and reside on the same device
60 bool checkCompatibility() const;
61 public:
62 /// checks whether all Elements have sizes compatible with \p n
63 bool checkSizesCompatibility(unsigned int n) const;
64 VectorOfElementsData();
65 explicit VectorOfElementsData(unsigned int n);
66 /**
67 \param n number of ElementData
68 \param s size of each ElementData
69 \param T type of ElementData: e.g. float double etc.
70 \param queue defines a device where the DataElements should be placed
71 */
72 template <typename T> VectorOfElementsData(unsigned int n,
73 unsigned int s,
74 T);
75 template <typename T> VectorOfElementsData(unsigned int n,
76 unsigned int s,
77 T,
78 CommandQueue queue);
79
80 VectorOfElements operator=(const VectorOfElements & a) const;
81 VectorOfElements operator=(const VectorOfElementsData & a) const;
82 void resizeElements(unsigned int n);
83 };
84
85 /// The class represents several ::Element
86 /**
87 \ingroup ComplexDataTypes
88 Basicaly the class is identical to the std::vector class. The only
89 difference is the assigment operator and mathematical operations.
90 */
91 class VectorOfElements: public std::vector<Element>
92 {
93 /// checks whether all Elements have sizes compatible
94 /// with each other and reside on the same device
95 bool checkCompatibility() const;
96 public:
97 /// checks whether all Elements have sizes compatible with \p n
98 bool checkSizesCompatibility(unsigned int n) const;
99 VectorOfElements();
100 explicit VectorOfElements(unsigned int n);
101 VectorOfElements(const VectorOfElementsData & a);
102 VectorOfElements operator=(const VectorOfElements & a) const;
103 };
104
105 typedef shared_ptr<VectorOfElementsData> SPVectorOfElementsData;
106 typedef shared_ptr<VectorOfElements> SPVectorOfElements;
107
108 inline bool compatibleSizes (unsigned int s, const VectorOfElements & a);
109
110 ///\related VectorOfElements
111 acl::TypeID getElementType(const VectorOfElements & a, unsigned int i = 0);
112
113 ///\related VectorOfElements
114 unsigned int getElementsSize(const VectorOfElements & a);
115
116 //------------------------- Implementation -----------------
117
118 inline bool compatibleSizes(unsigned int s, const VectorOfElements & a)
119 {
120 return a.checkSizesCompatibility(s);
121 }
122
123
124 } // namespace acl
125
126 #endif // ACLVECTORELEMENTSDEF_H