Panda3D
 All Classes Functions Variables Enumerations
config_dxml.cxx
00001 // Filename: config_dxml.cxx
00002 // Created by: drose (08Aug09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "config_dxml.h"
00016 #include "dconfig.h"
00017 #include <stdio.h>
00018 
00019 BEGIN_PUBLISH
00020 #include "tinyxml.h"
00021 END_PUBLISH
00022 
00023 Configure(config_dxml);
00024 NotifyCategoryDef(dxml, "");
00025 
00026 ConfigureFn(config_dxml) {
00027   init_libdxml();
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: init_libdxml
00032 //  Description: Initializes the library.  This must be called at
00033 //               least once before any of the functions or classes in
00034 //               this library can be used.  Normally it will be
00035 //               called by the static initializers and need not be
00036 //               called explicitly, but special cases exist.
00037 ////////////////////////////////////////////////////////////////////
00038 void
00039 init_libdxml() {
00040   static bool initialized = false;
00041   if (initialized) {
00042     return;
00043   }
00044   initialized = true;
00045 }
00046 
00047 BEGIN_PUBLISH
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: read_xml_stream
00050 //  Description: Reads an XML document from the indicated stream.
00051 //               Returns the document, or NULL on error.
00052 ////////////////////////////////////////////////////////////////////
00053 TiXmlDocument *
00054 read_xml_stream(istream &in) {
00055   TiXmlDocument *doc = new TiXmlDocument;
00056   in >> *doc;
00057   if (in.fail() && !in.eof()) {
00058     delete doc;
00059     return NULL;
00060   }
00061 
00062   return doc;
00063 }
00064 END_PUBLISH
00065 
00066 BEGIN_PUBLISH
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: write_xml_stream
00069 //  Description: Writes an XML document to the indicated stream.
00070 ////////////////////////////////////////////////////////////////////
00071 void
00072 write_xml_stream(ostream &out, TiXmlDocument *doc) {
00073   out << *doc;
00074 }
00075 END_PUBLISH
00076 
00077 BEGIN_PUBLISH
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: print_xml
00080 //  Description: Writes an XML object to stdout, with formatting.
00081 ////////////////////////////////////////////////////////////////////
00082 void
00083 print_xml(TiXmlNode *xnode) {
00084   xnode->Print(stdout, 0);
00085 }
00086 END_PUBLISH
00087 
00088 BEGIN_PUBLISH
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: print_xml_to_file
00091 //  Description: Writes an XML object to the indicated file, with
00092 //               formatting.  Unfortunately the VFS cannot be
00093 //               supported; the file must be a real filename on disk.
00094 ////////////////////////////////////////////////////////////////////
00095 void
00096 print_xml_to_file(const Filename &filename, TiXmlNode *xnode) {
00097   string os_name = filename.to_os_specific();
00098   FILE *file = fopen(os_name.c_str(), "w");
00099   xnode->Print(file, 0);
00100   fclose(file);
00101 }
00102 END_PUBLISH
 All Classes Functions Variables Enumerations