Panda3D
Loading...
Searching...
No Matches
config_dxml.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file config_dxml.cxx
10 * @author drose
11 * @date 2009-08-08
12 */
13
14#include "config_dxml.h"
15#include "dconfig.h"
16#include <stdio.h>
17
18BEGIN_PUBLISH
19#include "tinyxml.h"
20END_PUBLISH
21
22#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_PANDA_DXML)
23 #error Buildsystem error: BUILDING_PANDA_DXML not defined
24#endif
25
26Configure(config_dxml);
27NotifyCategoryDef(dxml, "");
28
29ConfigureFn(config_dxml) {
31}
32
33/**
34 * Initializes the library. This must be called at least once before any of
35 * the functions or classes in this library can be used. Normally it will be
36 * called by the static initializers and need not be called explicitly, but
37 * special cases exist.
38 */
39void
41 static bool initialized = false;
42 if (initialized) {
43 return;
44 }
45 initialized = true;
46}
47
48BEGIN_PUBLISH
49/**
50 * Reads an XML document from the indicated stream.
51 * @returns the document, or NULL on error.
52 */
54read_xml_stream(std::istream &in) {
56 in >> *doc;
57 if (in.fail() && !in.eof()) {
58 delete doc;
59 return nullptr;
60 }
61
62 return doc;
63}
64END_PUBLISH
65
66BEGIN_PUBLISH
67/**
68 * Writes an XML document to the indicated stream.
69 */
70void
71write_xml_stream(std::ostream &out, TiXmlDocument *doc) {
72 out << *doc;
73}
74END_PUBLISH
75
76BEGIN_PUBLISH
77/**
78 * Writes an XML object to stdout, with formatting.
79 */
80void
82 xnode->Print(stdout, 0);
83}
84END_PUBLISH
85
86BEGIN_PUBLISH
87/**
88 * Writes an XML object to the indicated file, with formatting. Unfortunately
89 * the VFS cannot be supported; the file must be a real filename on disk.
90 */
91void
92print_xml_to_file(const Filename &filename, TiXmlNode *xnode) {
93 std::string os_name = filename.to_os_specific();
94#ifdef _WIN32
95 FILE *file;
96 if (fopen_s(&file, os_name.c_str(), "w") != 0) {
97#else
98 FILE *file = fopen(os_name.c_str(), "w");
99 if (file == nullptr) {
100#endif
101 dxml_cat.error() << "Failed to open " << filename << " for writing\n";
102 }
103 xnode->Print(file, 0);
104 fclose(file);
105}
106END_PUBLISH
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
Always the top level node.
Definition tinyxml.h:1387
The parent class for everything in the Document Object Model.
Definition tinyxml.h:424
END_PUBLISH BEGIN_PUBLISH void write_xml_stream(std::ostream &out, TiXmlDocument *doc)
Writes an XML document to the indicated stream.
END_PUBLISH BEGIN_PUBLISH void print_xml_to_file(const Filename &filename, TiXmlNode *xnode)
Writes an XML object to the indicated file, with formatting.
END_PUBLISH BEGIN_PUBLISH void print_xml(TiXmlNode *xnode)
Writes an XML object to stdout, with formatting.
void init_libdxml()
Initializes the library.
BEGIN_PUBLISH TiXmlDocument * read_xml_stream(std::istream &in)
Reads an XML document from the indicated stream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.