]>
Dogcows Code - chaz/yoink/blob - src/deserializer.hh
2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
29 #ifndef _DESERIALIZER_HH_
30 #define _DESERIALIZER_HH_
33 * @file deserializer.hh
34 * Deserialize structures and types from input on a stream.
41 #include <boost/shared_ptr.hpp>
47 class serializable
; // forward declaration
48 typedef boost::shared_ptr
<serializable
> serializable_ptr
;
55 * Construction is initialization. A deserializer can be constructed with
56 * either an input stream or a string representing a filename that will be
57 * read from. If a stream is provided, it will not be closed after parsing,
58 * but the parser may read past the end of usable bytes, so you should not
59 * use a deserializer on a stream that you expect to continue to use after
60 * the deserialization.
61 * @param comments If true, C and C++-style comments will be allowed and
62 * ignored by the parser.
63 * @param check If true, UTF-8 strings will be checked for validity and an
64 * exception thrown if such a problem exists. Otherwise strings will not be
68 deserializer(const std::string
& filePath
, bool comments
= false,
70 deserializer(std::istream
& input
, bool comments
= false, bool check
= false);
74 * Parse the object from of the stream. The stream is considered to be
75 * dominated by the parser and may read and discard bytes past the end of
76 * the actual parsed object. Only one object can be deserialized by the
80 serializable_ptr
deserialize();
83 * Used by serializable objects to parse themselves. These methods should
84 * generally not be used directory for deserialization. This one returns
85 * the next object in the queue which has been parsed. This method may
86 * block if more data is pending and an object has not bee constructed yet.
87 * The caller takes ownership of the object which has been allocated with
88 * the new operator and must therefore be sure to delete the object as
89 * appropriated. Null (0) will be returned by this method to signify one of
90 * three things: 1) the end of an array, 2) the end of a map/dictionary, or
91 * 3) there is nothing more to be obtained. Container objects will be empty
92 * and will have to be filled with their contained elements by repeatedly
93 * calling this method until a null is returned. This method will continue
94 * to return the same value until pop() is called which will cause this
95 * method to return the next object as expected.
98 serializable
* pullNext();
101 * If the object returned by pullNext() has been received successfully and
102 * the caller is ready for the next object, this method should be called to
103 * take that object off of the queue.
110 * This exception is thrown upon deserialization errors.
113 struct exception
: std::runtime_error
115 explicit exception(const std::string
& what_arg
) :
116 std::runtime_error(what_arg
) {}
120 class deserializer_impl
;
121 boost::shared_ptr
<deserializer_impl
> impl
;
128 #endif // _DESERIALIZER_HH_
130 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.039884 seconds and 5 git commands to generate.