BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / cortex / Persistence / ImportContext.cpp
blob9727902fd69e12eb7d26dc8ebb0b49cca2798551
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 // ImportContext.cpp
33 // e.moon 1jul99
35 #include "ImportContext.h"
36 #include "expat.h"
38 using namespace std;
40 __USE_CORTEX_NAMESPACE
42 // -------------------------------------------------------- //
43 // ctor/dtor
44 // -------------------------------------------------------- //
46 ImportContext::~ImportContext() {}
47 ImportContext::ImportContext(list<BString>& errors) :
48 m_state(PARSING),
49 m_errors(errors),
50 m_pParser(0) {}
52 // -------------------------------------------------------- //
53 // accessors
54 // -------------------------------------------------------- //
56 // fetch the current element (tag)
57 // (returns 0 if the stack is empty)
58 const char* ImportContext::element() const {
59 return (m_elementStack.size()) ?
60 m_elementStack.back().String() :
64 const char* ImportContext::parentElement() const {
65 if(m_elementStack.size() < 2)
66 return 0;
67 list<BString>::const_reverse_iterator it = m_elementStack.rbegin();
68 ++it;
69 return (*it).String();
72 list<BString>& ImportContext::errors() const {
73 return m_errors;
75 const ImportContext::state_t ImportContext::state() const {
76 return m_state;
79 // -------------------------------------------------------- //
80 // error-reporting operations
81 // -------------------------------------------------------- //
83 // register a warning to be returned once the deserialization
84 // process is complete.
85 void ImportContext::reportWarning(
86 const char* pText) {
88 XML_Parser p = (XML_Parser)m_pParser;
90 BString err = "Warning: ";
91 err << pText;
92 if(p) {
93 err << "\n (line " <<
94 (uint32)XML_GetCurrentLineNumber(p) << ", column " <<
95 (uint32)XML_GetCurrentColumnNumber(p) << ", element '" <<
96 (element() ? element() : "(none)") << "')\n";
97 } else
98 err << "\n";
99 m_errors.push_back(err);
102 // register a fatal error; halts the deserialization process
103 // as soon as possible.
104 void ImportContext::reportError(
105 const char* pText) {
107 XML_Parser p = (XML_Parser)m_pParser;
109 BString err = "FATAL ERROR: ";
110 err << pText;
111 if(p) {
112 err << "\n (line " <<
113 (uint32)XML_GetCurrentLineNumber(p) << ", column " <<
114 (uint32)XML_GetCurrentColumnNumber(p) << ", element '" <<
115 (element() ? element() : "(none)") << "')\n";
116 } else
117 err << "\n";
118 m_errors.push_back(err);
120 m_state = ABORT;
123 // -------------------------------------------------------- //
124 // internal operations
125 // -------------------------------------------------------- //
127 void ImportContext::reset() {
128 m_state = PARSING;
129 m_elementStack.clear();
130 // +++++ potential for memory leaks; reset() is currently
131 // only to be called after an identify cycle, during
132 // which no objects are created anyway, but this still
133 // gives me the shivers...
134 m_objectStack.clear();
137 // END -- ImportContext.cpp --