Commit 03c6c401 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfInformation to store key/value pairs.

parent d07ee80d
......@@ -13,6 +13,7 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
#include <XdmfDataItem.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfInformation.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
......@@ -65,6 +66,10 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
{
$result = SWIG_NewPointerObj(SWIG_as_voidptr(new boost::shared_ptr<XdmfGridCollection>(gridCollection)), SWIGTYPE_p_boost__shared_ptrT_XdmfGridCollection_t, SWIG_POINTER_OWN);
}
else if(boost::shared_ptr<XdmfInformation> information = boost::shared_dynamic_cast<XdmfInformation>($1))
{
$result = SWIG_NewPointerObj(SWIG_as_voidptr(new boost::shared_ptr<XdmfInformation>(information)), SWIGTYPE_p_boost__shared_ptrT_XdmfInformation_t, SWIG_POINTER_OWN);
}
else if(boost::shared_ptr<XdmfSet> set = boost::shared_dynamic_cast<XdmfSet>($1))
{
$result = SWIG_NewPointerObj(SWIG_as_voidptr(new boost::shared_ptr<XdmfSet>(set)), SWIGTYPE_p_boost__shared_ptrT_XdmfSet_t, SWIG_POINTER_OWN);
......
......@@ -4,6 +4,7 @@
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfGridCollection.hpp"
#include "XdmfInformation.hpp"
#include "XdmfItemFactory.hpp"
#include "XdmfSet.hpp"
#include "XdmfTopology.hpp"
......@@ -47,6 +48,10 @@ boost::shared_ptr<XdmfItem> XdmfItemFactory::createItem(const std::string & item
newItem = XdmfGrid::New();
}
}
else if(itemTag.compare(XdmfInformation::ItemTag) == 0)
{
newItem = XdmfInformation::New();
}
else if(itemTag.compare(XdmfSet::ItemTag) == 0)
{
newItem = XdmfSet::New();
......
......@@ -28,6 +28,7 @@ set(XdmfCoreSources
XdmfDataItem
XdmfHDF5Controller
XdmfHDF5Writer
XdmfInformation
XdmfItem
XdmfItemProperty
XdmfObject
......
......@@ -12,6 +12,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
#include <XdmfDataItem.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfInformation.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
......@@ -33,6 +34,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%shared_ptr(XdmfDataItem)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
%shared_ptr(XdmfInformation)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfObject)
......@@ -53,6 +55,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
%include XdmfInformation.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp
......
/*
* XdmfInformation.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
*/
#include "XdmfInformation.hpp"
XdmfInformation::XdmfInformation() :
mKey(""),
mValue("")
{
std::cout << "Created Information " << this << std::endl;
}
XdmfInformation::~XdmfInformation()
{
std::cout << "Deleted Information " << this << std::endl;
}
const std::string XdmfInformation::ItemTag = "Information";
std::map<std::string, std::string> XdmfInformation::getItemProperties() const
{
std::map<std::string, std::string> informationProperties;
informationProperties["Name"] = mKey;
informationProperties["Value"] = mValue;
return informationProperties;
}
std::string XdmfInformation::getItemTag() const
{
return ItemTag;
}
std::string XdmfInformation::getKey() const
{
return mKey;
}
std::string XdmfInformation::getValue() const
{
return mValue;
}
void XdmfInformation::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{
std::map<std::string, std::string>::const_iterator key = itemProperties.find("Name");
if(key != itemProperties.end())
{
mKey = key->second;
}
else
{
assert(false);
}
std::map<std::string, std::string>::const_iterator value = itemProperties.find("Value");
if(value != itemProperties.end())
{
mValue = value->second;
}
else
{
assert(false);
}
}
void XdmfInformation::setKey(const std::string & key)
{
mKey= key;
}
void XdmfInformation::setValue(const std::string & value)
{
mValue= value;
}
#ifndef XDMFINFORMATION_HPP_
#define XDMFINFORMATION_HPP_
// Includes
#include "XdmfItem.hpp"
/**
* @brief Holds a key/value pair that can be attached to an Xdmf structure.
*
* This can useful for storing input parameters to a code or for general information like runtime.
*/
class XdmfInformation : public XdmfItem {
public:
XdmfNewMacro(XdmfInformation);
virtual ~XdmfInformation();
LOKI_DEFINE_VISITABLE(XdmfInformation, XdmfItem)
static const std::string ItemTag;
std::map<std::string, std::string> getItemProperties() const;
std::string getItemTag() const;
/**
* Get the key for this information item.
*
* @return std::string containing the key.
*/
std::string getKey() const;
/**
* Get the value for this information item.
*
* @return std::string containing the value.
*/
std::string getValue() const;
/**
* Set the key for this information item.
*
* @param key a string containing the key to set.
*/
void setKey(const std::string & key);
/**
* Set the value for this information item.
*
* @param value a string containing the value to set.
*/
void setValue(const std::string & value);
protected:
XdmfInformation();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
XdmfInformation(const XdmfInformation & information); // Not implemented.
void operator=(const XdmfInformation & information); // Not implemented.
std::string mKey;
std::string mValue;
};
#endif /* XDMFINFORMATION_HPP_ */
......@@ -2,6 +2,7 @@ set(XdmfCoreCxxTests
TestXdmfArray
TestXdmfArrayWriteRead
TestXdmfHDF5Writer
TestXdmfInformation
)
foreach(test ${XdmfCoreCxxTests})
......
#include "XdmfInformation.hpp"
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfInformation> information = XdmfInformation::New();
assert(information->getKey().compare("") == 0);
assert(information->getValue().compare("") == 0);
information->setKey("Key");
information->setValue("Value");
assert(information->getKey().compare("Key") == 0);
assert(information->getValue().compare("Value") == 0);
return 0;
}
......@@ -13,6 +13,7 @@ swig -v -c++ -python -o XdmfUtilsPython.cpp XdmfUtils.i
#include <XdmfDataItem.hpp>
#include <XdmfHDF5Controller.hpp>
#include <XdmfHDF5Writer.hpp>
#include <XdmfInformation.hpp>
#include <XdmfItem.hpp>
#include <XdmfItemProperty.hpp>
#include <XdmfObject.hpp>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment