XdmfTime.cpp 3.02 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 25

#include <sstream>
#include "XdmfTime.hpp"
26
#include "XdmfError.hpp"
27

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

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

XdmfTime::~XdmfTime()
{
}

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

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

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

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

68 69
void
XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties,
70
                       std::vector<shared_ptr<XdmfItem> > & childItems,
71
                       const XdmfCoreReader * const reader)
72
{
73 74 75 76 77 78 79
  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 {
80
    XdmfError::message(XdmfError::FATAL, "'Value' not in itemProperties in XdmfTime::populateItem");
81
  }
82 83
}

84 85
void
XdmfTime::setValue(const double & value)
86
{
87
  mValue = value;
88
}