-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXMLWriter.cpp
70 lines (60 loc) · 1.81 KB
/
XMLWriter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* CUDARadiosity 0.87a
* Copyright 2012 by David Sargeant, Patrick Gradie, Michael Rogers
*
* Based on code from rrv (Radiosity Renderer and Visualizer) by TODO
* Distributed under GPL (see <http://www.gnu.org/licenses/>)
*
*/
#include "XMLWriter.h"
#include "XMLNames.h"
#include <iostream>
#include <cstring>
using namespace XML;
/**
* @param const char*
* @return char*
* @brief Copy string. Using malloc.
*/
XMLSTR XMLWriter::copyString( XMLCSTR from )
{
XMLSTR copy = 0;
if ( 0 != from )
{
if ( 0 != (copy = (XMLSTR)malloc( sizeof(XMLCHAR) * (strlen(from) + 1) )))
{
strcpy(copy, from);
}
}
return copy;
}
/**
* @brief Construct creates XML nodes in our DTD.
*/
XMLWriter::XMLWriter()
{
this->objectName = "scene";
this->root_ = XMLNode::createXMLTopNode_WOSD( XMLWriter::copyString( XMLNames::TAGS[Root] ) );
this->definition_ = this->root_.addChild_WOSD( XMLWriter::copyString( XMLNames::TAGS[Definition] ) );
this->instantiate_ = this->root_.addChild_WOSD(XMLWriter::copyString( XMLNames::TAGS[Instantiate] ) );
this->objectdef_ = this->definition_.addChild_WOSD( XMLWriter::copyString( XMLNames::TAGS[ObjectDefinition] ) );
this->objectdef_.addAttribute_WOSD( XMLWriter::copyString( XMLNames::ATTRIBUTES[Name] ) , XMLWriter::copyString( objectName ) );
this->object_ = this->instantiate_.addChild_WOSD(XMLWriter::copyString( XMLNames::TAGS[Object] ) );
this->object_.addAttribute_WOSD( XMLWriter::copyString( XMLNames::ATTRIBUTES[Name] ) , XMLWriter::copyString( objectName ) );
}
/**
* @param XMLNode
* @brief Add entity to objectdef
*/
void XMLWriter::addEntity( XMLNode addedNode )
{
this->objectdef_.addChild( addedNode );
}
/**
* @param const char*
* @brief Write data to file
*/
void XMLWriter::writeToFile( const char* fileName )
{
this->root_.writeToFile( fileName );
}