1*c284bb0fSMatt Madia /* 2*c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon. 3*c284bb0fSMatt Madia * All rights reserved. 4*c284bb0fSMatt Madia * 5*c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without 6*c284bb0fSMatt Madia * modification, are permitted provided that the following conditions 7*c284bb0fSMatt Madia * are met: 8*c284bb0fSMatt Madia * 9*c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright 10*c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer. 11*c284bb0fSMatt Madia * 12*c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright 13*c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer in the 14*c284bb0fSMatt Madia * documentation and/or other materials provided with the distribution. 15*c284bb0fSMatt Madia * 16*c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products 17*c284bb0fSMatt Madia * derived from this software without specific prior written permission. 18*c284bb0fSMatt Madia * 19*c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 20*c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21*c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23*c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24*c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25*c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26*c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27*c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28*c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*c284bb0fSMatt Madia */ 30*c284bb0fSMatt Madia 31*c284bb0fSMatt Madia 32a0795c6fSMarcus Overhagen // ImportContext.h 33a0795c6fSMarcus Overhagen // * PURPOSE 34a0795c6fSMarcus Overhagen // Describe the state of a deserialization ('load') operation. 35a0795c6fSMarcus Overhagen // The 'save' equivalent is ExportContext. 36a0795c6fSMarcus Overhagen // 37a0795c6fSMarcus Overhagen // * HISTORY 38a0795c6fSMarcus Overhagen // e.moon 29jun99 Begun 39a0795c6fSMarcus Overhagen 40a0795c6fSMarcus Overhagen #ifndef __ImportContext_H__ 41a0795c6fSMarcus Overhagen #define __ImportContext_H__ 42a0795c6fSMarcus Overhagen 43a0795c6fSMarcus Overhagen #include <list> 44a0795c6fSMarcus Overhagen #include <utility> 45a0795c6fSMarcus Overhagen #include <String.h> 46a0795c6fSMarcus Overhagen 47a0795c6fSMarcus Overhagen #include "cortex_defs.h" 48a0795c6fSMarcus Overhagen __BEGIN_CORTEX_NAMESPACE 49a0795c6fSMarcus Overhagen 50a0795c6fSMarcus Overhagen class IPersistent; 51a0795c6fSMarcus Overhagen 52a0795c6fSMarcus Overhagen class ImportContext { 53a0795c6fSMarcus Overhagen friend class Importer; 54a0795c6fSMarcus Overhagen 55a0795c6fSMarcus Overhagen public: // *** types 56a0795c6fSMarcus Overhagen enum state_t { 57a0795c6fSMarcus Overhagen PARSING, 58a0795c6fSMarcus Overhagen COMPLETE, 59a0795c6fSMarcus Overhagen ABORT 60a0795c6fSMarcus Overhagen }; 61a0795c6fSMarcus Overhagen 62a0795c6fSMarcus Overhagen public: // *** ctor/dtor 63a0795c6fSMarcus Overhagen virtual ~ImportContext(); 64a0795c6fSMarcus Overhagen ImportContext( 6523e67806SIthamar R. Adema std::list<BString>& errors); 66a0795c6fSMarcus Overhagen 67a0795c6fSMarcus Overhagen public: // *** accessors 68a0795c6fSMarcus Overhagen 69a0795c6fSMarcus Overhagen // fetch the current element (tag) 70a0795c6fSMarcus Overhagen // (returns 0 if the stack is empty) 71a0795c6fSMarcus Overhagen const char* element() const; 72a0795c6fSMarcus Overhagen 73a0795c6fSMarcus Overhagen // fetch the current element's parent 74a0795c6fSMarcus Overhagen // (returns 0 if the stack is empty or the current element is top-level) 75a0795c6fSMarcus Overhagen const char* parentElement() const; 76a0795c6fSMarcus Overhagen 7723e67806SIthamar R. Adema std::list<BString>& errors() const; 78a0795c6fSMarcus Overhagen const state_t state() const; 79a0795c6fSMarcus Overhagen 80a0795c6fSMarcus Overhagen public: // *** error-reporting operations 81a0795c6fSMarcus Overhagen 82a0795c6fSMarcus Overhagen // register a warning to be returned once the deserialization 83a0795c6fSMarcus Overhagen // process is complete. 84a0795c6fSMarcus Overhagen void reportWarning( 85a0795c6fSMarcus Overhagen const char* text); 86a0795c6fSMarcus Overhagen 87a0795c6fSMarcus Overhagen // register a fatal error; halts the deserialization process 88a0795c6fSMarcus Overhagen // as soon as possible. 89a0795c6fSMarcus Overhagen void reportError( 90a0795c6fSMarcus Overhagen const char* text); 91a0795c6fSMarcus Overhagen 92a0795c6fSMarcus Overhagen protected: // *** internal operations 93a0795c6fSMarcus Overhagen 94a0795c6fSMarcus Overhagen void reset(); 95a0795c6fSMarcus Overhagen 96a0795c6fSMarcus Overhagen private: // *** members 97a0795c6fSMarcus Overhagen state_t m_state; 9823e67806SIthamar R. Adema std::list<BString>& m_errors; 99a0795c6fSMarcus Overhagen 10023e67806SIthamar R. Adema std::list<BString> m_elementStack; 10123e67806SIthamar R. Adema typedef std::pair<const char*, IPersistent*> object_entry; 10223e67806SIthamar R. Adema std::list<object_entry> m_objectStack; 103a0795c6fSMarcus Overhagen 104a0795c6fSMarcus Overhagen void* m_pParser; 105a0795c6fSMarcus Overhagen }; 106a0795c6fSMarcus Overhagen __END_CORTEX_NAMESPACE 107a0795c6fSMarcus Overhagen #endif /*__ImportContext_H__*/ 108