XdmfVisitor.cpp 2.87 KB
Newer Older
1 2 3
// Kenneth Leiter
// Xdmf Smart Pointer Test

4
#include "XdmfAttribute.hpp"
5
#include "XdmfDataItem.hpp"
Kenneth Leiter's avatar
Kenneth Leiter committed
6
#include "XdmfDomain.hpp"
7 8 9
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
10 11
#include "XdmfVisitor.hpp"

12 13 14 15 16
#include <iomanip>

XdmfVisitor::XdmfVisitor() :
	mTabIndex(0),
	xmlData()
17
{
18
	std::cout << "Created Visitor " << this << std::endl;
19 20 21 22
}

XdmfVisitor::~XdmfVisitor()
{
23 24 25 26 27
	std::cout << "Deleted Visitor " << this << std::endl;
}

void XdmfVisitor::visit(const XdmfAttribute * const attribute)
{
28 29 30 31
	xmlData << std::setw(mTabIndex) << "" << "<Attribute Name=\"" << attribute->getName() << "\" AttributeType=\"" << attribute->getAttributeTypeAsString() << "\" Center=\"" << attribute->getAttributeCenterAsString() << "\">\n";
	mTabIndex++;
	visit((XdmfDataItem*)attribute);
	mTabIndex--;
32 33 34
	xmlData << std::setw(mTabIndex) << "" << "</Attribute>\n";
}

35 36
void XdmfVisitor::visit(const XdmfDataItem * const dataItem)
{
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
	xmlData << std::setw(mTabIndex) << "" << "<DataItem Format=\"XML\" DataType=\"Int\" Precision=\"4\" Dimensions=\"" << dataItem->getNumberValues() << "\">";
	const int* const intPointer = dataItem->getData<int>();
	mTabIndex++;
	for (unsigned int i=0; i<dataItem->getNumberValues(); ++i)
	{
		if (i % 10 == 0)
		{
			xmlData << "\n" << std::setw(mTabIndex) << "" << intPointer[i] << " ";
		}
		else
		{
			xmlData << intPointer[i] << " ";
		}
	}
	mTabIndex--;
	xmlData << "\n" << std::setw(mTabIndex) << "" << "</DataItem>\n";
53 54
}

Kenneth Leiter's avatar
Kenneth Leiter committed
55 56 57 58 59 60 61 62 63 64 65 66
void XdmfVisitor::visit(const XdmfDomain * const domain)
{
	xmlData << std::setw(mTabIndex) << "" << "<Domain>\n";
	mTabIndex++;
	for(unsigned int i=0; i<domain->getNumberOfGrids(); ++i)
	{
		visit(domain->getGrid(i).get());
	}
	mTabIndex--;
	xmlData << std::setw(mTabIndex) << "" << "</Domain>\n";
}

67 68 69
void XdmfVisitor::visit(const XdmfGeometry * const geometry)
{
	xmlData << std::setw(mTabIndex) << "" << "<Geometry GeometryType=\"" << geometry->getGeometryTypeAsString() << "\">\n";
70
	mTabIndex++;
71
	visit((XdmfDataItem*)geometry);
72
	mTabIndex--;
73 74 75 76 77 78 79 80 81
	xmlData << std::setw(mTabIndex) << "" << "</Geometry>\n";
}

void XdmfVisitor::visit(const XdmfGrid * const grid)
{
	xmlData << std::setw(mTabIndex) << "" << "<Grid Name=\"" << grid->getName() <<"\">\n";
	mTabIndex++;
	visit(grid->getGeometry().get());
	visit(grid->getTopology().get());
Kenneth Leiter's avatar
Kenneth Leiter committed
82
	for(unsigned int i=0; i<grid->getNumberOfAttributes(); i++)
83 84 85
	{
		visit(grid->getAttribute(i).get());
	}
86 87
	mTabIndex--;
	xmlData << std::setw(mTabIndex) << "" << "</Grid>\n";
88 89
}

90
void XdmfVisitor::visit(const XdmfTopology * const topology)
91
{
92 93
	xmlData << std::setw(mTabIndex) << "" << "<Topology TopologyType=\"" << topology->getTopologyTypeAsString() << "\" NumberOfElements=\"" << topology->getNumberElements() << "\">\n";
	mTabIndex++;
94
	visit((XdmfDataItem*)topology);
95
	mTabIndex--;
96
	xmlData << std::setw(mTabIndex) << "" << "</Topology>\n";
97 98
}

99
std::string XdmfVisitor::printSelf() const
100
{
101
	return "XdmfVisitor:\n" + xmlData.str();
102
}