1 /* Copyright (C) 2014 The libxml++ development team
3 * This file is part of libxml++.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef __LIBXMLPP_VALIDATOR_SCHEMAVALIDATORBASE_H
20 #define __LIBXMLPP_VALIDATOR_SCHEMAVALIDATORBASE_H
22 #include <libxml++/validators/validator.h>
23 #include <memory> // std::auto_ptr
27 class LIBXMLPP_API ustring;
32 class LIBXMLPP_API Document;
34 /** Base class for schema validators.
38 class LIBXMLPP_API SchemaValidatorBase : public Validator
41 SchemaValidatorBase();
42 ~SchemaValidatorBase() override;
44 //TODO: Remove virtuals when we can break ABI,
45 //or really put these in the base class.
47 /** Parse a schema definition file.
48 * If the validator already contains a schema, that schema is released
49 * (deleted if the validator owns the schema).
50 * @param filename The URL of the schema.
51 * @throws xmlpp::parse_error
53 virtual void parse_file(const Glib::ustring& filename) = 0;
55 /** Parse a schema definition from a string.
56 * If the validator already contains a schema, that schema is released
57 * (deleted if the validator owns the schema).
58 * @param contents The schema definition as a string.
59 * @throws xmlpp::parse_error
61 virtual void parse_memory(const Glib::ustring& contents) = 0;
63 /** Parse a schema definition from a document.
64 * If the validator already contains a schema, that schema is released
65 * (deleted if the validator owns the schema).
66 * @param document A preparsed document tree, containing the schema definition.
67 * @throws xmlpp::parse_error
69 virtual void parse_document(const Document* document) = 0;
71 /** This typedef is just to make it more obvious that
72 * our operator const void* should be used like operator bool().
74 typedef const void* BoolExpr;
76 /** Test whether a schema has been parsed.
83 virtual operator BoolExpr() const = 0;
85 /** Validate a document, using a previously parsed schema.
86 * @param document Pointer to the document.
87 * @throws xmlpp::internal_error
88 * @throws xmlpp::validity_error
90 virtual void validate(const Document* document) = 0;
92 /** Validate an XML file, using a previously parsed schema.
93 * @param filename The URL of the XML file.
94 * @throws xmlpp::internal_error
95 * @throws xmlpp::parse_error
96 * @throws xmlpp::validity_error
98 virtual void validate(const Glib::ustring& filename) = 0;
101 void initialize_valid() override;
102 void release_underlying() override;
107 #endif //__LIBXMLPP_VALIDATOR_SCHEMAVALIDATORBASE_H