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

// Supported XdmfAttributeCenters
29
shared_ptr<const XdmfAttributeCenter>
30
XdmfAttributeCenter::Grid()
31
{
32
  static shared_ptr<const XdmfAttributeCenter>
33 34
    p(new XdmfAttributeCenter("Grid"));
  return p;
35 36
}

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

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

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

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

69
XdmfAttributeCenter::XdmfAttributeCenter(const std::string & name) :
70
  mName(name)
71 72
{
}
73

74
XdmfAttributeCenter::~XdmfAttributeCenter()
75 76 77
{
}

78
shared_ptr<const XdmfAttributeCenter>
79
XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperties)
80
{
81 82
  std::map<std::string, std::string>::const_iterator center =
    itemProperties.find("Center");
83
  if(center == itemProperties.end()) {
84 85 86 87 88 89 90 91
    try {
      XdmfError::message(XdmfError::FATAL, 
                         "'Center' not found in itemProperties in "
                         "XdmfAttributeCenter::New");
    }
    catch (XdmfError e) {
      throw e;
    }
92
  }
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  const std::string & centerVal = center->second;
  
  if(centerVal.compare("Node") == 0) {
    return Node();
  }
  else if(centerVal.compare("Cell") == 0) {
    return Cell();
  }
  else if(centerVal.compare("Grid") == 0) {
    return Grid();
  }
  else if(centerVal.compare("Face") == 0) {
    return Face();
  }
  else if(centerVal.compare("Edge") == 0) {
    return Edge();
  }

111 112 113 114 115 116 117 118
  try {
    XdmfError::message(XdmfError::FATAL, 
                       "Center not of 'Grid','Cell','Face','Edge','Node' "
                       "in XdmfAttributeCenter::New");
  }
  catch (XdmfError e) {
    throw e;
  }
119

120
  return shared_ptr<const XdmfAttributeCenter>();
121 122
}

123 124
void
XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
125
{
126
  collectedProperties.insert(std::make_pair("Center", mName));
127
}