XdmfAttributeType.cpp 4.53 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

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

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

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

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

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

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

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

85
XdmfAttributeType::XdmfAttributeType(const std::string & name) :
86
  mName(name)
87 88
{
}
89

90
XdmfAttributeType::~XdmfAttributeType()
91 92 93
{
}

94
shared_ptr<const XdmfAttributeType>
95
XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties)
96
{
97 98 99 100 101
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("AttributeType");
  }
102
  if(type == itemProperties.end()) {
103 104
    // to support old xdmf defaults, return Scalar()
    return Scalar();
105 106 107 108 109 110 111 112 113 114 115 116 117 118
  }
  const std::string & typeVal = type->second;

  if(typeVal.compare("Scalar") == 0) {
    return Scalar();
  }
  else if(typeVal.compare("Vector") == 0) {
    return Vector();
  }
  else if(typeVal.compare("Tensor") == 0) {
    return Tensor();
  }
  else if(typeVal.compare("Matrix") == 0) {
    return Matrix();
119
  }
120 121 122 123 124 125 126 127 128 129
  else if(typeVal.compare("Tensor6") == 0) {
    return Tensor6();
  }
  else if(typeVal.compare("GlobalId") == 0) {
    return GlobalId();
  }
  else if(typeVal.compare("None") == 0) {
    return NoAttributeType();
  }

130 131 132 133 134 135 136 137 138
  try {
    XdmfError::message(XdmfError::FATAL, 
                       "Type not of 'None','Scalar','Vector','Tensor', "
                       "'Matrix','Tensor6', or 'GlobalId' in "
                       "XdmfAttributeType::New");
  }
  catch (XdmfError e) {
    throw e;
  }
139

140
  return shared_ptr<const XdmfAttributeType>();
141 142
}

143 144
void
XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
145
{
146
  collectedProperties.insert(std::make_pair("Type", mName));
147
}