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