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