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

30
shared_ptr<XdmfAttribute>
31
XdmfAttribute::New()
32
{
33
  shared_ptr<XdmfAttribute> p(new XdmfAttribute());
34
  return p;
35 36
}

37
XdmfAttribute::XdmfAttribute() :
38 39 40
  mCenter(XdmfAttributeCenter::Grid()),
  mName(""),
  mType(XdmfAttributeType::NoAttributeType())
41 42 43 44 45 46 47
{
}

XdmfAttribute::~XdmfAttribute()
{
}

48
const std::string XdmfAttribute::ItemTag = "Attribute";
49

50
shared_ptr<const XdmfAttributeCenter>
51
XdmfAttribute::getCenter() const
52
{
53
  return mCenter;
54 55
}

56 57
std::map<std::string, std::string>
XdmfAttribute::getItemProperties() const
58
{
59
  std::map<std::string, std::string> attributeProperties;
60
  attributeProperties.insert(std::make_pair("Name", mName));
61 62 63
  mType->getProperties(attributeProperties);
  mCenter->getProperties(attributeProperties);
  return attributeProperties;
64 65
}

66 67
std::string
XdmfAttribute::getItemTag() const
68
{
69
  return ItemTag;
70 71
}

72 73
std::string
XdmfAttribute::getName() const
74
{
75
  return mName;
76 77
}

78
shared_ptr<const XdmfAttributeType>
79
XdmfAttribute::getType() const
80
{
81
  return mType;
82 83
}

84 85
void
XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties,
86
                            const std::vector<shared_ptr<XdmfItem> > & childItems,
87
                            const XdmfCoreReader * const reader)
88
{
89 90 91 92 93 94 95 96
  XdmfItem::populateItem(itemProperties, childItems, reader);

  std::map<std::string, std::string>::const_iterator name =
    itemProperties.find("Name");
  if(name != itemProperties.end()) {
    mName = name->second;
  }
  else {
97 98 99
    XdmfError::message(XdmfError::FATAL,
                       "'Name' not found in itemProperties in "
                       "XdmfAttribute::populateItem");
100 101 102 103
  }

  mCenter = XdmfAttributeCenter::New(itemProperties);
  mType = XdmfAttributeType::New(itemProperties);
104
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter = 
105 106 107
        childItems.begin();
      iter != childItems.end();
      ++iter) {
108
    if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
109
      this->swap(array);
110
      break;
111 112
    }
  }
113 114
}

115
void
116
XdmfAttribute::setCenter(const shared_ptr<const XdmfAttributeCenter> center)
117
{
118
  mCenter = center;
119 120
}

121 122
void
XdmfAttribute::setName(const std::string & name)
123
{
124
  mName= name;
125 126
}

127
void
128
XdmfAttribute::setType(const shared_ptr<const XdmfAttributeType> type)
129
{
130
  mType = type;
131
}