File: XdmfAttributeCenter.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 (154 lines) | stat: -rw-r--r-- 4,970 bytes parent folder | download | duplicates (3)
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
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfAttributeCenter.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 "XdmfAttributeCenter.hpp"
#include "XdmfError.hpp"

std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()> XdmfAttributeCenter::mAttributeCenterDefinitions;

// Supported XdmfAttributeCenters
shared_ptr<const XdmfAttributeCenter>
XdmfAttributeCenter::Grid()
{
  static shared_ptr<const XdmfAttributeCenter>
    p(new XdmfAttributeCenter("Grid"));
  return p;
}

shared_ptr<const XdmfAttributeCenter>
XdmfAttributeCenter::Cell()
{
  static shared_ptr<const XdmfAttributeCenter> 
    p(new XdmfAttributeCenter("Cell"));
  return p;
}

shared_ptr<const XdmfAttributeCenter>
XdmfAttributeCenter::Face()
{
  static shared_ptr<const XdmfAttributeCenter>
    p(new XdmfAttributeCenter("Face"));
  return p;
}

shared_ptr<const XdmfAttributeCenter>
XdmfAttributeCenter::Edge()
{
  static shared_ptr<const XdmfAttributeCenter>
    p(new XdmfAttributeCenter("Edge"));
  return p;
}

shared_ptr<const XdmfAttributeCenter>
XdmfAttributeCenter::Node()
{
  static shared_ptr<const XdmfAttributeCenter>
    p(new XdmfAttributeCenter("Node"));
  return p;
}

void
XdmfAttributeCenter::InitTypes()
{
  mAttributeCenterDefinitions["GRID"] = Grid;
  mAttributeCenterDefinitions["CELL"] = Cell;
  mAttributeCenterDefinitions["FACE"] = Face;
  mAttributeCenterDefinitions["EDGE"] = Edge;
  mAttributeCenterDefinitions["NODE"] = Node;
}

XdmfAttributeCenter::XdmfAttributeCenter(const std::string & name) :
  mName(name)
{
}

XdmfAttributeCenter::~XdmfAttributeCenter()
{
}

shared_ptr<const XdmfAttributeCenter>
XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperties)
{
  InitTypes();
  std::map<std::string, std::string>::const_iterator center =
    itemProperties.find("Center");
  if(center == itemProperties.end()) {
    XdmfError::message(XdmfError::FATAL, 
                       "'Center' not found in itemProperties in "
                       "XdmfAttributeCenter::New");
  }

  const std::string & centerVal = ConvertToUpper(center->second);

  std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()>::const_iterator returnType = mAttributeCenterDefinitions.find(centerVal);

  if (returnType == mAttributeCenterDefinitions.end()) {
    XdmfError::message(XdmfError::FATAL,
                       "Center not of 'Grid','Cell','Face','Edge','Node' "
                       "in XdmfAttributeCenter::New");
  }
  else {
    return (*(returnType->second))();
  }

  XdmfError::message(XdmfError::FATAL, 
                     "Center not of 'Grid','Cell','Face','Edge','Node' "
                     "in XdmfAttributeCenter::New");

  // unreachable
  return shared_ptr<const XdmfAttributeCenter>();
}

void
XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
  collectedProperties.insert(std::make_pair("Center", mName));
}

// C Wrappers

int XdmfAttributeCenterGrid()
{
  return XDMF_ATTRIBUTE_CENTER_GRID;
}

int XdmfAttributeCenterCell()
{
  return XDMF_ATTRIBUTE_CENTER_CELL;
}

int XdmfAttributeCenterFace()
{
  return XDMF_ATTRIBUTE_CENTER_FACE;
}

int XdmfAttributeCenterEdge()
{
  return XDMF_ATTRIBUTE_CENTER_EDGE;
}

int XdmfAttributeCenterNode()
{
  return XDMF_ATTRIBUTE_CENTER_NODE;
}