libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / cortex / Persistence / Importer.h
blobe0ee7e230c62173e906a3e6350fe7299c7c99ef6
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // Importer.h
34 // * PURPOSE
35 // Given a stream of XML parser events, produce the object[s]
36 // represented by the markup.
38 // * HISTORY
39 // e.moon 30jun99 Moved actual object-building responsibility
40 // to IPersistent; this class is now internal
41 // to Cortex::XML.
42 // e.moon 28jun99 Begun. [was 'Importer']
44 #ifndef __Importer_H__
45 #define __Importer_H__
47 #include <list>
48 #include <String.h>
50 #include "ImportContext.h"
51 #include "XML.h"
52 #include "expat.h"
54 #include "cortex_defs.h"
55 __BEGIN_CORTEX_NAMESPACE
57 class Importer {
59 public: // *** ctor/dtor
60 virtual ~Importer();
62 // constructs a format-guessing Importer (uses the
63 // DocumentType registry)
64 Importer(
65 std::list<BString>& errors);
67 // the Importer takes ownership of the given context!
68 Importer(
69 ImportContext* context);
71 // constructs a manual Importer; the given root
72 // object is populated
73 Importer(
74 std::list<BString>& errors,
75 IPersistent* rootObject,
76 XML::DocumentType* docType);
78 // the Importer takes ownership of the given context!
79 Importer(
80 ImportContext* context,
81 IPersistent* rootObject,
82 XML::DocumentType* docType);
84 public: // *** accessors
86 // the import context
87 const ImportContext& context() const;
89 // matched document type
90 XML::DocumentType* docType() const;
92 // completed object (available if
93 // context().state() == ImportContext::COMPLETE, or
94 // if a root object was provided to the ctor)
95 IPersistent* target() const;
97 public: // *** operations
99 // put the importer into 'identify mode'
100 // (disengaged once the first element is encountered)
101 void setIdentifyMode();
103 // prepare to read the document after an identify cycle
104 void reset();
106 // handle a buffer; return false if an error occurs
107 bool parseBuffer(
108 const char* buffer,
109 uint32 length,
110 bool last);
112 public: // *** internal operations
114 // create & initialize parser
115 void initParser();
117 // clean up the parser
118 void freeParser();
120 public: // *** XML parser event hooks
122 virtual void xmlElementStart(
123 const char* name,
124 const char** attributes);
126 virtual void xmlElementEnd(
127 const char* name);
129 virtual void xmlProcessingInstruction(
130 const char* target,
131 const char* data);
133 // not 0-terminated
134 virtual void xmlCharacterData(
135 const char* data,
136 int32 length);
138 // not 0-terminated
139 virtual void xmlDefaultData(
140 const char* data,
141 int32 length);
143 private: // *** implementation
145 XML_Parser m_parser;
146 XML::DocumentType* m_docType;
148 // if true, the importer is being used to identify the
149 // document type -- it should halt as soon as the first
150 // element is encountered.
151 bool m_identify;
153 ImportContext* const m_context;
155 // the constructed object: if no rootObject was provided
156 // in the ctor, this is only filled in once the document
157 // end tag has been encountered.
158 IPersistent* m_rootObject;
161 __END_CORTEX_NAMESPACE
162 #endif /*__Importer_H__*/