XdmfInformation.cpp 5.13 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 : XdmfInformation.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 "XdmfArray.hpp"
26
#include "XdmfError.hpp"
27 28 29
#include "XdmfInformation.hpp"

XDMF_CHILDREN_IMPLEMENTATION(XdmfInformation, XdmfArray, Array, Name)
30

31
shared_ptr<XdmfInformation>
32
XdmfInformation::New()
33
{
34
  shared_ptr<XdmfInformation> p(new XdmfInformation());
35
  return p;
36
}
37

38
shared_ptr<XdmfInformation>
39 40
XdmfInformation::New(const std::string & key,
                     const std::string & value)
41
{
42
  shared_ptr<XdmfInformation> p(new XdmfInformation(key, value));
43
  return p;
44
}
45

46 47 48 49
XdmfInformation::XdmfInformation(const std::string & key,
                                 const std::string & value) :
  mKey(key),
  mValue(value)
50 51 52 53 54 55 56 57 58
{
}

XdmfInformation::~XdmfInformation()
{
}

const std::string XdmfInformation::ItemTag = "Information";

59 60
std::map<std::string, std::string>
XdmfInformation::getItemProperties() const
61
{
62
  std::map<std::string, std::string> informationProperties;
63 64
  informationProperties.insert(std::make_pair("Name", mKey));
  informationProperties.insert(std::make_pair("Value", mValue));
65
  return informationProperties;
66 67
}

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

74 75
std::string
XdmfInformation::getKey() const
76
{
77 78 79 80 81 82
  if (mKey.c_str() == NULL) {
    return "";
  }
  else {
    return mKey;
  }
83 84
}

85 86
std::string
XdmfInformation::getValue() const
87
{
88 89 90 91 92 93
  if (mValue.c_str() == NULL) {
    return "";
  }
  else {
    return mValue;
  }
94 95
}

96 97
void
XdmfInformation::populateItem(const std::map<std::string, std::string> & itemProperties,
98
                              const std::vector<shared_ptr<XdmfItem> > & childItems,
99
                              const XdmfCoreReader * const reader)
100
{
101 102 103 104 105 106 107 108
  XdmfItem::populateItem(itemProperties, childItems, reader);

  std::map<std::string, std::string>::const_iterator key =
    itemProperties.find("Name");
  if(key != itemProperties.end()) {
    mKey = key->second;
  }
  else {
109 110 111
    XdmfError::message(XdmfError::FATAL,
                       "'Name' not found in itemProperties in "
                       "XdmfInformation::populateItem");
112 113 114 115 116 117 118 119
  }

  std::map<std::string, std::string>::const_iterator value =
    itemProperties.find("Value");
  if(value != itemProperties.end()) {
    mValue = value->second;
  }
  else {
120 121 122 123 124
    value = itemProperties.find("Content");
    if(value != itemProperties.end()) {
      mValue = value->second;
    }
    else {
125 126 127
      XdmfError::message(XdmfError::FATAL,
                         "'Value' not found in itemProperties in "
                         "XdmfInformation::populateItem");
128
    }
129
  }
130 131 132 133 134 135 136 137
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
        childItems.begin();
      iter != childItems.end();
      ++iter) {
    if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
      this->insert(array);
    }
  }
138 139
}

140 141
void
XdmfInformation::setKey(const std::string & key)
142
{
143 144 145 146 147 148
  if (mKey.c_str() == NULL) {
    XdmfError::message(XdmfError::FATAL, "Error: Internal Key String is a null reference");
  }
  else {
    mKey = key;
  }
149 150
}

151 152
void
XdmfInformation::setValue(const std::string & value)
153
{
154 155 156 157 158 159
  if (mValue.c_str() == NULL) {
    XdmfError::message(XdmfError::FATAL, "Error: Internal Value String is a null reference");
  }
  else {
    mValue = value;
  }
160
}
161 162 163 164 165 166 167 168 169 170 171 172

void
XdmfInformation::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
{
  XdmfItem::traverse(visitor);
  for(std::vector<shared_ptr<XdmfArray> >::const_iterator iter = 
        mArrays.begin();
      iter != mArrays.end();
      ++iter) {
    (*iter)->accept(visitor);
  }
}