XdmfSet.cpp 4.11 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 : XdmfSet.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
#include "XdmfHDF5Controller.hpp"
27
#include "XdmfSet.hpp"
28
#include "XdmfSetType.hpp"
29
#include "XdmfError.hpp"
30

31 32
XDMF_CHILDREN_IMPLEMENTATION(XdmfSet, XdmfAttribute, Attribute, Name)

33
  shared_ptr<XdmfSet>
34
XdmfSet::New()
35
{
36
  shared_ptr<XdmfSet> p(new XdmfSet());
37
  return p;
38 39
}

40
XdmfSet::XdmfSet() :
41 42
  mName(""),
  mType(XdmfSetType::NoSetType())
43 44 45 46 47 48 49
{
}

XdmfSet::~XdmfSet()
{
}

50
const std::string XdmfSet::ItemTag = "Set";
51

52 53
std::map<std::string, std::string>
XdmfSet::getItemProperties() const
54
{
55
  std::map<std::string, std::string> setProperties;
56
  setProperties.insert(std::make_pair("Name", mName));
57 58
  mType->getProperties(setProperties);
  return setProperties;
59 60
}

61 62
std::string
XdmfSet::getItemTag() const
63
{
64
  return ItemTag;
65 66
}

67 68
std::string
XdmfSet::getName() const
69
{
70
  return mName;
71 72
}

73
shared_ptr<const XdmfSetType>
74
XdmfSet::getType() const
75
{
76
  return mType;
77 78
}

79 80
void
XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties,
81
                      const std::vector<shared_ptr<XdmfItem> > & childItems,
82
                      const XdmfCoreReader * const reader)
83
{
84 85 86 87 88 89 90
  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  {
91 92 93
    XdmfError::message(XdmfError::FATAL, 
                       "'Name' not found in itemProperties in "
                       "XdmfSet::populateItem");
94 95
  }
  mType = XdmfSetType::New(itemProperties);
96
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
97 98 99
        childItems.begin();
      iter != childItems.end();
      ++iter) {
100 101
    if(shared_ptr<XdmfAttribute> attribute =
       shared_dynamic_cast<XdmfAttribute>(*iter)) {
102 103
      this->insert(attribute);
    }
104 105
    else if(shared_ptr<XdmfArray> array = 
            shared_dynamic_cast<XdmfArray>(*iter)) {
106 107 108 109
      this->swap(array);
      // TODO: If multiple dataitems.
    }
  }
110 111
}

112 113
void
XdmfSet::setName(const std::string & name)
114
{
115
  mName = name;
116 117
}

118
void
119
XdmfSet::setType(const shared_ptr<const XdmfSetType> type)
120
{
121
  mType = type;
122
}
123

124
void
125
XdmfSet::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
126
{
127
  XdmfItem::traverse(visitor);
128
  for(std::vector<shared_ptr<XdmfAttribute> >::const_iterator iter =
129 130 131
        mAttributes.begin();
      iter != mAttributes.end();
      ++iter) {
132 133
    (*iter)->accept(visitor);
  }
134
}