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