• 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 <wtf/Vector.h>
30 
31 namespace WebCore {
32 
33 class String;
34 
35 // Writes a limited subset of binary property lists.
36 // Covers only what's needed for writing browser history as of this writing.
37 class BinaryPropertyListObjectStream {
38 public:
39     // Call writeBooleanTrue to write the boolean true value.
40     // A single shared object will be used in the serialized list.
41     virtual void writeBooleanTrue() = 0;
42 
43     // Call writeInteger to write an integer value.
44     // A single shared object will be used for each integer in the serialized list.
45     virtual void writeInteger(int) = 0;
46 
47     // Call writeString to write a string value.
48     // A single shared object will be used for each string in the serialized list.
49     virtual void writeString(const String&) = 0;
50 
51     // Call writeUniqueString instead of writeString when it's unlikely the
52     // string will be written twice in the same property list; this saves hash
53     // table overhead for such strings. A separate object will be used for each
54     // of these strings in the serialized list.
55     virtual void writeUniqueString(const String&) = 0;
56     virtual void writeUniqueString(const char*) = 0;
57 
58     // Call writeIntegerArray instead of writeArrayStart/writeArrayEnd for
59     // arrays entirely composed of integers. A single shared object will be used
60     // for each identical array in the serialized list. Warning: The integer
61     // pointer must remain valid until the writeBinaryPropertyList function
62     // returns, because these lists are put into a hash table without copying
63     // them -- that's OK if the client already has a Vector<int>.
64     virtual void writeIntegerArray(const int*, size_t) = 0;
65 
66     // After calling writeArrayStart, write array elements.
67     // Then call writeArrayEnd, passing in the result from writeArrayStart.
68     // A separate object will be used for each of these arrays in the serialized list.
69     virtual size_t writeArrayStart() = 0;
70     virtual void writeArrayEnd(size_t resultFromWriteArrayStart) = 0;
71 
72     // After calling writeDictionaryStart, write all keys, then all values.
73     // Then call writeDictionaryEnd, passing in the result from writeDictionaryStart.
74     // A separate object will be used for each dictionary in the serialized list.
75     virtual size_t writeDictionaryStart() = 0;
76     virtual void writeDictionaryEnd(size_t resultFromWriteDictionaryStart) = 0;
77 
78 protected:
~BinaryPropertyListObjectStream()79     virtual ~BinaryPropertyListObjectStream() { }
80 };
81 
82 class BinaryPropertyListWriter {
83 public:
84     // Calls writeObjects once to prepare for writing and determine how big a
85     // buffer is required. Then calls buffer to get the appropriately-sized
86     // buffer, then calls writeObjects a second time and writes the property list.
87     void writePropertyList();
88 
89 protected:
~BinaryPropertyListWriter()90     virtual ~BinaryPropertyListWriter() { }
91 
92 private:
93     // Called by writePropertyList.
94     // Must call the object stream functions for the objects to be written
95     // into the property list.
96     virtual void writeObjects(BinaryPropertyListObjectStream&) = 0;
97 
98     // Called by writePropertyList.
99     // Returns the buffer that the writer should write into.
100     virtual UInt8* buffer(size_t) = 0;
101 
102     friend class BinaryPropertyListPlan;
103     friend class BinaryPropertyListSerializer;
104 };
105 
106 }
107 
108 #endif
109