XdmfTime.cpp 3.74 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(XdmfTime & refTime) :
  XdmfItem(refTime),
  mValue(refTime.getValue())
{
}

47 48 49 50 51 52
XdmfTime::~XdmfTime()
{
}

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

53 54
std::map<std::string, std::string>
XdmfTime::getItemProperties() const
55
{
56 57 58
  std::map<std::string, std::string> timeProperties;
  std::stringstream value;
  value << mValue;
59
  timeProperties.insert(std::make_pair("Value", value.str()));
60
  return timeProperties;
61 62
}

63 64
std::string
XdmfTime::getItemTag() const
65
{
66
  return ItemTag;
67 68
}

69 70
double
XdmfTime::getValue() const
71
{
72
  return mValue;
73 74
}

75 76
void
XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties,
77
                       const std::vector<shared_ptr<XdmfItem> > & childItems,
78
                       const XdmfCoreReader * const reader)
79
{
80 81 82 83 84 85 86
  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 {
87 88 89
    XdmfError::message(XdmfError::FATAL, 
                       "'Value' not in itemProperties in "
                       "XdmfTime::populateItem");
90
  }
91 92
}

93 94
void
XdmfTime::setValue(const double & value)
95
{
96
  mValue = value;
97 98 99 100 101 102 103
  this->setIsChanged(true);
}

// C Wrappers

XDMFTIME * XdmfTimeNew(double value)
{
104 105 106 107 108 109 110 111
  try
  {
    return (XDMFTIME *)((void *)(new XdmfTime(*(XdmfTime::New(value).get()))));
  }
  catch (...)
  {
    return (XDMFTIME *)((void *)(new XdmfTime(*(XdmfTime::New(value).get()))));
  }
112 113 114 115
}

double XdmfTimeGetValue(XDMFTIME * timePointer)
{
116
  return ((XdmfTime *)timePointer)->getValue();
117
}
118 119 120

void XdmfTimeSetValue(XDMFTIME * timePointer, double time)
{
121
  ((XdmfTime *)timePointer)->setValue(time);
122 123 124
}

XDMF_ITEM_C_CHILD_WRAPPER(XdmfTime, XDMFTIME)