xref: /haiku/src/apps/cortex/Persistence/ImportContext.h (revision b55a57da7173b9af0432bd3e148d03f06161d036)
1 // ImportContext.h
2 // * PURPOSE
3 //   Describe the state of a deserialization ('load') operation.
4 //   The 'save' equivalent is ExportContext.
5 //
6 // * HISTORY
7 //   e.moon		29jun99		Begun
8 
9 #ifndef __ImportContext_H__
10 #define __ImportContext_H__
11 
12 #include <list>
13 #include <utility>
14 #include <String.h>
15 
16 #include "cortex_defs.h"
17 __BEGIN_CORTEX_NAMESPACE
18 
19 class IPersistent;
20 
21 class ImportContext {
22 	friend class Importer;
23 
24 public:													// *** types
25 	enum state_t {
26 		PARSING,
27 		COMPLETE,
28 		ABORT
29 	};
30 
31 public:													// *** ctor/dtor
32 	virtual ~ImportContext();
33 	ImportContext(
34 		std::list<BString>&						errors);
35 
36 public:													// *** accessors
37 
38 	// fetch the current element (tag)
39 	// (returns 0 if the stack is empty)
40 	const char* element() const;
41 
42 	// fetch the current element's parent
43 	// (returns 0 if the stack is empty or the current element is top-level)
44 	const char* parentElement() const;
45 
46 	std::list<BString>& errors() const;
47 	const state_t state() const;
48 
49 public:													// *** error-reporting operations
50 
51 	// register a warning to be returned once the deserialization
52 	// process is complete.
53 	void reportWarning(
54 		const char*									text);
55 
56 	// register a fatal error; halts the deserialization process
57 	// as soon as possible.
58 	void reportError(
59 		const char*									text);
60 
61 protected:											// *** internal operations
62 
63 	void reset();
64 
65 private:												// *** members
66 	state_t												m_state;
67 	std::list<BString>&							m_errors;
68 
69 	std::list<BString>								m_elementStack;
70 	typedef std::pair<const char*, IPersistent*> object_entry;
71 	std::list<object_entry>						m_objectStack;
72 
73 	void*													m_pParser;
74 };
75 __END_CORTEX_NAMESPACE
76 #endif /*__ImportContext_H__*/
77