Otclient  14/8/2020
binarytree.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef BINARYTREE_H
24 #define BINARYTREE_H
25 
26 #include "declarations.h"
28 
29 enum {
33 };
34 
36 {
37 public:
38  BinaryTree(const FileStreamPtr& fin);
39  ~BinaryTree();
40 
41  void seek(uint pos);
42  void skip(uint len);
43  uint tell() { return m_pos; }
44  uint size() { unserialize(); return m_buffer.size(); }
45 
46  uint8 getU8();
47  uint16 getU16();
48  uint32 getU32();
49  uint64 getU64();
50  std::string getString(uint16 len = 0);
51  Point getPoint();
52 
54  bool canRead() { unserialize(); return m_pos < m_buffer.size(); }
55 
56 private:
57  void unserialize();
58  void skipNodes();
59 
60  FileStreamPtr m_fin;
61  DataBuffer<uint8> m_buffer;
62  uint m_pos;
63  uint m_startPos;
64 };
65 
67 {
68 public:
69  OutputBinaryTree(const FileStreamPtr& finish);
70 
71  void addU8(uint8 v);
72  void addU16(uint16 v);
73  void addU32(uint32 v);
74  void addString(const std::string& v);
75  void addPos(uint16 x, uint16 y, uint8 z);
76  void addPoint(const Point& point);
77 
78  void startNode(uint8 node);
79  void endNode();
80 
81 private:
82  FileStreamPtr m_fin;
83 
84 protected:
85  void write(const uint8* data, size_t size);
86 };
87 
88 #endif
89 
BinaryTree::getU16
uint16 getU16()
Definition: binarytree.cpp:130
databuffer.h
BinaryTree::getChildren
BinaryTreeVec getChildren()
Definition: binarytree.cpp:82
z
gc sort z
Definition: CMakeLists.txt:176
BinaryTree::size
uint size()
Definition: binarytree.h:44
OutputBinaryTree::write
void write(const uint8 *data, size_t size)
Definition: binarytree.cpp:240
uint32
uint32_t uint32
Definition: types.h:35
BinaryTree::getU32
uint32 getU32()
Definition: binarytree.cpp:140
DataBuffer< uint8 >
BinaryTree::skip
void skip(uint len)
Definition: binarytree.cpp:114
DataBuffer::size
uint size() const
Definition: databuffer.h:47
OutputBinaryTree::addString
void addString(const std::string &v)
Definition: binarytree.cpp:207
BinaryTree::canRead
bool canRead()
Definition: binarytree.h:54
BinaryTree::getString
std::string getString(uint16 len=0)
Definition: binarytree.cpp:160
uint16
uint16_t uint16
Definition: types.h:36
BinaryTree::BinaryTree
BinaryTree(const FileStreamPtr &fin)
Definition: binarytree.cpp:26
BinaryTree::getPoint
Point getPoint()
Definition: binarytree.cpp:174
OutputBinaryTree::OutputBinaryTree
OutputBinaryTree(const FileStreamPtr &finish)
Definition: binarytree.cpp:182
BinaryTree
Definition: binarytree.h:35
declarations.h
uint
unsigned int uint
Definition: types.h:31
BinaryTree::seek
void seek(uint pos)
Definition: binarytree.cpp:106
OutputBinaryTree::addPoint
void addPoint(const Point &point)
Definition: binarytree.cpp:223
OutputBinaryTree::addU32
void addU32(uint32 v)
Definition: binarytree.cpp:200
BINARYTREE_NODE_END
@ BINARYTREE_NODE_END
Definition: binarytree.h:32
BinaryTree::getU64
uint64 getU64()
Definition: binarytree.cpp:150
uint64
uint64_t uint64
Definition: types.h:34
OutputBinaryTree
Definition: binarytree.h:66
OutputBinaryTree::addU16
void addU16(uint16 v)
Definition: binarytree.cpp:193
BinaryTree::getU8
uint8 getU8()
Definition: binarytree.cpp:120
BINARYTREE_NODE_START
@ BINARYTREE_NODE_START
Definition: binarytree.h:31
stdext::shared_object_ptr< FileStream >
OutputBinaryTree::addPos
void addPos(uint16 x, uint16 y, uint8 z)
Definition: binarytree.cpp:216
BinaryTreeVec
std::vector< BinaryTreePtr > BinaryTreeVec
Definition: declarations.h:47
BinaryTree::~BinaryTree
~BinaryTree()
Definition: binarytree.cpp:32
BINARYTREE_ESCAPE_CHAR
@ BINARYTREE_ESCAPE_CHAR
Definition: binarytree.h:30
OutputBinaryTree::endNode
void endNode()
Definition: binarytree.cpp:235
TPoint< int >
OutputBinaryTree::startNode
void startNode(uint8 node)
Definition: binarytree.cpp:229
stdext::shared_object
Definition: shared_object.h:41
uint8
uint8_t uint8
Definition: types.h:37
BinaryTree::tell
uint tell()
Definition: binarytree.h:43
OutputBinaryTree::addU8
void addU8(uint8 v)
Definition: binarytree.cpp:188