1 #if !defined(__DALI_INTERNAL_ARCHIVE_H__)
2 #define __DALI_INTERNAL_ARCHIVE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
38 * Archive class. Serializes data to a Tag-Length-Value archive
43 typedef std::pair<unsigned int, std::streampos> ChunkHeader;
48 * @param[in] buf An open streambuf
50 Archive(std::streambuf& buf);
60 unsigned int GetVersion() const
67 * @param[in] version the version number
69 void SetVersion(const unsigned int version)
75 * Returns the result of the archiving operation
76 * The result status is initialised to true on construction
77 * Any failure will set it to false
78 * @return the archiving result, true signals success.
80 bool GetResult() const
86 * Set the archive status to failed
88 void SetResultFailed()
94 * Write a bytestream to the archive
95 * @param[in] data A pointer to the data
96 * @param[in] length The length of the data in bytes
97 * @return true if the data was successfully written
99 virtual bool Write(const char* data, const unsigned int length)
105 * Read a bytestream from the archive
106 * @param[in] data A pointer to a buffer to store the data
107 * @param[in] length The length of the data in bytes
108 * @return true if the data was successfully read
110 virtual bool Read(char* data, const unsigned int length)
117 * @param[in] tag The FourCC tag for the chunk
118 * @return true if success.
120 virtual bool OpenChunk(const unsigned int tag) = 0;
123 * Skip an entire chunk
124 * @param[in] tag The FourCC tag for the chunk
126 virtual void SkipChunk(const unsigned int tag)
131 * Close the current chunk
132 * The chunk length is written to the archive
134 virtual void CloseChunk() = 0;
137 * Peek at the tag of the next chunk.
138 * This will move the file pointer to the next even byte,
139 * then read the next four bytes
140 * @result The FourCC tag for the next chunk.
142 virtual unsigned int PeekChunk()
148 unsigned int mVersion;
149 std::iostream mStream;
150 std::stack<ChunkHeader> mChunkStack;
155 * Archive specialization. Performs serialization to an Archive
157 class OutputArchive : public Archive
160 OutputArchive(std::streambuf& buf, const unsigned int version);
161 virtual ~OutputArchive();
163 public: // from Archive
165 * @copydoc Archive::Write()
167 virtual bool Write(const char* data, const unsigned int length);
170 * @copydoc Archive::OpenChunk()
171 * @param[in] tag The chunk tag
173 virtual bool OpenChunk(const unsigned int tag);
176 * @copydoc Archive::CloseChunk()
178 virtual void CloseChunk();
180 }; // class OutputArchive
183 * Archive specialization. Performs serialization from an Archive
185 class InputArchive : public Archive
188 InputArchive(std::streambuf& buf, const unsigned int version);
189 virtual ~InputArchive();
191 public: // from Archive
193 * @copydoc Archive::Read()
195 virtual bool Read(char* data, const unsigned int length);
198 * @copydoc Archive::OpenChunk()
199 * @param[in] tag The chunk tag
201 virtual bool OpenChunk(const unsigned int tag);
204 * @copydoc Archive::SkipChunk()
205 * @param[in] tag The chunk tag
207 virtual void SkipChunk(const unsigned int tag);
210 * @copydoc Archive::CloseChunk()
212 virtual void CloseChunk();
215 * @copydoc Archive::PeekChunk()
217 virtual unsigned int PeekChunk();
221 * Set the archive version as read from the archive
222 * @param[in] version The archives version number
224 void SetFileVersion(unsigned int version)
226 mFileVersion = version;
230 * Get the archive version number read from the archive
232 unsigned int GetFileVersion() const
237 unsigned int mFileVersion;
239 }; // class InputArchive
244 Archive& operator<< (Archive&, const char&);
245 Archive& operator>> (Archive&, char&);
246 Archive& operator<< (Archive&, const unsigned char&);
247 Archive& operator>> (Archive&, unsigned char&);
248 Archive& operator<< (Archive&, const bool&);
249 Archive& operator>> (Archive&, bool&);
250 Archive& operator<< (Archive&, const short&);
251 Archive& operator>> (Archive&, short&);
252 Archive& operator<< (Archive&, const unsigned short&);
253 Archive& operator>> (Archive&, unsigned short&);
254 Archive& operator<< (Archive&, const int&);
255 Archive& operator>> (Archive&, int&);
256 Archive& operator<< (Archive&, const unsigned int&);
257 Archive& operator>> (Archive&, unsigned int&);
258 Archive& operator<< (Archive&, const float&);
259 Archive& operator>> (Archive&, float&);
261 Archive& operator<< (Archive&, const std::string&);
262 Archive& operator>> (Archive&, std::string&);
265 Archive& operator<< (Archive&, const Vector2&);
266 Archive& operator>> (Archive&, Vector2&);
267 Archive& operator<< (Archive&, const Vector3&);
268 Archive& operator>> (Archive&, Vector3&);
269 Archive& operator<< (Archive&, const Vector4&);
270 Archive& operator>> (Archive&, Vector4&);
271 Archive& operator<< (Archive&, const Quaternion&);
272 Archive& operator>> (Archive&, Quaternion&);
273 Archive& operator<< (Archive&, const Matrix&);
274 Archive& operator>> (Archive&, Matrix&);
276 } // namespace Serialize
281 #endif // !defined(__DALI_INTERNAL_ARCHIVE_H__)