libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / cortex / Persistence / Wrappers / MessageIO.h
blobd36b123b3264894244f4b340de863b4b1638f2ec
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 // MessageIO.h
33 // * PURPOSE
34 // Export/import of BMessages to and from
35 // XML using the Cortex persistence library.
36 // Messages are stored in a user-readable form.
38 // TO DO +++++
39 // - sanity-check string values (filter/escape single quotes)
41 // * HISTORY
42 // e.moon 1dec99 Begun.
44 #ifndef __MessageIO_H__
45 #define __MessageIO_H__
47 #include <Message.h>
48 #include <String.h>
49 #include "XML.h"
51 #include "cortex_defs.h"
52 __BEGIN_CORTEX_NAMESPACE
54 class MessageIO :
55 public IPersistent {
57 public: // *** ctor/dtor/accessor
58 virtual ~MessageIO();
60 MessageIO(); //nyi
62 // When given a message to export, this object does NOT take
63 // responsibility for deleting it. It will, however, handle
64 // deletion of an imported BMessage.
66 MessageIO(
67 const BMessage* message);
68 void setMessage(
69 BMessage* message);
71 // Returns 0 if no message has been set, and if no message has
72 // been imported.
74 const BMessage* message() const { return m_message; }
76 // Returns true if the message will be automatically deleted.
78 bool ownsMessage() const { return m_ownMessage; }
80 public: // *** static setup method
81 // call this method to install hooks for the tags needed by
82 // MessageIO into the given document type
83 static void AddTo(
84 XML::DocumentType* docType);
86 public: // *** XML formatting
87 static const char* const s_element;
89 public: // *** IPersistent impl.
91 // EXPORT:
93 void xmlExportBegin(
94 ExportContext& context) const;
96 void xmlExportAttributes(
97 ExportContext& context) const;
99 void xmlExportContent(
100 ExportContext& context) const;
102 void xmlExportEnd(
103 ExportContext& context) const;
106 // IMPORT:
108 virtual void xmlImportBegin(
109 ImportContext& context);
111 virtual void xmlImportAttribute(
112 const char* key,
113 const char* value,
114 ImportContext& context);
116 virtual void xmlImportContent(
117 const char* data,
118 uint32 length,
119 ImportContext& context);
121 virtual void xmlImportChild(
122 IPersistent* child,
123 ImportContext& context);
125 virtual void xmlImportComplete(
126 ImportContext& context);
128 virtual void xmlImportChildBegin(
129 const char* name,
130 ImportContext& context);
132 virtual void xmlImportChildAttribute(
133 const char* key,
134 const char* value,
135 ImportContext& context);
137 virtual void xmlImportChildContent(
138 const char* data,
139 uint32 length,
140 ImportContext& context);
142 virtual void xmlImportChildComplete(
143 const char* name,
144 ImportContext& context);
146 private: // *** members
147 bool m_ownMessage;
148 BMessage* m_message;
150 // name of the message (if used to import a nested BMessage)
151 BString m_name;
153 // current field
154 BString m_fieldName;
155 BString m_fieldData;
157 bool _isValidMessageElement(
158 const char* element) const;
160 status_t _importField(
161 BMessage* message,
162 const char* element,
163 const char* name,
164 const char* data);
166 status_t _exportField(
167 ExportContext& context,
168 BMessage* message,
169 type_code type,
170 const char* name,
171 int32 index) const;
174 __END_CORTEX_NAMESPACE
176 #endif /*__MessageIO_H__*/