[libxml++] Validators: Change which methods are virtual, add override
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Validators: Change which methods are virtual, add override
- Date: Thu, 24 Sep 2015 07:58:43 +0000 (UTC)
commit 31716dcae4acfdd9e85e1076e084f277eef2f554
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Sep 24 09:55:55 2015 +0200
Validators: Change which methods are virtual, add override
* libxml++/validators/validator.h: Add some pure virtual methods.
* libxml++/validators/dtdvalidator.[h|cc]: Only overridden methods are virtual.
operator bool() is explicit and overridden. validate() returns void.
* libxml++/validators/schemavalidatorbase.h: Replace operator const void*()
by explicit operator bool(). Remove typedef BoolExpr.
* libxml++/validators/relaxngvalidator.[h|cc]:
* libxml++/validators/xsdvalidator.[h|cc]: Replace operator const void*()
by explicit operator bool(). Add override. Bug #754673.
libxml++/validators/dtdvalidator.cc | 14 +++++-------
libxml++/validators/dtdvalidator.h | 27 ++++++++++++-----------
libxml++/validators/relaxngvalidator.cc | 2 +-
libxml++/validators/relaxngvalidator.h | 15 +++++--------
libxml++/validators/schemavalidatorbase.h | 10 +--------
libxml++/validators/validator.h | 32 ++++++++++++++++++++++++++++-
libxml++/validators/xsdvalidator.cc | 2 +-
libxml++/validators/xsdvalidator.h | 15 +++++--------
8 files changed, 66 insertions(+), 51 deletions(-)
---
diff --git a/libxml++/validators/dtdvalidator.cc b/libxml++/validators/dtdvalidator.cc
index be4e6ca..210064f 100644
--- a/libxml++/validators/dtdvalidator.cc
+++ b/libxml++/validators/dtdvalidator.cc
@@ -32,7 +32,7 @@ DtdValidator::DtdValidator(const Glib::ustring& file)
parse_subset("",file);
}
-DtdValidator::DtdValidator(const Glib::ustring& external,const Glib::ustring& system)
+DtdValidator::DtdValidator(const Glib::ustring& external, const Glib::ustring& system)
: dtd_(nullptr)
{
parse_subset(external,system);
@@ -49,7 +49,7 @@ void DtdValidator::parse_file(const Glib::ustring& filename)
parse_subset("",filename);
}
-void DtdValidator::parse_subset(const Glib::ustring& external,const Glib::ustring& system)
+void DtdValidator::parse_subset(const Glib::ustring& external, const Glib::ustring& system)
{
release_underlying(); // Free any existing dtd.
xmlResetLastError();
@@ -106,7 +106,7 @@ void DtdValidator::release_underlying()
}
}
-DtdValidator::operator bool() const
+DtdValidator::operator bool() const noexcept
{
return dtd_ != nullptr;
}
@@ -121,9 +121,9 @@ const Dtd* DtdValidator::get_dtd() const
return dtd_;
}
-bool DtdValidator::validate(const Document* doc)
+void DtdValidator::validate(const Document* document)
{
- if (!doc)
+ if (!document)
{
throw internal_error("Document pointer cannot be 0.");
}
@@ -145,15 +145,13 @@ bool DtdValidator::validate(const Document* doc)
xmlResetLastError();
initialize_valid();
- const bool res = (bool)xmlValidateDtd( valid_, (xmlDoc*)doc->cobj(), dtd_->cobj() );
+ const bool res = (bool)xmlValidateDtd( valid_, (xmlDoc*)document->cobj(), dtd_->cobj() );
if (!res)
{
check_for_exception();
throw validity_error("Document failed DTD validation\n" + format_xml_error());
}
-
- return res;
}
} // namespace xmlpp
diff --git a/libxml++/validators/dtdvalidator.h b/libxml++/validators/dtdvalidator.h
index 01b04c1..aaa7a8d 100644
--- a/libxml++/validators/dtdvalidator.h
+++ b/libxml++/validators/dtdvalidator.h
@@ -15,6 +15,7 @@
namespace xmlpp {
/** XML DTD validator.
+ * DTD = Document Type Definition
*/
class DtdValidator : public Validator
{
@@ -32,45 +33,47 @@ public:
* @param system The URL of the DTD.
* @throws xmlpp::parse_error
*/
- explicit DtdValidator(const Glib::ustring& external,const Glib::ustring& system);
+ explicit DtdValidator(const Glib::ustring& external, const Glib::ustring& system);
~DtdValidator() override;
- //TODO: Remove virtuals when we can break ABI,
- //or really put these in the base class.
-
/** Parse an external subset (DTD file).
* If the validator already contains a DTD, that DTD is deleted.
* @param external The external ID of the DTD.
* @param system The URL of the DTD.
* @throws xmlpp::parse_error
*/
- virtual void parse_subset(const Glib::ustring& external,const Glib::ustring& system);
+ void parse_subset(const Glib::ustring& external, const Glib::ustring& system);
/** Parse an external subset (DTD file).
* If the validator already contains a DTD, that DTD is deleted.
* @param filename The URL of the DTD.
* @throws xmlpp::parse_error
*/
- virtual void parse_file(const Glib::ustring& filename);
+ void parse_file(const Glib::ustring& filename) override;
/** Parse a DTD from a string.
* If the validator already contains a DTD, that DTD is deleted.
* @param contents The DTD as a string.
* @throws xmlpp::parse_error
*/
- virtual void parse_memory(const Glib::ustring& contents);
+ void parse_memory(const Glib::ustring& contents) override;
/** Parse a DTD from a stream.
* If the validator already contains a DTD, that DTD is deleted.
* @param in The stream.
* @throws xmlpp::parse_error
*/
- virtual void parse_stream(std::istream& in);
+ void parse_stream(std::istream& in);
/** Test whether a DTD has been parsed.
+ * For instance
+ * @code
+ * if (validator)
+ * do_something();
+ * @endcode
*/
- operator bool() const;
+ explicit operator bool() const noexcept override;
/** Get the parsed DTD.
* @returns A pointer to the parsed DTD, or <tt>0</tt>.
@@ -85,12 +88,11 @@ public:
/** Validate a document, using a previously parsed DTD.
* The internal subset (if present) is de-coupled (i.e. not used),
* which could give problems if ID or IDREF is present.
- * @param doc Pointer to the document.
- * @returns Whether the document is valid.
+ * @param document Pointer to the document.
* @throws xmlpp::internal_error
* @throws xmlpp::validity_error
*/
- bool validate(const Document* doc);
+ void validate(const Document* document) override;
protected:
void release_underlying() override;
@@ -101,4 +103,3 @@ protected:
} // namespace xmlpp
#endif //__LIBXMLPP_VALIDATORS_DTDVALIDATOR_H
-
diff --git a/libxml++/validators/relaxngvalidator.cc b/libxml++/validators/relaxngvalidator.cc
index 0d00560..bbd9c9a 100644
--- a/libxml++/validators/relaxngvalidator.cc
+++ b/libxml++/validators/relaxngvalidator.cc
@@ -117,7 +117,7 @@ const RelaxNGSchema* RelaxNGValidator::get_schema() const
return pimpl_->schema;
}
-RelaxNGValidator::operator const void*() const
+RelaxNGValidator::operator bool() const noexcept
{
return reinterpret_cast<const void*>(pimpl_->schema && pimpl_->schema->cobj());
}
diff --git a/libxml++/validators/relaxngvalidator.h b/libxml++/validators/relaxngvalidator.h
index 1f86222..38051c6 100644
--- a/libxml++/validators/relaxngvalidator.h
+++ b/libxml++/validators/relaxngvalidator.h
@@ -71,9 +71,6 @@ public:
~RelaxNGValidator() override;
- //TODO: Remove virtuals when we can break ABI,
- //or really put these in the base class.
-
/** Parse a schema definition file.
* The schema must be defined with XML syntax (.rng file). The compact syntax
* (.rnc file) is not supported.
@@ -83,7 +80,7 @@ public:
* @param filename The URL of the schema.
* @throws xmlpp::parse_error
*/
- virtual void parse_file(const Glib::ustring& filename);
+ void parse_file(const Glib::ustring& filename) override;
/** Parse a schema definition from a string.
* The schema must be defined with XML syntax. The compact syntax is not supported.
@@ -93,7 +90,7 @@ public:
* @param contents The schema definition as a string.
* @throws xmlpp::parse_error
*/
- virtual void parse_memory(const Glib::ustring& contents);
+ void parse_memory(const Glib::ustring& contents) override;
/** Parse a schema definition from a document.
* If the validator already contains a schema, that schema is released
@@ -101,7 +98,7 @@ public:
* @param document A preparsed document tree, containing the schema definition.
* @throws xmlpp::parse_error
*/
- virtual void parse_document(const Document* document);
+ void parse_document(const Document* document) override;
/** Set a schema.
* If the validator already contains a schema, that schema is released
@@ -123,7 +120,7 @@ public:
* do_something();
* @endcode
*/
- virtual operator BoolExpr() const;
+ explicit operator bool() const noexcept override;
/** Get the schema.
* @returns A pointer to the schema, or <tt>0</tt>.
@@ -140,7 +137,7 @@ public:
* @throws xmlpp::internal_error
* @throws xmlpp::validity_error
*/
- virtual void validate(const Document* document);
+ void validate(const Document* document) override;
/** Validate an XML file, using a previously parsed schema.
* @param filename The URL of the XML file.
@@ -148,7 +145,7 @@ public:
* @throws xmlpp::parse_error
* @throws xmlpp::validity_error
*/
- virtual void validate(const Glib::ustring& filename);
+ void validate(const Glib::ustring& filename) override;
protected:
void initialize_valid() override;
diff --git a/libxml++/validators/schemavalidatorbase.h b/libxml++/validators/schemavalidatorbase.h
index 85299fd..18a6a35 100644
--- a/libxml++/validators/schemavalidatorbase.h
+++ b/libxml++/validators/schemavalidatorbase.h
@@ -40,9 +40,6 @@ public:
SchemaValidatorBase();
~SchemaValidatorBase() override;
- //TODO: Remove virtuals when we can break ABI,
- //or really put these in the base class.
-
/** Parse a schema definition file.
* If the validator already contains a schema, that schema is released
* (deleted if the validator owns the schema).
@@ -67,11 +64,6 @@ public:
*/
virtual void parse_document(const Document* document) = 0;
- /** This typedef is just to make it more obvious that
- * our operator const void* should be used like operator bool().
- */
- typedef const void* BoolExpr;
-
/** Test whether a schema has been parsed.
* For instance
* @code
@@ -79,7 +71,7 @@ public:
* do_something();
* @endcode
*/
- virtual operator BoolExpr() const = 0;
+ explicit virtual operator bool() const noexcept = 0;
/** Validate a document, using a previously parsed schema.
* @param document Pointer to the document.
diff --git a/libxml++/validators/validator.h b/libxml++/validators/validator.h
index 82c94c8..e46f899 100644
--- a/libxml++/validators/validator.h
+++ b/libxml++/validators/validator.h
@@ -12,7 +12,7 @@
#pragma warning (disable : 4786)
#endif
-#include <libxml++/nodes/element.h>
+#include <libxml++/noncopyable.h>
#include <libxml++/exceptions/validity_error.h>
#include <libxml++/exceptions/internal_error.h>
#include <exception> // std::exception_ptr
@@ -23,6 +23,8 @@ extern "C" {
namespace xmlpp {
+class Document;
+
/** Base class for XML validators.
*/
class Validator : NonCopyable
@@ -31,6 +33,34 @@ public:
Validator();
~Validator() override;
+ /** Parse a schema definition file or an external subset (DTD file).
+ * @param filename The URL of the schema or the DTD.
+ * @throws xmlpp::parse_error
+ */
+ virtual void parse_file(const Glib::ustring& filename) = 0;
+
+ /** Parse a schema definition or a DTD from a string.
+ * @param contents The schema definition or the DTD as a string.
+ * @throws xmlpp::parse_error
+ */
+ virtual void parse_memory(const Glib::ustring& contents) = 0;
+
+ /** Validate a document, using a previously parsed schema or DTD.
+ * @param document Pointer to the document.
+ * @throws xmlpp::internal_error
+ * @throws xmlpp::validity_error
+ */
+ virtual void validate(const Document* document) = 0;
+
+ /** Test whether a schema or a DTD has been parsed.
+ * For instance
+ * @code
+ * if (validator)
+ * do_something();
+ * @endcode
+ */
+ explicit virtual operator bool() const noexcept = 0;
+
protected:
virtual void initialize_valid();
virtual void release_underlying();
diff --git a/libxml++/validators/xsdvalidator.cc b/libxml++/validators/xsdvalidator.cc
index 674296e..0dd8a09 100644
--- a/libxml++/validators/xsdvalidator.cc
+++ b/libxml++/validators/xsdvalidator.cc
@@ -114,7 +114,7 @@ const XsdSchema* XsdValidator::get_schema() const
return pimpl_->schema;
}
-XsdValidator::operator const void*() const
+XsdValidator::operator bool() const noexcept
{
return reinterpret_cast<const void*>(pimpl_->schema && pimpl_->schema->cobj());
}
diff --git a/libxml++/validators/xsdvalidator.h b/libxml++/validators/xsdvalidator.h
index bf65ecd..9f784bb 100644
--- a/libxml++/validators/xsdvalidator.h
+++ b/libxml++/validators/xsdvalidator.h
@@ -67,16 +67,13 @@ public:
~XsdValidator() override;
- //TODO: Remove virtuals when we can break ABI,
- //or really put these in the base class.
-
/** Parse a schema definition file.
* If the validator already contains a schema, that schema is released
* (deleted if the validator owns the schema).
* @param filename The URL of the schema.
* @throws xmlpp::parse_error
*/
- virtual void parse_file(const Glib::ustring& filename);
+ void parse_file(const Glib::ustring& filename) override;
/** Parse a schema definition from a string.
* If the validator already contains a schema, that schema is released
@@ -84,7 +81,7 @@ public:
* @param contents The schema definition as a string.
* @throws xmlpp::parse_error
*/
- virtual void parse_memory(const Glib::ustring& contents);
+ void parse_memory(const Glib::ustring& contents) override;
/** Parse a schema definition from a document.
* If the validator already contains a schema, that schema is released
@@ -92,7 +89,7 @@ public:
* @param document A preparsed document tree, containing the schema definition.
* @throws xmlpp::parse_error
*/
- virtual void parse_document(const Document* document);
+ void parse_document(const Document* document) override;
/** Set a schema.
* If the validator already contains a schema, that schema is released
@@ -114,7 +111,7 @@ public:
* do_something();
* @endcode
*/
- virtual operator BoolExpr() const;
+ explicit operator bool() const noexcept override;
/** Get the schema.
* @returns A pointer to the schema, or <tt>0</tt>.
@@ -131,14 +128,14 @@ public:
* @throws xmlpp::internal_error
* @throws xmlpp::validity_error
*/
- virtual void validate(const Document* document);
+ void validate(const Document* document) override;
/** Validate an XML file, using a previously parsed schema.
* @param filename The URL of the XML file.
* @throws xmlpp::internal_error
* @throws xmlpp::validity_error
*/
- virtual void validate(const Glib::ustring& filename);
+ void validate(const Glib::ustring& filename) override;
protected:
void initialize_valid() override;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]