Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XMLSerializer Class Reference

#include <xml_serializer.h>

Public Member Functions

 XMLSerializer (const char *filename, const char *modificationname, void *mythis)
 
void AddTag (const std::string &tag)
 
void AddElement (const std::string &element, XMLHandler *handler, const XMLType &input)
 
void Write (const char *modificationname="")
 
string WriteString ()
 
void EndTag (const std::string endname=string(""))
 
std::string getName ()
 
void setName (const std::string &fil)
 

Public Attributes

std::string randomdata [1]
 

Detailed Description

Definition at line 149 of file xml_serializer.h.

Constructor & Destructor Documentation

XMLSerializer::XMLSerializer ( const char *  filename,
const char *  modificationname,
void *  mythis 
)

Definition at line 193 of file xml_serializer.cpp.

References Network.

193  : savedir( modificationname )
194  , mythis( mythis )
195 {
196  curnode = &topnode;
197  //In network mode we don't care about saving filename, we want always to save with modification
198  //name since we only work with savegames
199  if (Network != NULL)
200  this->filename = string( modificationname );
201  else
202  this->filename = string( filename );
203 }

Member Function Documentation

void XMLSerializer::AddElement ( const std::string &  element,
XMLHandler handler,
const XMLType input 
)

Definition at line 210 of file xml_serializer.cpp.

References XMLnode::elements.

211 {
212  curnode->elements.push_back( XMLElement( element, input, handler ) );
213 }
void XMLSerializer::AddTag ( const std::string &  tag)

Definition at line 204 of file xml_serializer.cpp.

References XMLnode::subnodes.

205 {
206  curnode->subnodes.push_back( XMLnode( tag, curnode ) );
207  curnode = &curnode->subnodes.back();
208 }
void XMLSerializer::EndTag ( const std::string  endname = string( "" ))

Definition at line 215 of file xml_serializer.cpp.

References XMLnode::up, and XMLnode::val.

216 {
217  if (curnode)
218  if (endname == curnode->val)
219  curnode = curnode->up;
220 }
std::string XMLSerializer::getName ( )
inline

Definition at line 164 of file xml_serializer.h.

Referenced by Unit::subunitSerializer().

165  {
166  return filename;
167  }
void XMLSerializer::setName ( const std::string &  fil)
inline

Definition at line 168 of file xml_serializer.h.

Referenced by Unit::UpgradeSubUnitsWithFactory().

169  {
170  this->filename = fil;
171  }
void XMLSerializer::Write ( const char *  modificationname = "")

Definition at line 135 of file xml_serializer.cpp.

References VSFileSystem::VSFile::Close(), VSFileSystem::CreateDirectoryHome(), f, fprintf, VSFileSystem::VSFile::GetFullPath(), i, VSFileSystem::Ok, VSFileSystem::VSFile::OpenCreateWrite(), VSFileSystem::savedunitpath, and VSFileSystem::UnitFile.

Referenced by Unit::WriteUnit().

136 {
137  if (modificationname)
138  if (strlen( modificationname ) != 0)
139  savedir = modificationname;
141  VSFile f;
142  VSError err = f.OpenCreateWrite( savedir+"/"+this->filename, UnitFile );
143  if (err > Ok) {
144  fprintf( stderr, "!!! ERROR : Writing saved unit file : %s\n", f.GetFullPath().c_str() );
145  return;
146  }
147  for (unsigned int i = 0; i < topnode.subnodes.size(); i++)
148  topnode.subnodes[i].Write( f, mythis, 0 );
149  f.Close();
150 }
string XMLSerializer::WriteString ( )

Definition at line 159 of file xml_serializer.cpp.

References i.

Referenced by Unit::WriteUnitString().

160 {
161  string ret = "";
162  for (unsigned int i = 0; i < topnode.subnodes.size(); i++)
163  ret += topnode.subnodes[i].WriteString( mythis, 0 );
164  return ret;
165 }

Member Data Documentation

std::string XMLSerializer::randomdata[1]

Definition at line 157 of file xml_serializer.h.


The documentation for this class was generated from the following files: