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

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

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

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

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

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

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

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

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

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

93
shared_ptr<const XdmfAttributeType>
94
XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties)
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
  std::map<std::string, std::string>::const_iterator type =
    itemProperties.find("Type");
  if(type == itemProperties.end()) {
    type = itemProperties.find("AttributeType");
  }
  if(type != itemProperties.end()) {
    const std::string typeVal = type->second;
    if(typeVal.compare("None") == 0) {
      return NoAttributeType();
    }
    else 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();
    }
    else if(typeVal.compare("Tensor6") == 0) {
      return Tensor6();
    }
    else if(typeVal.compare("GlobalId") == 0) {
      return GlobalId();
    }
    else {
125 126 127 128
      XdmfError::message(XdmfError::FATAL, 
                         "Type not of 'None','Scalar','Vector','Tensor', "
                         "'Matrix','Tensor6', or 'GlobalId' in "
                         "XdmfAttributeType::New");
129 130
    }
  }
131 132 133 134
  XdmfError::message(XdmfError::FATAL, 
                     "Neither 'Type' nor 'AttributeType' found in "
                     "itemProperties in XdmfAttributeType::New");
  return shared_ptr<const XdmfAttributeType>();
135 136
}

137 138
void
XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
139
{
140
  collectedProperties["Type"] = mName;
141
}