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

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

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

XdmfAttribute::~XdmfAttribute()
{
}

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

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

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

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

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

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

83 84
void
XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties,
85
                            std::vector<shared_ptr<XdmfItem> > & childItems,
86
                            const XdmfCoreReader * const reader)
87
{
88 89 90 91 92 93 94 95
  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 {
96
    XdmfError::message(XdmfError::FATAL,"'Name' not found in itemProperties in XdmfAttribute::populateItem");
97 98 99 100
  }

  mCenter = XdmfAttributeCenter::New(itemProperties);
  mType = XdmfAttributeType::New(itemProperties);
101
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter = 
102 103 104
        childItems.begin();
      iter != childItems.end();
      ++iter) {
105
    if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
106 107 108 109
      this->swap(array);
    }
    // TODO: If multiple dataitems.
  }
110 111
}

112
void
113
XdmfAttribute::setCenter(const shared_ptr<const XdmfAttributeCenter> center)
114
{
115
  mCenter = center;
116 117
}

118 119
void
XdmfAttribute::setName(const std::string & name)
120
{
121
  mName= name;
122 123
}

124
void
125
XdmfAttribute::setType(const shared_ptr<const XdmfAttributeType> type)
126
{
127
  mType = type;
128
}