-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXdmfGeometryType.cpp
242 lines (214 loc) · 6.84 KB
/
XdmfGeometryType.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*****************************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : XdmfGeometryType.cpp */
/* */
/* Author: */
/* Kenneth Leiter */
/* [email protected] */
/* US Army Research Laboratory */
/* Aberdeen Proving Ground, MD */
/* */
/* Copyright @ 2011 US Army Research Laboratory */
/* All Rights Reserved */
/* See Copyright.txt for details */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfGeometryType.hpp"
#include "XdmfError.hpp"
#include "string.h"
#include <sstream>
std::map<std::string, shared_ptr<const XdmfGeometryType>(*)()> XdmfGeometryType::mGeometryDefinitions;
// Supported XdmfGeometryTypes
shared_ptr<const XdmfGeometryType>
XdmfGeometryType::NoGeometryType()
{
static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("None", 0));
return p;
}
shared_ptr<const XdmfGeometryType>
XdmfGeometryType::XYZ()
{
static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("XYZ", 3));
return p;
}
shared_ptr<const XdmfGeometryType>
XdmfGeometryType::XY()
{
static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("XY", 2));
return p;
}
shared_ptr<const XdmfGeometryType>
XdmfGeometryType::Polar()
{
static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("Polar", 2));
return p;
}
shared_ptr<const XdmfGeometryType>
XdmfGeometryType::Spherical()
{
static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("Spherical", 3));
return p;
}
void
XdmfGeometryType::InitTypes()
{
mGeometryDefinitions["NONE"] = NoGeometryType;
mGeometryDefinitions["XYZ"] = XYZ;
mGeometryDefinitions["XY"] = XY;
mGeometryDefinitions["POLAR"] = Polar;
mGeometryDefinitions["SPHERICAL"] = Spherical;
}
XdmfGeometryType::XdmfGeometryType(const std::string& name,
const int& dimensions) :
mDimensions(dimensions),
mName(name)
{
}
XdmfGeometryType::~XdmfGeometryType()
{
}
shared_ptr<const XdmfGeometryType>
XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
{
InitTypes();
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("Type");
if(type == itemProperties.end()) {
type = itemProperties.find("GeometryType");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'GeometryType' in itemProperties "
"in XdmfGeometryType::New");
}
const std::string & typeVal = ConvertToUpper(type->second);
std::map<std::string, shared_ptr<const XdmfGeometryType>(*)()>::const_iterator returnType
= mGeometryDefinitions.find(typeVal);
if (returnType == mGeometryDefinitions.end()) {
XdmfError::message(XdmfError::FATAL, "Type "
+ typeVal + " not Supported "
"in XdmfGeometryType::New");
}
else {
return (*(returnType->second))();
}
return shared_ptr<const XdmfGeometryType>();
}
unsigned int
XdmfGeometryType::getDimensions() const
{
return mDimensions;
}
std::string
XdmfGeometryType::getName() const
{
return mName;
}
void
XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties.insert(std::make_pair("Type", mName));
}
// C Wrappers
int XdmfGeometryTypeNoGeometryType()
{
return XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE;
}
int XdmfGeometryTypeXYZ()
{
return XDMF_GEOMETRY_TYPE_XYZ;
}
int XdmfGeometryTypeXY()
{
return XDMF_GEOMETRY_TYPE_XY;
}
int XdmfGeometryTypePolar()
{
return XDMF_GEOMETRY_TYPE_POLAR;
}
int XdmfGeometryTypeSpherical()
{
return XDMF_GEOMETRY_TYPE_SPHERICAL;
}
unsigned int XdmfGeometryTypeGetDimensions(int type, int * status)
{
XDMF_ERROR_WRAP_START(status)
switch (type) {
case XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE:
return XdmfGeometryType::NoGeometryType()->getDimensions();
break;
case XDMF_GEOMETRY_TYPE_XYZ:
return XdmfGeometryType::XYZ()->getDimensions();
break;
case XDMF_GEOMETRY_TYPE_XY:
return XdmfGeometryType::XY()->getDimensions();
break;
case XDMF_GEOMETRY_TYPE_POLAR:
return XdmfGeometryType::Polar()->getDimensions();
break;
case XDMF_GEOMETRY_TYPE_SPHERICAL:
return XdmfGeometryType::Spherical()->getDimensions();
break;
default:
try {
std::stringstream sstr;
sstr << "Error: Invalid Geometry Type: Code " << type;
XdmfError::message(XdmfError::FATAL, sstr.str());
}
catch (XdmfError & e) {
throw e;
}
break;
}
XDMF_ERROR_WRAP_END(status)
return 0;
}
char * XdmfGeometryTypeGetName(int type)
{
switch (type) {
case XDMF_GEOMETRY_TYPE_NO_GEOMETRY_TYPE:
{
char * returnPointer = strdup(XdmfGeometryType::NoGeometryType()->getName().c_str());
return returnPointer;
break;
}
case XDMF_GEOMETRY_TYPE_XYZ:
{
char * returnPointer = strdup(XdmfGeometryType::XYZ()->getName().c_str());
return returnPointer;
break;
}
case XDMF_GEOMETRY_TYPE_XY:
{
char * returnPointer = strdup(XdmfGeometryType::XY()->getName().c_str());
return returnPointer;
break;
}
case XDMF_GEOMETRY_TYPE_POLAR:
{
char * returnPointer = strdup(XdmfGeometryType::Polar()->getName().c_str());
return returnPointer;
break;
}
case XDMF_GEOMETRY_TYPE_SPHERICAL:
{
char * returnPointer = strdup(XdmfGeometryType::Spherical()->getName().c_str());
return returnPointer;
break;
}
default:
{
char * returnPointer = NULL;
return returnPointer;
break;
}
}
}