libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / cortex / Persistence / Wrappers / FlatMessageIO.h
blob7a76f8c814bd55bd59bcf990e16c42919184d853
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 // FlatMessageIO.h
33 // * PURPOSE
34 // Efficient export/import of BMessages to and from
35 // XML using the Cortex persistence library.
36 // Messages are stored in flattened form.
37 // * HISTORY
38 // e.moon 6jul99 Begun.
40 // Example:
42 // <flat-BMessage
43 // encoding = 'base64'>
44 // nKJNFBlkn3lknbxlkfnbLKN/lknlknlDSLKn3lkn3l2k35234ljk234
45 // lkdsg23823nlknsdlkbNDSLKBNlkn3lk23n4kl23n423lknLKENL+==
46 // </flat-BMessage>
48 #ifndef __FlatMessageIO_H__
49 #define __FlatMessageIO_H__
51 #include <Message.h>
52 #include <String.h>
53 #include "XML.h"
55 #include "cortex_defs.h"
56 __BEGIN_CORTEX_NAMESPACE
58 class FlatMessageIO :
59 public IPersistent {
61 public: // *** ctor/dtor/accessor
62 virtual ~FlatMessageIO();
64 FlatMessageIO();
66 // When given a message to export, this object does NOT take
67 // responsibility for deleting it. It will, however, handle
68 // deletion of an imported BMessage.
70 FlatMessageIO(const BMessage* message);
71 void setMessage(BMessage* message);
73 // Returns 0 if no message has been set, and if no message has
74 // been imported.
76 const BMessage* message() const { return m_message; }
78 // Returns true if the message will be automatically deleted.
80 bool ownsMessage() const { return m_ownMessage; }
82 public: // *** static setup method
83 // call this method to install hooks for the tags needed by
84 // FlatMessageIO into the given document type
85 static void AddTo(XML::DocumentType* pDocType);
87 public: // *** XML formatting
88 static const char* const s_element;
89 static const uint16 s_encodeToMax = 72;
90 static const uint16 s_encodeToMin = 24;
92 public: // *** IPersistent impl.
94 // virtual void xmlExport(
95 // ostream& stream,
96 // ExportContext& context) const;
98 // EXPORT:
100 void xmlExportBegin(
101 ExportContext& context) const;
103 void xmlExportAttributes(
104 ExportContext& context) const;
106 void xmlExportContent(
107 ExportContext& context) const;
109 void xmlExportEnd(
110 ExportContext& context) const;
113 // IMPORT:
115 virtual void xmlImportBegin(
116 ImportContext& context);
118 virtual void xmlImportAttribute(
119 const char* key,
120 const char* value,
121 ImportContext& context);
123 virtual void xmlImportContent(
124 const char* data,
125 uint32 length,
126 ImportContext& context);
128 virtual void xmlImportChild(
129 IPersistent* child,
130 ImportContext& context);
132 virtual void xmlImportComplete(
133 ImportContext& context);
135 private: // *** members
136 bool m_ownMessage;
137 BMessage* m_message;
139 // encoded data is cached here during the import process
140 BString m_base64Data;
143 __END_CORTEX_NAMESPACE
145 #endif /*__FlatMessageIO_H__*/