File: XdmfInformation.cpp

package info (click to toggle)
xdmf 3.0%2Bgit20160803-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,388 kB
  • ctags: 36,627
  • sloc: ansic: 265,382; cpp: 162,889; python: 10,976; f90: 1,378; yacc: 687; fortran: 464; xml: 200; java: 187; lex: 125; makefile: 82; sh: 28
file content (277 lines) | stat: -rw-r--r-- 8,179 bytes parent folder | download | duplicates (13)
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfInformation.cpp                                                 */
/*                                                                           */
/*  Author:                                                                  */
/*     Kenneth Leiter                                                        */
/*     kenneth.leiter@arl.army.mil                                           */
/*     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 "string.h"
#include "XdmfArray.hpp"
#include "XdmfError.hpp"
#include "XdmfInformation.hpp"

XDMF_CHILDREN_IMPLEMENTATION(XdmfInformation, XdmfArray, Array, Name)

shared_ptr<XdmfInformation>
XdmfInformation::New()
{
  shared_ptr<XdmfInformation> p(new XdmfInformation());
  return p;
}

shared_ptr<XdmfInformation>
XdmfInformation::New(const std::string & key,
                     const std::string & value)
{
  shared_ptr<XdmfInformation> p(new XdmfInformation(key, value));
  return p;
}

XdmfInformation::XdmfInformation(const std::string & key,
                                 const std::string & value) :
  mKey(key),
  mValue(value)
{
}

XdmfInformation::XdmfInformation(XdmfInformation & refInfo) :
  XdmfItem(refInfo),
  mArrays(refInfo.mArrays)
{
  mKey = refInfo.getKey();
  mValue = refInfo.getValue();
}

XdmfInformation::~XdmfInformation()
{
}

const std::string XdmfInformation::ItemTag = "Information";

std::map<std::string, std::string>
XdmfInformation::getItemProperties() const
{
  std::map<std::string, std::string> informationProperties;
  informationProperties.insert(std::make_pair("Name", mKey));
  informationProperties.insert(std::make_pair("Value", mValue));
  return informationProperties;
}

std::string
XdmfInformation::getItemTag() const
{
  return ItemTag;
}

std::string
XdmfInformation::getKey() const
{
  return mKey;
}

std::string
XdmfInformation::getValue() const
{
  return mValue;
}

void
XdmfInformation::populateItem(const std::map<std::string, std::string> & itemProperties,
                              const std::vector<shared_ptr<XdmfItem> > & childItems,
                              const XdmfCoreReader * const reader)
{
  XdmfItem::populateItem(itemProperties, childItems, reader);

  std::map<std::string, std::string>::const_iterator key =
    itemProperties.find("Name");
  if(key != itemProperties.end()) {
    mKey = key->second;
  }
  else {
    XdmfError::message(XdmfError::FATAL,
                       "'Name' not found in itemProperties in "
                       "XdmfInformation::populateItem");
  }

  std::map<std::string, std::string>::const_iterator value =
    itemProperties.find("Value");
  if(value != itemProperties.end()) {
    mValue = value->second;
  }
  else {
    value = itemProperties.find("Content");
    if(value != itemProperties.end()) {
      mValue = value->second;
    }
    else {
      XdmfError::message(XdmfError::FATAL,
                         "'Value' not found in itemProperties in "
                         "XdmfInformation::populateItem");
    }
  }
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
        childItems.begin();
      iter != childItems.end();
      ++iter) {
    if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
      this->insert(array);
    }
  }
}

void
XdmfInformation::setKey(const std::string & key)
{
  mKey = key;
  this->setIsChanged(true);
}

void
XdmfInformation::setValue(const std::string & value)
{
  mValue = value;
  this->setIsChanged(true);
}

void
XdmfInformation::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
{
  XdmfItem::traverse(visitor);
  for (unsigned int i = 0; i < mArrays.size(); ++i)
  {
    mArrays[i]->accept(visitor);
  }
}

// C Wrappers

XDMFINFORMATION *
XdmfInformationNew(char * key, char * value)
{
  try
  {
    std::string createKey(key);
    std::string createValue(value);
    shared_ptr<XdmfInformation> generatedInfo = XdmfInformation::New(createKey, createValue);
    return (XDMFINFORMATION *)((void *)(new XdmfInformation(*generatedInfo.get())));
  }
  catch (...)
  {
    std::string createKey(key);
    std::string createValue(value);
    shared_ptr<XdmfInformation> generatedInfo = XdmfInformation::New(createKey, createValue);
    return (XDMFINFORMATION *)((void *)(new XdmfInformation(*generatedInfo.get())));
  }
}

XDMFARRAY *
XdmfInformationGetArray(XDMFINFORMATION * information, unsigned int index)
{
  return (XDMFARRAY *)((void *)(((XdmfInformation *)(information))->getArray(index).get()));
}

XDMFARRAY *
XdmfInformationGetArrayByName(XDMFINFORMATION * information, char * name)
{
  return (XDMFARRAY *)((void *)(((XdmfInformation *)(information))->getArray(name).get()));
}

char *
XdmfInformationGetKey(XDMFINFORMATION * information)
{
  try
  {
    XdmfInformation referenceInfo = *(XdmfInformation *)(information);
    char * returnPointer = strdup(referenceInfo.getKey().c_str());
    return returnPointer;
  }
  catch (...)
  {
    XdmfInformation referenceInfo = *(XdmfInformation *)(information);
    char * returnPointer = strdup(referenceInfo.getKey().c_str());
    return returnPointer;
  }
}

unsigned int
XdmfInformationGetNumberArrays(XDMFINFORMATION * information)
{
  return ((XdmfInformation *)(information))->getNumberArrays();
}

char *
XdmfInformationGetValue(XDMFINFORMATION * information)
{
  try
  {
    XdmfInformation referenceInfo = *(XdmfInformation *)(information);
    char * returnPointer = strdup(referenceInfo.getValue().c_str());
    return returnPointer;
  }
  catch (...)
  { 
    XdmfInformation referenceInfo = *(XdmfInformation *)(information);
    char * returnPointer = strdup(referenceInfo.getValue().c_str());
    return returnPointer;
  }
}

void
XdmfInformationInsertArray(XDMFINFORMATION * information, XDMFARRAY * array, int transferOwnership)
{
  if (transferOwnership) {
    ((XdmfInformation *)(information))->insert(shared_ptr<XdmfArray>((XdmfArray *)array));
  }
  else {
    ((XdmfInformation *)(information))->insert(shared_ptr<XdmfArray>((XdmfArray *)array, XdmfNullDeleter()));
  }
}

void
XdmfInformationRemoveArray(XDMFINFORMATION * information, unsigned int index)
{
  ((XdmfInformation *)(information))->removeArray(index);
}

void
XdmfInformationRemoveArrayByName(XDMFINFORMATION * information, char * name)
{
  ((XdmfInformation *)(information))->removeArray(name);
}

void
XdmfInformationSetKey(XDMFINFORMATION * information, char * key, int * status)
{
  XDMF_ERROR_WRAP_START(status)
  ((XdmfInformation *)(information))->setKey(key);
  XDMF_ERROR_WRAP_END(status)
}

void
XdmfInformationSetValue(XDMFINFORMATION * information, char * value, int * status)
{
  XDMF_ERROR_WRAP_START(status)
  ((XdmfInformation *)(information))->setValue(value);
  XDMF_ERROR_WRAP_END(status)
}

// C Wrappers for parent classes are generated by macros

XDMF_ITEM_C_CHILD_WRAPPER(XdmfInformation, XDMFINFORMATION)