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