XdmfGeometryType.cpp 3.84 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 : XdmfGeometryType.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 "XdmfGeometryType.hpp"
26
#include "XdmfError.hpp"
27 28

// Supported XdmfGeometryTypes
29
shared_ptr<const XdmfGeometryType>
30
XdmfGeometryType::NoGeometryType()
31
{
32
  static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("None", 0));
33
  return p;
34
}
35

36
shared_ptr<const XdmfGeometryType>
37
XdmfGeometryType::XYZ()
38
{
39
  static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("XYZ", 3));
40
  return p;
41
}
42

43
shared_ptr<const XdmfGeometryType>
44
XdmfGeometryType::XY()
45
{
46
  static shared_ptr<const XdmfGeometryType> p(new XdmfGeometryType("XY", 2));
47
  return p;
48
}
49

50 51 52 53
XdmfGeometryType::XdmfGeometryType(const std::string& name,
                                   const int& dimensions) :
  mDimensions(dimensions),
  mName(name)
54 55 56
{
}

57 58 59 60
XdmfGeometryType::~XdmfGeometryType()
{
}

61
shared_ptr<const XdmfGeometryType>
62
XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
63
{
64 65 66 67 68
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("GeometryType");
  }
69
  if(type == itemProperties.end()) {
70 71 72 73 74 75 76 77
    try {
      XdmfError::message(XdmfError::FATAL, 
                         "Neither 'Type' nor 'GeometryType' in itemProperties "
                         "in XdmfGeometryType::New");
      }
      catch (XdmfError e) {
        throw e;
      }
78 79
  }
  const std::string & typeVal = type->second;
80

81 82 83 84 85
  if(typeVal.compare("None") == 0) {
    return NoGeometryType();
  }
  else if(typeVal.compare("XYZ") == 0) {
    return XYZ();
86
  }
87 88 89 90
  else if(typeVal.compare("XY") == 0) {
    return XY();
  }

91 92 93 94 95 96 97
  try {
    XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' "
                       "in XdmfGeometryType::New");
  }
  catch (XdmfError e) {
    throw e;
  }
98

99
  return shared_ptr<const XdmfGeometryType>();
100
}
101

102 103
unsigned int
XdmfGeometryType::getDimensions() const
104
{
105
  return mDimensions;
106 107
}

108 109
std::string
XdmfGeometryType::getName() const
110
{
111
  return mName;
112 113
}

114 115
void
XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
116
{
117
  collectedProperties.insert(std::make_pair("Type", mName));
118
}