XdmfTime.cpp 3.19 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 : XdmfTime.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 <sstream>
25
#include <utility>
26
#include "XdmfTime.hpp"
27
#include "XdmfError.hpp"
28

29
shared_ptr<XdmfTime>
30
XdmfTime::New(const double & value)
31
{
32
  shared_ptr<XdmfTime> p(new XdmfTime(value));
33
  return p;
34 35
}

36
XdmfTime::XdmfTime(const double & value) :
37
  mValue(value)
38 39 40 41 42 43 44 45 46
{
}

XdmfTime::~XdmfTime()
{
}

const std::string XdmfTime::ItemTag = "Time";

47 48
std::map<std::string, std::string>
XdmfTime::getItemProperties() const
49
{
50 51 52
  std::map<std::string, std::string> timeProperties;
  std::stringstream value;
  value << mValue;
53
  timeProperties.insert(std::make_pair("Value", value.str()));
54
  return timeProperties;
55 56
}

57 58
std::string
XdmfTime::getItemTag() const
59
{
60
  return ItemTag;
61 62
}

63 64
double
XdmfTime::getValue() const
65
{
66
  return mValue;
67 68
}

69 70
void
XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties,
71
                       const std::vector<shared_ptr<XdmfItem> > & childItems,
72
                       const XdmfCoreReader * const reader)
73
{
74 75 76 77 78 79 80
  XdmfItem::populateItem(itemProperties, childItems, reader);
  std::map<std::string, std::string>::const_iterator value =
    itemProperties.find("Value");
  if(value != itemProperties.end()) {
    mValue = atof(value->second.c_str());
  }
  else {
81 82 83 84 85 86 87 88
    try {
      XdmfError::message(XdmfError::FATAL, 
                         "'Value' not in itemProperties in "
                         "XdmfTime::populateItem");
    }
    catch (XdmfError e) {
      throw e;
    }
89
  }
90 91
}

92 93
void
XdmfTime::setValue(const double & value)
94
{
95
  mValue = value;
96
}