XdmfAttributeCenter.cpp 4.85 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 29
std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()> XdmfAttributeCenter::mAttributeCenterDefinitions;

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

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

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

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

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

71 72 73 74 75 76 77 78 79 80
void
XdmfAttributeCenter::InitTypes()
{
  mAttributeCenterDefinitions["GRID"] = Grid;
  mAttributeCenterDefinitions["CELL"] = Cell;
  mAttributeCenterDefinitions["FACE"] = Face;
  mAttributeCenterDefinitions["EDGE"] = Edge;
  mAttributeCenterDefinitions["NODE"] = Node;
}

81
XdmfAttributeCenter::XdmfAttributeCenter(const std::string & name) :
82
  mName(name)
83 84
{
}
85

86
XdmfAttributeCenter::~XdmfAttributeCenter()
87 88 89
{
}

90
shared_ptr<const XdmfAttributeCenter>
91
XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperties)
92
{
93
  InitTypes();
94 95
  std::map<std::string, std::string>::const_iterator center =
    itemProperties.find("Center");
96
  if(center == itemProperties.end()) {
97 98 99
    XdmfError::message(XdmfError::FATAL, 
                       "'Center' not found in itemProperties in "
                       "XdmfAttributeCenter::New");
100
  }
101 102 103 104 105 106 107 108 109

  const std::string & centerVal = ConvertToUpper(center->second);

  std::map<std::string, shared_ptr<const XdmfAttributeCenter>(*)()>::const_iterator returnType = mAttributeCenterDefinitions.find(centerVal);

  if (returnType == mAttributeCenterDefinitions.end()) {
    XdmfError::message(XdmfError::FATAL,
                       "Center not of 'Grid','Cell','Face','Edge','Node' "
                       "in XdmfAttributeCenter::New");
110
  }
111 112
  else {
    return (*(returnType->second))();
113 114
  }

115 116 117
  XdmfError::message(XdmfError::FATAL, 
                     "Center not of 'Grid','Cell','Face','Edge','Node' "
                     "in XdmfAttributeCenter::New");
118

119
  // unreachable
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
}
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

// C Wrappers

int XdmfAttributeCenterGrid()
{
  return XDMF_ATTRIBUTE_CENTER_GRID;
}

int XdmfAttributeCenterCell()
{
  return XDMF_ATTRIBUTE_CENTER_CELL;
}

int XdmfAttributeCenterFace()
{
  return XDMF_ATTRIBUTE_CENTER_FACE;
}

int XdmfAttributeCenterEdge()
{
  return XDMF_ATTRIBUTE_CENTER_EDGE;
}

int XdmfAttributeCenterNode()
{
  return XDMF_ATTRIBUTE_CENTER_NODE;
}