XdmfAttribute.cpp 2.33 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * XdmfAttribute.cpp
 *
 *  Created on: Jan 29, 2010
 *      Author: kleiter
 */

#include "XdmfAttribute.hpp"
9 10
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
11

12 13
boost::shared_ptr<XdmfAttribute>
XdmfAttribute::New()
14
{
15 16
  boost::shared_ptr<XdmfAttribute> p(new XdmfAttribute());
  return p;
17 18
}

19
XdmfAttribute::XdmfAttribute() :
20 21 22
  mCenter(XdmfAttributeCenter::Grid()),
  mName(""),
  mType(XdmfAttributeType::NoAttributeType())
23 24 25 26 27 28 29
{
}

XdmfAttribute::~XdmfAttribute()
{
}

30
const std::string XdmfAttribute::ItemTag = "Attribute";
31

32 33
boost::shared_ptr<const XdmfAttributeCenter>
XdmfAttribute::getCenter() const
34
{
35
  return mCenter;
36 37
}

38 39
std::map<std::string, std::string>
XdmfAttribute::getItemProperties() const
40
{
41 42 43 44 45
  std::map<std::string, std::string> attributeProperties;
  attributeProperties["Name"] = mName;
  mType->getProperties(attributeProperties);
  mCenter->getProperties(attributeProperties);
  return attributeProperties;
46 47
}

48 49
std::string
XdmfAttribute::getItemTag() const
50
{
51
  return ItemTag;
52 53
}

54 55
std::string
XdmfAttribute::getName() const
56
{
57
  return mName;
58 59
}

60 61
boost::shared_ptr<const XdmfAttributeType>
XdmfAttribute::getType() const
62
{
63
  return mType;
64 65
}

66 67 68 69
void
XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties,
                            std::vector<boost::shared_ptr<XdmfItem> > & childItems,
                            const XdmfCoreReader * const reader)
70
{
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  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 {
    assert(false);
  }

  mCenter = XdmfAttributeCenter::New(itemProperties);
  mType = XdmfAttributeType::New(itemProperties);
  for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter =
        childItems.begin();
      iter != childItems.end();
      ++iter) {
    if(boost::shared_ptr<XdmfArray> array =
       boost::shared_dynamic_cast<XdmfArray>(*iter)) {
      this->swap(array);
    }
    // TODO: If multiple dataitems.
  }
94 95
}

96 97
void
XdmfAttribute::setCenter(const boost::shared_ptr<const XdmfAttributeCenter> center)
98
{
99
  mCenter = center;
100 101
}

102 103
void
XdmfAttribute::setName(const std::string & name)
104
{
105
  mName= name;
106 107
}

108 109
void
XdmfAttribute::setType(const boost::shared_ptr<const XdmfAttributeType> type)
110
{
111
  mType = type;
112
}