XdmfAttributeType.cpp 5.25 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 : XdmfAttributeType.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 "XdmfAttributeType.hpp"
26
#include "XdmfError.hpp"
27

28 29
std::map<std::string, shared_ptr<const XdmfAttributeType>(*)()> XdmfAttributeType::mAttributeDefinitions;

30
// Supported XdmfAttributeTypes
31
shared_ptr<const XdmfAttributeType>
32
XdmfAttributeType::NoAttributeType()
33
{
34
  static shared_ptr<const XdmfAttributeType> 
35 36
    p(new XdmfAttributeType("None"));
  return p;
37 38
}

39
shared_ptr<const XdmfAttributeType>
40
XdmfAttributeType::Scalar()
41
{
42
  static shared_ptr<const XdmfAttributeType> 
43 44
    p(new XdmfAttributeType("Scalar"));
  return p;
45 46
}

47
shared_ptr<const XdmfAttributeType>
48
XdmfAttributeType::Vector()
49
{
50
  static shared_ptr<const XdmfAttributeType> 
51 52
    p(new XdmfAttributeType("Vector"));
  return p;
53 54
}

55
shared_ptr<const XdmfAttributeType>
56
XdmfAttributeType::Tensor()
57
{
58
  static shared_ptr<const XdmfAttributeType>
59 60
    p(new XdmfAttributeType("Tensor"));
  return p;
61 62
}

63
shared_ptr<const XdmfAttributeType>
64
XdmfAttributeType::Matrix()
65
{
66
  static shared_ptr<const XdmfAttributeType>
67 68
    p(new XdmfAttributeType("Matrix"));
  return p;
69 70
}

71
shared_ptr<const XdmfAttributeType>
72
XdmfAttributeType::Tensor6()
73
{
74
  static shared_ptr<const XdmfAttributeType>
75 76
    p(new XdmfAttributeType("Tensor6"));
  return p;
77 78
}

79
shared_ptr<const XdmfAttributeType>
80
XdmfAttributeType::GlobalId()
81
{
82
  static shared_ptr<const XdmfAttributeType>
83 84
    p(new XdmfAttributeType("GlobalId"));
  return p;
85 86
}

87 88 89 90 91 92 93 94 95 96 97 98
void
XdmfAttributeType::InitTypes()
{
  mAttributeDefinitions["NONE"] = NoAttributeType;
  mAttributeDefinitions["SCALAR"] = Scalar;
  mAttributeDefinitions["VECTOR"] = Vector;
  mAttributeDefinitions["TENSOR"] = Tensor;
  mAttributeDefinitions["MATRIX"] = Matrix;
  mAttributeDefinitions["TENSOR6"] = Tensor6;
  mAttributeDefinitions["GLOBALID"] = GlobalId;
}

99
XdmfAttributeType::XdmfAttributeType(const std::string & name) :
100
  mName(name)
101 102
{
}
103

104
XdmfAttributeType::~XdmfAttributeType()
105 106 107
{
}

108
shared_ptr<const XdmfAttributeType>
109
XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties)
110
{
111
  InitTypes();
112 113 114 115 116
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("AttributeType");
  }
117
  if(type == itemProperties.end()) {
118 119
    // to support old xdmf defaults, return Scalar()
    return Scalar();
120 121
  }

122

123
  const std::string & typeVal = ConvertToUpper(type->second);
124 125 126 127 128 129 130 131

  std::map<std::string, shared_ptr<const XdmfAttributeType>(*)()>::const_iterator returnType = mAttributeDefinitions.find(typeVal);

  if (returnType == mAttributeDefinitions.end()) {
    XdmfError::message(XdmfError::FATAL,
                       "Type not of 'None','Scalar','Vector','Tensor', "
                       "'Matrix','Tensor6', or 'GlobalId' in "
                       "XdmfAttributeType::New");
132
  }
133 134
  else {
    return (*(returnType->second))();
135 136
  }

137
  // unreachable
138
  return shared_ptr<const XdmfAttributeType>();
139 140
}

141 142
void
XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
143
{
144
  collectedProperties.insert(std::make_pair("Type", mName));
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

// C Wrappers

int XdmfAttributeTypeScalar()
{
  return XDMF_ATTRIBUTE_TYPE_SCALAR;
}

int XdmfAttributeTypeVector()
{
  return XDMF_ATTRIBUTE_TYPE_VECTOR;
}

int XdmfAttributeTypeTensor()
{
  return XDMF_ATTRIBUTE_TYPE_TENSOR;
}

int XdmfAttributeTypeMatrix()
{
  return XDMF_ATTRIBUTE_TYPE_MATRIX;
}

int XdmfAttributeTypeTensor6()
{
  return XDMF_ATTRIBUTE_TYPE_TENSOR6;
}

int XdmfAttributeTypeGlobalId()
{
  return XDMF_ATTRIBUTE_TYPE_GLOBALID;
}

int XdmfAttributeTypeNoAttributeType()
{
  return XDMF_ATTRIBUTE_TYPE_NOTYPE;
}