02780057f5e2f0cc8f509832d9fb553878619c02
[platform/upstream/libxml++.git] / libxml++ / validators / schemavalidatorbase.h
1 /* Copyright (C) 2014 The libxml++ development team
2  *
3  * This file is part of libxml++.
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 #ifndef __LIBXMLPP_VALIDATOR_SCHEMAVALIDATORBASE_H
20 #define __LIBXMLPP_VALIDATOR_SCHEMAVALIDATORBASE_H
21
22 #include <libxml++/validators/validator.h>
23 #include <memory> // std::auto_ptr
24
25 namespace Glib
26 {
27 class LIBXMLPP_API ustring;
28 }
29
30 namespace xmlpp
31 {
32 class LIBXMLPP_API Document;
33
34 /** Base class for schema validators.
35  *
36  * @newin{2,38}
37  */
38 class LIBXMLPP_API SchemaValidatorBase : public Validator
39 {
40 public:
41   SchemaValidatorBase();
42   ~SchemaValidatorBase() override;
43
44   //TODO: Remove virtuals when we can break ABI,
45   //or really put these in the base class.
46
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
52    */
53   virtual void parse_file(const Glib::ustring& filename) = 0;
54
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
60    */
61   virtual void parse_memory(const Glib::ustring& contents) = 0;
62
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
68    */
69   virtual void parse_document(const Document* document) = 0;
70
71   /** This typedef is just to make it more obvious that
72    * our operator const void* should be used like operator bool().
73    */
74   typedef const void* BoolExpr;
75
76   /** Test whether a schema has been parsed.
77    * For instance
78    * @code
79    * if (validator)
80    *   do_something();
81    * @endcode
82    */
83   virtual operator BoolExpr() const = 0;
84
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
89    */
90   virtual void validate(const Document* document) = 0;
91
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
97    */
98   virtual void validate(const Glib::ustring& filename) = 0;
99
100 protected:
101   void initialize_valid() override;
102   void release_underlying() override;
103 };
104
105 } // namespace xmlpp
106
107 #endif //__LIBXMLPP_VALIDATOR_SCHEMAVALIDATORBASE_H