XdmfGrid.cpp 5.33 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 "XdmfAttribute.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
25
#include "XdmfGeometry.hpp"
26
#include "XdmfGrid.hpp"
27
#include "XdmfMap.hpp"
28
#include "XdmfSet.hpp"
29
#include "XdmfTime.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
30 31
#include "XdmfTopology.hpp"

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

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

XdmfGrid::~XdmfGrid()
{
}

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

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

58 59
std::map<std::string, std::string>
XdmfGrid::getItemProperties() const
60
{
61 62 63
  std::map<std::string, std::string> gridProperties;
  gridProperties["Name"] = mName;
  return gridProperties;
64 65
}

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

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

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

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

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

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

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

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

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