Panda3D
|
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 00018 BEGIN_PUBLISH 00019 #include "tinyxml.h" 00020 END_PUBLISH 00021 00022 Configure(config_dxml); 00023 NotifyCategoryDef(dxml, ""); 00024 00025 ConfigureFn(config_dxml) { 00026 init_libdxml(); 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: init_libdxml 00031 // Description: Initializes the library. This must be called at 00032 // least once before any of the functions or classes in 00033 // this library can be used. Normally it will be 00034 // called by the static initializers and need not be 00035 // called explicitly, but special cases exist. 00036 //////////////////////////////////////////////////////////////////// 00037 void 00038 init_libdxml() { 00039 static bool initialized = false; 00040 if (initialized) { 00041 return; 00042 } 00043 initialized = true; 00044 } 00045 00046 BEGIN_PUBLISH 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: read_xml_stream 00049 // Description: Reads an XML document from the indicated stream. 00050 // Returns the document, or NULL on error. 00051 //////////////////////////////////////////////////////////////////// 00052 TiXmlDocument * 00053 read_xml_stream(istream &in) { 00054 TiXmlDocument *doc = new TiXmlDocument; 00055 in >> *doc; 00056 if (in.fail() && !in.eof()) { 00057 delete doc; 00058 return NULL; 00059 } 00060 00061 return doc; 00062 } 00063 END_PUBLISH 00064 00065 BEGIN_PUBLISH 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: write_xml_stream 00068 // Description: Writes an XML document to the indicated stream. 00069 //////////////////////////////////////////////////////////////////// 00070 void 00071 write_xml_stream(ostream &out, TiXmlDocument *doc) { 00072 out << *doc; 00073 } 00074 END_PUBLISH