XdmfSetType.cpp 4.49 KB
Newer Older
Kenneth Leiter's avatar
Kenneth Leiter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************/
/*                                    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.                                                 */
/*                                                                           */
/*****************************************************************************/
23

24
#include <utility>
25
#include "XdmfSetType.hpp"
26
#include "XdmfError.hpp"
27

28 29
std::map<std::string, shared_ptr<const XdmfSetType>(*)()> XdmfSetType::mSetDefinitions;

30
// Supported XdmfSetTypes
31
shared_ptr<const XdmfSetType>
32
XdmfSetType::NoSetType()
33
{
34
  static shared_ptr<const XdmfSetType> p(new XdmfSetType("None"));
35
  return p;
36 37
}

38
shared_ptr<const XdmfSetType>
39
XdmfSetType::Node()
40
{
41
  static shared_ptr<const XdmfSetType> p(new XdmfSetType("Node"));
42
  return p;
43 44
}

45
shared_ptr<const XdmfSetType>
46
XdmfSetType::Cell()
47
{
48
  static shared_ptr<const XdmfSetType> p(new XdmfSetType("Cell"));
49
  return p;
50 51
}

52
shared_ptr<const XdmfSetType>
53
XdmfSetType::Face()
54
{
55
  static shared_ptr<const XdmfSetType> p(new XdmfSetType("Face"));
56
  return p;
57 58
}

59
shared_ptr<const XdmfSetType>
60
XdmfSetType::Edge()
61
{
62
  static shared_ptr<const XdmfSetType> p(new XdmfSetType("Edge"));
63
  return p;
64 65
}

66 67 68 69 70 71 72 73 74 75
void
XdmfSetType::InitTypes()
{
  mSetDefinitions["NONE"] = NoSetType;
  mSetDefinitions["NODE"] = Node;
  mSetDefinitions["CELL"] = Cell;
  mSetDefinitions["FACE"] = Face;
  mSetDefinitions["EDGE"] = Edge;
}

76
XdmfSetType::XdmfSetType(const std::string & name) :
77
  mName(name)
78 79 80
{
}

81 82 83 84
XdmfSetType::~XdmfSetType()
{
}

85
shared_ptr<const XdmfSetType>
86
XdmfSetType::New(const std::map<std::string, std::string> & itemProperties)
87
{
88 89
  InitTypes();

90 91 92 93 94
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("SetType");
  }
95
  if(type == itemProperties.end()) {
96 97 98
    XdmfError::message(XdmfError::FATAL, 
                       "Neither 'Type' nor 'SetType' found in itemProperties "
                       "in XdmfSetType::New");
99
  }
100
  const std::string & typeVal = ConvertToUpper(type->second);
101

102 103 104 105 106 107 108
  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");
109
  }
110 111
  else {
    return (*(returnType->second))();
112 113
  }

114 115 116
  XdmfError::message(XdmfError::FATAL, 
                     "Type not of 'None', 'Node', 'Cell', 'Face', or "
                     "'Edge' in XdmfSetType::New");
117

118
  // unreachable
119
  return shared_ptr<const XdmfSetType>();
120 121
}

122 123
void
XdmfSetType::getProperties(std::map<std::string, std::string> & collectedProperties) const
124
{
125
  collectedProperties.insert(std::make_pair("Type", mName));
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

// 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;
}