XdmfGrid.cpp 5.38 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 : XdmfGrid.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.                                                 */
/*                                                                           */
/*****************************************************************************/
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
23

24
#include <utility>
25
#include "XdmfAttribute.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
26
#include "XdmfGeometry.hpp"
27
#include "XdmfGrid.hpp"
28
#include "XdmfMap.hpp"
29
#include "XdmfSet.hpp"
30
#include "XdmfTime.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
31 32
#include "XdmfTopology.hpp"

33
XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfAttribute, Attribute, Name)
34
XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfMap, Map, Name)
35 36
XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfSet, Set, Name)

37 38
XdmfGrid::XdmfGrid(const shared_ptr<XdmfGeometry> geometry,
                   const shared_ptr<XdmfTopology> topology,
39 40 41 42
                   const std::string & name) :
  mGeometry(geometry),
  mTopology(topology),
  mName(name),
43
  mTime(shared_ptr<XdmfTime>())
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
44 45 46 47 48 49 50
{
}

XdmfGrid::~XdmfGrid()
{
}

51
const std::string XdmfGrid::ItemTag = "Grid";
52

53
shared_ptr<const XdmfGeometry>
54
XdmfGrid::getGeometry() const
55
{
56
  return mGeometry;
57 58
}

59 60
std::map<std::string, std::string>
XdmfGrid::getItemProperties() const
61
{
62
  std::map<std::string, std::string> gridProperties;
63
  gridProperties.insert(std::make_pair("Name", mName));
64
  return gridProperties;
65 66
}

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

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

79
shared_ptr<XdmfTime>
80
XdmfGrid::getTime()
81
{
82 83
  return boost::const_pointer_cast<XdmfTime>
    (static_cast<const XdmfGrid &>(*this).getTime());
84 85
}

86
shared_ptr<const XdmfTime>
87
XdmfGrid::getTime() const
88
{
89
  return mTime;
90 91
}

92
shared_ptr<const XdmfTopology>
93
XdmfGrid::getTopology() const
94
{
95
  return mTopology;
96 97
}

98 99
void
XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
100
                       const std::vector<shared_ptr<XdmfItem> > & childItems,
101
                       const XdmfCoreReader * const reader)
102
{
103 104 105 106 107 108 109 110 111
  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 {
    mName = "";
  }
112
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
113 114 115
        childItems.begin();
      iter != childItems.end();
      ++iter) {
116 117
    if(shared_ptr<XdmfAttribute> attribute =
       shared_dynamic_cast<XdmfAttribute>(*iter)) {
118 119
      this->insert(attribute);
    }
120 121
    else if(shared_ptr<XdmfGeometry> geometry =
            shared_dynamic_cast<XdmfGeometry>(*iter)) {
122 123
      mGeometry = geometry;
    }
124 125
    else if(shared_ptr<XdmfMap> map =
            shared_dynamic_cast<XdmfMap>(*iter)) {
126
      this->insert(map);
127
    }
128 129
    else if(shared_ptr<XdmfSet> set =
            shared_dynamic_cast<XdmfSet>(*iter)) {
130 131
      this->insert(set);
    }
132 133
    else if(shared_ptr<XdmfTime> time =
            shared_dynamic_cast<XdmfTime>(*iter)) {
134 135
      mTime = time;
    }
136 137
    else if(shared_ptr<XdmfTopology> topology =
            shared_dynamic_cast<XdmfTopology>(*iter)) {
138 139 140
      mTopology = topology;
    }
  }
141 142
}

143 144
void
XdmfGrid::setName(const std::string & name)
145
{
146
  mName = name;
147 148
}

149
void
150
XdmfGrid::setTime(const shared_ptr<XdmfTime> time)
151
{
152
  mTime = time;
153
}
154 155

void
156
XdmfGrid::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
157 158 159 160 161 162 163 164 165 166 167
{
  XdmfItem::traverse(visitor);
  if(mTime) {
    mTime->accept(visitor);
  }
  if(mGeometry) {
    mGeometry->accept(visitor);
  }
  if(mTopology) {
    mTopology->accept(visitor);
  }
168
  for(std::vector<shared_ptr<XdmfAttribute> >::const_iterator iter = 
169 170 171 172 173
        mAttributes.begin();
      iter != mAttributes.end();
      ++iter) {
    (*iter)->accept(visitor);
  }
174 175 176 177 178 179
  for(std::vector<shared_ptr<XdmfMap> >::const_iterator iter = 
        mMaps.begin();
      iter != mMaps.end();
      ++iter) {
    (*iter)->accept(visitor);
  }
180
  for(std::vector<shared_ptr<XdmfSet> >::const_iterator iter = mSets.begin();
181 182 183 184
      iter != mSets.end();
      ++iter) {
    (*iter)->accept(visitor);
  }
185
}