2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
35 #include "ImportContext.h"
40 __USE_CORTEX_NAMESPACE
42 // -------------------------------------------------------- //
44 // -------------------------------------------------------- //
46 ImportContext::~ImportContext() {}
47 ImportContext::ImportContext(list
<BString
>& errors
) :
52 // -------------------------------------------------------- //
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)
67 list
<BString
>::const_reverse_iterator it
= m_elementStack
.rbegin();
69 return (*it
).String();
72 list
<BString
>& ImportContext::errors() const {
75 const ImportContext::state_t
ImportContext::state() const {
79 // -------------------------------------------------------- //
80 // error-reporting operations
81 // -------------------------------------------------------- //
83 // register a warning to be returned once the deserialization
84 // process is complete.
85 void ImportContext::reportWarning(
88 XML_Parser p
= (XML_Parser
)m_pParser
;
90 BString err
= "Warning: ";
94 (uint32
)XML_GetCurrentLineNumber(p
) << ", column " <<
95 (uint32
)XML_GetCurrentColumnNumber(p
) << ", element '" <<
96 (element() ? element() : "(none)") << "')\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(
107 XML_Parser p
= (XML_Parser
)m_pParser
;
109 BString err
= "FATAL ERROR: ";
112 err
<< "\n (line " <<
113 (uint32
)XML_GetCurrentLineNumber(p
) << ", column " <<
114 (uint32
)XML_GetCurrentColumnNumber(p
) << ", element '" <<
115 (element() ? element() : "(none)") << "')\n";
118 m_errors
.push_back(err
);
123 // -------------------------------------------------------- //
124 // internal operations
125 // -------------------------------------------------------- //
127 void ImportContext::reset() {
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 --