[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src file_reader.hxx,NONE,1.1 file_writer.
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src file_reader.hxx,NONE,1.1 file_writer.hxx,NONE,1.1 xml_file_reader.cxx,NONE,1.1 xml_file_reader.hxx,NONE,1.1 xml_file_writer.cxx,NONE,1.1 xml_file_writer.hxx,NONE,1.1 Makefile.am,1.124,1.125 worldobj_data.cxx,1.1,NONE |
Date: |
20 Dec 2002 18:45:44 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv22357
Modified Files:
Makefile.am
Added Files:
file_reader.hxx file_writer.hxx xml_file_reader.cxx
xml_file_reader.hxx xml_file_writer.cxx xml_file_writer.hxx
Removed Files:
worldobj_data.cxx
Log Message:
added generic reader/write classes
--- NEW FILE: file_reader.hxx ---
// $Id: file_reader.hxx,v 1.1 2002/12/20 18:45:41 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PINGUS_FILE_READER_HXX
#define HEADER_PINGUS_FILE_READER_HXX
#include <string>
#include "vector.hxx"
/** Interface to read name/value pairs out of some kind of file or
structure */
class FileReader
{
public:
virtual bool read_int (const char* name, int*) =0;
virtual bool read_float (const char* name, float*) =0;
virtual bool read_bool (const char* name, bool*) =0;
virtual bool read_string(const char* name, std::string*) =0;
virtual bool read_vector(const char* name, Vector*) =0;
};
#endif
/* EOF */
--- NEW FILE: file_writer.hxx ---
// $Id: file_writer.hxx,v 1.1 2002/12/20 18:45:41 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PINGUS_FILE_WRITER_HXX
#define HEADER_PINGUS_FILE_WRITER_HXX
#include <string>
#include "vector.hxx"
/** Interface to write out name/value pairs out of some kind of file or
structure */
class FileWriter
{
private:
public:
virtual void begin_section (const char* name) =0;
virtual void end_section () =0;
virtual void write_int (const char* name, int) =0;
virtual void write_float (const char* name, float) =0;
virtual void write_bool (const char* name, bool) =0;
virtual void write_string (const char* name, const std::string&) =0;
virtual void write_vector (const char* name, const Vector&) =0;
};
#endif
/* EOF */
--- NEW FILE: xml_file_reader.cxx ---
// $Id: xml_file_reader.cxx,v 1.1 2002/12/20 18:45:41 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "xml_file_reader.hxx"
XMLFileReader::XMLFileReader(xmlDocPtr doc_, xmlNodePtr node)
: doc(doc_), section_node(node)
{
}
xmlNodePtr
XMLFileReader::find_node(const char* name)
{
xmlNodePtr node = section_node->children;
while (node)
{
if (xmlIsBlankNode(node))
{
node = node->next;
continue;
}
if (XMLhelper::equal_str(node->name, name))
{
return node;
}
}
return 0;
}
bool
XMLFileReader::read_int (const char* name, int* value)
{
xmlNodePtr node = find_node(name);
if (node)
{
*value = XMLhelper::parse_int(doc, node);
return true;
}
return false;
}
bool
XMLFileReader::read_float (const char* name, float* value)
{
xmlNodePtr node = find_node(name);
if (node)
{
*value = XMLhelper::parse_float(doc, node);
return true;
}
return false;
}
bool
XMLFileReader::read_bool (const char* name, bool* value)
{
xmlNodePtr node = find_node(name);
if (node)
{
*value = XMLhelper::parse_bool(doc, node);
return true;
}
return false;
}
bool
XMLFileReader::read_string(const char* name, std::string* value)
{
xmlNodePtr node = find_node(name);
if (node)
{
*value = XMLhelper::parse_string(doc, node);
return true;
}
return false;
}
bool
XMLFileReader::read_vector(const char* name, Vector* value)
{
xmlNodePtr node = find_node(name);
if (node)
{
*value = XMLhelper::parse_vector(doc, node);
return true;
}
return false;
}
/* EOF */
--- NEW FILE: xml_file_reader.hxx ---
// $Id: xml_file_reader.hxx,v 1.1 2002/12/20 18:45:41 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_XML_FILE_READER_HXX
#define HEADER_XML_FILE_READER_HXX
#include "xml_helper.hxx"
#include "file_reader.hxx"
/** */
class XMLFileReader : public FileReader
{
private:
/** Pointer to the XML document */
xmlDocPtr doc;
/** Pointer to the current section node, if one wants to access the
content of the section one has to use cur->children */
xmlNodePtr section_node;
xmlNodePtr find_node(const char* name);
public:
XMLFileReader(xmlDocPtr doc, xmlNodePtr node);
bool read_int (const char* name, int*);
bool read_float (const char* name, float*);
bool read_bool (const char* name, bool*);
bool read_string(const char* name, std::string*);
bool read_vector(const char* name, Vector*);
private:
XMLFileReader (const XMLFileReader&);
XMLFileReader& operator= (const XMLFileReader&);
};
#endif
/* EOF */
--- NEW FILE: xml_file_writer.cxx ---
// $Id: xml_file_writer.cxx,v 1.1 2002/12/20 18:45:41 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "xml_file_writer.hxx"
XMLFileWriter::XMLFileWriter(std::ostream& out_)
: out(&out_)
{
}
XMLFileWriter::~XMLFileWriter()
{
}
void
XMLFileWriter::begin_section (const char* name)
{
(*out) << "<" << name << ">\n";
section_stack.push(name);
}
void
XMLFileWriter::end_section ()
{
const std::string& section_name = section_stack.top();
(*out) << "</" << section_name << ">\n";
section_stack.pop();
}
void
XMLFileWriter::write_int (const char* name, int value)
{
(*out) << "<" << name << ">" << value << "</" << name << ">\n";
}
void
XMLFileWriter::write_float (const char* name, float value)
{
(*out) << "<" << name << ">" << value << "</" << name << ">\n";
}
void
XMLFileWriter::write_bool (const char* name, bool value)
{
(*out) << "<" << name << ">" << value << "</" << name << ">\n";
}
void
XMLFileWriter::write_string (const char* name, const std::string& value)
{
// FIXME: We don't handle escaping of characters here, might end
// FIXME: ugly if people enter '<>' in there strings.
(*out) << "<" << name << ">" << value << "</" << name << ">\n";
}
void
XMLFileWriter::write_vector (const char* name, const Vector& value)
{
(*out) << "<" << name << ">\n"
<< " <x-pos>" << value.x << "</x-pos>\n"
<< " <y-pos>" << value.y << "</y-pos>\n"
<< " <z-pos>" << value.z << "</z-pos>\n"
<< "</" << name << ">\n";
}
/* EOF */
--- NEW FILE: xml_file_writer.hxx ---
// $Id: xml_file_writer.hxx,v 1.1 2002/12/20 18:45:41 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_XML_FILE_WRITER_HXX
#define HEADER_XML_FILE_WRITER_HXX
#include <iostream>
#include <stack>
#include "file_writer.hxx"
/** */
class XMLFileWriter : public FileWriter
{
private:
/** A reference to the output stream */
std::ostream* out;
std::stack<std::string> section_stack;
public:
XMLFileWriter(std::ostream& out_);
virtual ~XMLFileWriter();
void begin_section (const char* name);
void end_section ();
void write_int (const char* name, int);
void write_float (const char* name, float);
void write_bool (const char* name, bool);
void write_string (const char* name, const std::string&);
void write_vector (const char* name, const Vector&);
private:
XMLFileWriter (const XMLFileWriter&);
XMLFileWriter& operator= (const XMLFileWriter&);
};
#endif
/* EOF */
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- Makefile.am 1 Dec 2002 17:45:21 -0000 1.124
+++ Makefile.am 20 Dec 2002 18:45:41 -0000 1.125
@@ -129,6 +129,8 @@
exit_menu.hxx \
fade_out.cxx \
fade_out.hxx \
+file_reader.hxx \
+file_writer.hxx \
fonts.hxx \
fonts.cxx \
fps_counter.cxx \
@@ -297,12 +299,15 @@
world_impl.hxx \
worldobj.cxx \
worldobj.hxx \
-worldobj_data.cxx \
worldobj_data.hxx \
worldobj_data_factory.cxx \
worldobj_data_factory.hxx \
xml_helper.cxx \
xml_helper.hxx \
+xml_file_reader.hxx \
+xml_file_reader.cxx \
+xml_file_writer.hxx \
+xml_file_writer.cxx \
xml_plf.cxx \
xml_plf.hxx \
xml_pdf.hxx \
--- worldobj_data.cxx DELETED ---
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src file_reader.hxx,NONE,1.1 file_writer.hxx,NONE,1.1 xml_file_reader.cxx,NONE,1.1 xml_file_reader.hxx,NONE,1.1 xml_file_writer.cxx,NONE,1.1 xml_file_writer.hxx,NONE,1.1 Makefile.am,1.124,1.125 worldobj_data.cxx,1.1,NONE,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/worldobjsdata groundpiece_data.cxx,1.7,1.8 groundpiece_data.hxx,1.3,1.4
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/input event_fwd.hxx,1.1,1.2
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/worldobjsdata groundpiece_data.cxx,1.7,1.8 groundpiece_data.hxx,1.3,1.4
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/input event_fwd.hxx,1.1,1.2
- Index(es):