]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSSerialize.h
adcfd2dd95ff2cf1ee1785604cef6525afc33de4
[apple/xnu.git] / libkern / libkern / c++ / OSSerialize.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* OSSerialize.h created by rsulack on Wen 25-Nov-1998 */
24
25 #ifndef _OS_OSSERIALIZE_H
26 #define _OS_OSSERIALIZE_H
27
28 #include <libkern/c++/OSObject.h>
29
30 class OSSet;
31 class OSDictionary;
32
33 /*!
34 @class OSSerialize
35 @abstract A class used by the OS Container classes to serialize their instance data.
36 @discussion This class is for the most part internal to the OS Container classes and should not be used directly. Each class inherits a serialize() method from OSObject which is used to actually serialize an object.
37 */
38
39 class OSSerialize : public OSObject
40 {
41 OSDeclareDefaultStructors(OSSerialize)
42
43 protected:
44 char *data; // container for serialized data
45 unsigned int length; // of serialized data (counting NULL)
46 unsigned int capacity; // of container
47 unsigned int capacityIncrement; // of container
48
49 unsigned int tag;
50 OSDictionary *tags; // tags for all objects seen
51
52 struct ExpansionData { };
53
54 /*! @var reserved
55 Reserved for future use. (Internal use only) */
56 ExpansionData *reserved;
57
58
59 public:
60 static OSSerialize *withCapacity(unsigned int capacity);
61
62 virtual char *text() const;
63
64 virtual void clearText(); // using this can be a great speedup
65 // if you are serializing the same object
66 // over and over again
67
68 // stuff to serialize your object
69 virtual bool previouslySerialized(const OSMetaClassBase *);
70
71 virtual bool addXMLStartTag(const OSMetaClassBase *o, const char *tagString);
72 virtual bool addXMLEndTag(const char *tagString);
73
74 virtual bool addChar(const char);
75 virtual bool addString(const char *);
76
77 // stuff you should never have to use (in theory)
78
79 virtual bool initWithCapacity(unsigned int inCapacity);
80 virtual unsigned int getLength() const;
81 virtual unsigned int getCapacity() const;
82 virtual unsigned int getCapacityIncrement() const;
83 virtual unsigned int setCapacityIncrement(unsigned increment);
84 virtual unsigned int ensureCapacity(unsigned int newCapacity);
85 virtual void free();
86
87 OSMetaClassDeclareReservedUnused(OSSerialize, 0);
88 OSMetaClassDeclareReservedUnused(OSSerialize, 1);
89 OSMetaClassDeclareReservedUnused(OSSerialize, 2);
90 OSMetaClassDeclareReservedUnused(OSSerialize, 3);
91 OSMetaClassDeclareReservedUnused(OSSerialize, 4);
92 OSMetaClassDeclareReservedUnused(OSSerialize, 5);
93 OSMetaClassDeclareReservedUnused(OSSerialize, 6);
94 OSMetaClassDeclareReservedUnused(OSSerialize, 7);
95 };
96
97 typedef bool (*OSSerializerCallback)(void * target, void * ref,
98 OSSerialize * s);
99
100 class OSSerializer : public OSObject
101 {
102 OSDeclareDefaultStructors(OSSerializer)
103
104 void * target;
105 void * ref;
106 OSSerializerCallback callback;
107
108 public:
109
110 static OSSerializer * forTarget(void * target,
111 OSSerializerCallback callback, void * ref = 0);
112
113 virtual bool serialize(OSSerialize * s) const;
114 };
115
116 #endif /* _OS_OSSERIALIZE_H */