• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef BinaryPropertyList_h
27 #define BinaryPropertyList_h
28 
29 #include <CoreFoundation/CoreFoundation.h>
30 
31 #include <wtf/Vector.h>
32 
33 namespace WebCore {
34 
35 class String;
36 
37 // Writes a limited subset of binary property lists.
38 // Covers only what's needed for writing browser history as of this writing.
39 class BinaryPropertyListObjectStream {
40 public:
41     // Call writeBooleanTrue to write the boolean true value.
42     // A single shared object will be used in the serialized list.
43     virtual void writeBooleanTrue() = 0;
44 
45     // Call writeInteger to write an integer value.
46     // A single shared object will be used for each integer in the serialized list.
47     virtual void writeInteger(int) = 0;
48 
49     // Call writeString to write a string value.
50     // A single shared object will be used for each string in the serialized list.
51     virtual void writeString(const String&) = 0;
52 
53     // Call writeUniqueString instead of writeString when it's unlikely the
54     // string will be written twice in the same property list; this saves hash
55     // table overhead for such strings. A separate object will be used for each
56     // of these strings in the serialized list.
57     virtual void writeUniqueString(const String&) = 0;
58     virtual void writeUniqueString(const char*) = 0;
59 
60     // Call writeIntegerArray instead of writeArrayStart/writeArrayEnd for
61     // arrays entirely composed of integers. A single shared object will be used
62     // for each identical array in the serialized list. Warning: The integer
63     // pointer must remain valid until the writeBinaryPropertyList function
64     // returns, because these lists are put into a hash table without copying
65     // them -- that's OK if the client already has a Vector<int>.
66     virtual void writeIntegerArray(const int*, size_t) = 0;
67 
68     // After calling writeArrayStart, write array elements.
69     // Then call writeArrayEnd, passing in the result from writeArrayStart.
70     // A separate object will be used for each of these arrays in the serialized list.
71     virtual size_t writeArrayStart() = 0;
72     virtual void writeArrayEnd(size_t resultFromWriteArrayStart) = 0;
73 
74     // After calling writeDictionaryStart, write all keys, then all values.
75     // Then call writeDictionaryEnd, passing in the result from writeDictionaryStart.
76     // A separate object will be used for each dictionary in the serialized list.
77     virtual size_t writeDictionaryStart() = 0;
78     virtual void writeDictionaryEnd(size_t resultFromWriteDictionaryStart) = 0;
79 
80 protected:
~BinaryPropertyListObjectStream()81     virtual ~BinaryPropertyListObjectStream() { }
82 };
83 
84 class BinaryPropertyListWriter {
85 public:
86     // Calls writeObjects once to prepare for writing and determine how big a
87     // buffer is required. Then calls buffer to get the appropriately-sized
88     // buffer, then calls writeObjects a second time and writes the property list.
89     void writePropertyList();
90 
91 protected:
~BinaryPropertyListWriter()92     virtual ~BinaryPropertyListWriter() { }
93 
94 private:
95     // Called by writePropertyList.
96     // Must call the object stream functions for the objects to be written
97     // into the property list.
98     virtual void writeObjects(BinaryPropertyListObjectStream&) = 0;
99 
100     // Called by writePropertyList.
101     // Returns the buffer that the writer should write into.
102     virtual UInt8* buffer(size_t) = 0;
103 
104     friend class BinaryPropertyListPlan;
105     friend class BinaryPropertyListSerializer;
106 };
107 
108 }
109 
110 #endif
111