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
|
/*****************************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : XdmfSetType.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 "XdmfSetType.hpp"
#include "XdmfError.hpp"
std::map<std::string, shared_ptr<const XdmfSetType>(*)()> XdmfSetType::mSetDefinitions;
// Supported XdmfSetTypes
shared_ptr<const XdmfSetType>
XdmfSetType::NoSetType()
{
static shared_ptr<const XdmfSetType> p(new XdmfSetType("None"));
return p;
}
shared_ptr<const XdmfSetType>
XdmfSetType::Node()
{
static shared_ptr<const XdmfSetType> p(new XdmfSetType("Node"));
return p;
}
shared_ptr<const XdmfSetType>
XdmfSetType::Cell()
{
static shared_ptr<const XdmfSetType> p(new XdmfSetType("Cell"));
return p;
}
shared_ptr<const XdmfSetType>
XdmfSetType::Face()
{
static shared_ptr<const XdmfSetType> p(new XdmfSetType("Face"));
return p;
}
shared_ptr<const XdmfSetType>
XdmfSetType::Edge()
{
static shared_ptr<const XdmfSetType> p(new XdmfSetType("Edge"));
return p;
}
void
XdmfSetType::InitTypes()
{
mSetDefinitions["NONE"] = NoSetType;
mSetDefinitions["NODE"] = Node;
mSetDefinitions["CELL"] = Cell;
mSetDefinitions["FACE"] = Face;
mSetDefinitions["EDGE"] = Edge;
}
XdmfSetType::XdmfSetType(const std::string & name) :
mName(name)
{
}
XdmfSetType::~XdmfSetType()
{
}
shared_ptr<const XdmfSetType>
XdmfSetType::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("SetType");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'SetType' found in itemProperties "
"in XdmfSetType::New");
}
const std::string & typeVal = ConvertToUpper(type->second);
std::map<std::string, shared_ptr<const XdmfSetType>(*)()>::const_iterator returnType
= mSetDefinitions.find(typeVal);
if (returnType == mSetDefinitions.end()) {
XdmfError::message(XdmfError::FATAL,
"Type not of 'None', 'Node', 'Cell', 'Face', or "
"'Edge' in XdmfSetType::New");
}
else {
return (*(returnType->second))();
}
XdmfError::message(XdmfError::FATAL,
"Type not of 'None', 'Node', 'Cell', 'Face', or "
"'Edge' in XdmfSetType::New");
// unreachable
return shared_ptr<const XdmfSetType>();
}
void
XdmfSetType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties.insert(std::make_pair("Type", mName));
}
// C Wrappers
int XdmfSetTypeNoSetType()
{
return XDMF_SET_TYPE_NO_SET_TYPE;
}
int XdmfSetTypeNode()
{
return XDMF_SET_TYPE_NODE;
}
int XdmfSetTypeCell()
{
return XDMF_SET_TYPE_CELL;
}
int XdmfSetTypeFace()
{
return XDMF_SET_TYPE_FACE;
}
int XdmfSetTypeEdge()
{
return XDMF_SET_TYPE_EDGE;
}
|