HPL1: replace files with generic streams in tinyxml

This commit is contained in:
grisenti 2022-08-18 15:53:04 +02:00 committed by Eugene Sandulenko
parent 2bf971bef9
commit a41b8d026c
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 28 additions and 28 deletions

View File

@ -580,7 +580,7 @@ void TiXmlElement::SetAttribute(const std::string &name, const std::string &_val
} }
#endif #endif
void TiXmlElement::Print(Common::DumpFile &file, int depth) const { void TiXmlElement::Print(Common::WriteStream &file, int depth) const {
int i; int i;
for (i = 0; i < depth; i++) { for (i = 0; i < depth; i++) {
file.writeString(" "); file.writeString(" ");
@ -731,22 +731,22 @@ bool TiXmlDocument::LoadFile(const char *filename, TiXmlEncoding encoding) {
value = filename; value = filename;
// reading in binary mode so that tinyxml can normalize the EOL // reading in binary mode so that tinyxml can normalize the EOL
Common::File file; Common::File file;
file.open(value); file.open(value);
if (file.isOpen()) { if (file.isOpen()) {
bool result = LoadFile(file, encoding); bool result = LoadFile(file, encoding);
return result; return result;
} else { } else {
debugC(Hpl1::kDebugFilePath, "file %s not found", value.c_str()); debugC(Hpl1::kDebugFilePath, "file %s not found", value.c_str());
SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN); SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN);
return false; return false;
} }
} }
bool TiXmlDocument::LoadFile(Common::File &file, TiXmlEncoding encoding) { bool TiXmlDocument::LoadFile(Common::SeekableReadStream &file, TiXmlEncoding encoding) {
if (file.err()) { if (file.err()) {
debugC(Hpl1::kDebugResourceLoading, "file %s could not be read", file.getName()); Hpl1::logError(Hpl1::kDebugResourceLoading, "xml file could not be read%c", '\n');
SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN); SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN);
return false; return false;
} }
@ -792,9 +792,9 @@ bool TiXmlDocument::LoadFile(Common::File &file, TiXmlEncoding encoding) {
char *buf = new char[length + 1]; char *buf = new char[length + 1];
buf[0] = 0; buf[0] = 0;
file.read(buf, length); file.read(buf, length);
if (file.err()) { if (file.err()) {
debugC(Hpl1::kDebugResourceLoading, "file read for %s failed", file.getName()); Hpl1::logError(Hpl1::kDebugResourceLoading, "xml file read for failed%c", '\n');
delete[] buf; delete[] buf;
SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN); SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN);
return false; return false;
@ -863,7 +863,7 @@ bool TiXmlDocument::SaveFile(const char *filename) const {
return false; return false;
} }
bool TiXmlDocument::SaveFile(Common::DumpFile &fp) const { bool TiXmlDocument::SaveFile(Common::WriteStream &fp) const {
if (useMicrosoftBOM) { if (useMicrosoftBOM) {
const unsigned char TIXML_UTF_LEAD_0 = 0xefU; const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
@ -897,7 +897,7 @@ TiXmlNode *TiXmlDocument::Clone() const {
return clone; return clone;
} }
void TiXmlDocument::Print(Common::DumpFile &cfile, int depth) const { void TiXmlDocument::Print(Common::WriteStream &cfile, int depth) const {
for (const TiXmlNode *node = FirstChild(); node; node = node->NextSibling()) { for (const TiXmlNode *node = FirstChild(); node; node = node->NextSibling()) {
node->Print(cfile, depth); node->Print(cfile, depth);
cfile.writeString("\n"); cfile.writeString("\n");
@ -952,7 +952,7 @@ TiXmlAttribute* TiXmlAttribute::Previous()
} }
*/ */
void TiXmlAttribute::Print(Common::DumpFile *cfile, int /*depth*/, TIXML_STRING *str) const { void TiXmlAttribute::Print(Common::WriteStream *cfile, int /*depth*/, TIXML_STRING *str) const {
TIXML_STRING n, v; TIXML_STRING n, v;
PutString(name, &n); PutString(name, &n);
@ -1020,7 +1020,7 @@ void TiXmlComment::operator=(const TiXmlComment &base) {
base.CopyTo(this); base.CopyTo(this);
} }
void TiXmlComment::Print(Common::DumpFile &cfile, int depth) const { void TiXmlComment::Print(Common::WriteStream &cfile, int depth) const {
for (int i = 0; i < depth; i++) { for (int i = 0; i < depth; i++) {
cfile.writeString(" "); cfile.writeString(" ");
} }
@ -1045,7 +1045,7 @@ TiXmlNode *TiXmlComment::Clone() const {
return clone; return clone;
} }
void TiXmlText::Print(Common::DumpFile &cfile, int depth) const { void TiXmlText::Print(Common::WriteStream &cfile, int depth) const {
if (cdata) { if (cdata) {
int i; int i;
cfile.writeString("\n"); cfile.writeString("\n");
@ -1110,7 +1110,7 @@ void TiXmlDeclaration::operator=(const TiXmlDeclaration &copy) {
copy.CopyTo(this); copy.CopyTo(this);
} }
void TiXmlDeclaration::Print(Common::DumpFile *cfile, int /*depth*/, TIXML_STRING *str) const { void TiXmlDeclaration::Print(Common::WriteStream *cfile, int /*depth*/, TIXML_STRING *str) const {
if (cfile) if (cfile)
cfile->writeString("<?xml "); cfile->writeString("<?xml ");
if (str) if (str)
@ -1171,7 +1171,7 @@ TiXmlNode *TiXmlDeclaration::Clone() const {
return clone; return clone;
} }
void TiXmlUnknown::Print(Common::DumpFile &cfile, int depth) const { void TiXmlUnknown::Print(Common::WriteStream &cfile, int depth) const {
for (int i = 0; i < depth; i++) for (int i = 0; i < depth; i++)
cfile.writeString(" "); cfile.writeString(" ");
cfile.writeString("<" + value + ">"); cfile.writeString("<" + value + ">");

View File

@ -165,7 +165,7 @@ public:
(For an unformatted stream, use the << operator.) (For an unformatted stream, use the << operator.)
*/ */
virtual void Print(Common::DumpFile &file, int depth) const = 0; virtual void Print(Common::WriteStream &file, int depth) const = 0;
/** The world does not agree on whether white space should be kept or /** The world does not agree on whether white space should be kept or
not. In order to make everyone happy, these global, static functions not. In order to make everyone happy, these global, static functions
@ -792,10 +792,10 @@ public:
virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding); virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);
// Prints this Attribute to a FILE stream. // Prints this Attribute to a FILE stream.
virtual void Print(Common::DumpFile &file, int depth) const { virtual void Print(Common::WriteStream &file, int depth) const {
Print(&file, depth, 0); Print(&file, depth, 0);
} }
void Print(Common::DumpFile *cfile, int depth, TIXML_STRING *str) const; void Print(Common::WriteStream *cfile, int depth, TIXML_STRING *str) const;
// [internal use] // [internal use]
// Set the document pointer so the attribute can report errors. // Set the document pointer so the attribute can report errors.
@ -1016,7 +1016,7 @@ public:
/// Creates a new Element and returns it - the returned element is a copy. /// Creates a new Element and returns it - the returned element is a copy.
virtual TiXmlNode *Clone() const; virtual TiXmlNode *Clone() const;
// Print the Element to a FILE stream. // Print the Element to a FILE stream.
virtual void Print(Common::DumpFile &cfile, int depth) const; virtual void Print(Common::WriteStream &cfile, int depth) const;
/* Attribtue parsing starts: next char past '<' /* Attribtue parsing starts: next char past '<'
returns: next char past '>' returns: next char past '>'
@ -1066,7 +1066,7 @@ public:
/// Returns a copy of this Comment. /// Returns a copy of this Comment.
virtual TiXmlNode *Clone() const; virtual TiXmlNode *Clone() const;
// Write this Comment to a FILE stream. // Write this Comment to a FILE stream.
virtual void Print(Common::DumpFile &cfile, int depth) const; virtual void Print(Common::WriteStream &cfile, int depth) const;
/* Attribtue parsing starts: at the ! of the !-- /* Attribtue parsing starts: at the ! of the !--
returns: next char past '>' returns: next char past '>'
@ -1123,7 +1123,7 @@ public:
void operator=(const TiXmlText &base) { base.CopyTo(this); } void operator=(const TiXmlText &base) { base.CopyTo(this); }
// Write this text object to a FILE stream. // Write this text object to a FILE stream.
virtual void Print(Common::DumpFile &cfile, int depth) const; virtual void Print(Common::WriteStream &cfile, int depth) const;
/// Queries whether this represents text using a CDATA section. /// Queries whether this represents text using a CDATA section.
bool CDATA() const { return cdata; } bool CDATA() const { return cdata; }
@ -1199,8 +1199,8 @@ public:
/// Creates a copy of this Declaration and returns it. /// Creates a copy of this Declaration and returns it.
virtual TiXmlNode *Clone() const; virtual TiXmlNode *Clone() const;
// Print this declaration to a FILE stream. // Print this declaration to a FILE stream.
virtual void Print(Common::DumpFile *cfile, int depth, TIXML_STRING *str) const; virtual void Print(Common::WriteStream *cfile, int depth, TIXML_STRING *str) const;
virtual void Print(Common::DumpFile &cfile, int depth) const { virtual void Print(Common::WriteStream &cfile, int depth) const {
Print(&cfile, depth, 0); Print(&cfile, depth, 0);
} }
@ -1244,7 +1244,7 @@ public:
/// Creates a copy of this Unknown and returns it. /// Creates a copy of this Unknown and returns it.
virtual TiXmlNode *Clone() const; virtual TiXmlNode *Clone() const;
// Print this Unknown to a FILE stream. // Print this Unknown to a FILE stream.
virtual void Print(Common::DumpFile &cfile, int depth) const; virtual void Print(Common::WriteStream &cfile, int depth) const;
virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding); virtual const char *Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding);
@ -1302,9 +1302,9 @@ public:
will be interpreted as an XML file. TinyXML doesn't stream in XML from the current will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
file location. Streaming may be added in the future. file location. Streaming may be added in the future.
*/ */
bool LoadFile(Common::File &file, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING); bool LoadFile(Common::SeekableReadStream &file, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
/// Save a file using the given FILE*. Returns true if successful. /// Save a file using the given FILE*. Returns true if successful.
bool SaveFile(Common::DumpFile &) const; bool SaveFile(Common::WriteStream &) const;
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
bool LoadFile(const std::string &filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING) ///< STL std::string version. bool LoadFile(const std::string &filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING) ///< STL std::string version.
@ -1408,7 +1408,7 @@ public:
// char* PrintToMemory() const; // char* PrintToMemory() const;
/// Print this Document to file /// Print this Document to file
virtual void Print(Common::DumpFile &file, int depth = 0) const; virtual void Print(Common::WriteStream &file, int depth = 0) const;
// [internal use] // [internal use]
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding); void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding);