liblcf
Toggle main menu visibility
Loading...
Searching...
No Matches
lmt_rect.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of liblcf. Copyright (c) liblcf authors.
3
* https://github.com/EasyRPG/liblcf - https://easyrpg.org
4
*
5
* liblcf is Free/Libre Open Source Software, released under the MIT License.
6
* For the full copyright and license information, please view the COPYING
7
* file that was distributed with this source code.
8
*/
9
10
#include "lcf/lmt/reader.h"
11
#include "lcf/lmt/chunks.h"
12
#include "
reader_struct.h
"
13
14
namespace
lcf
{
15
16
template
<>
17
struct
RawStruct
<
rpg
::Rect> {
18
static
void
ReadLcf
(rpg::Rect& ref, LcfReader& stream, uint32_t length);
19
static
void
WriteLcf
(
const
rpg::Rect& ref, LcfWriter& stream);
20
static
int
LcfSize
(
const
rpg::Rect& ref, LcfWriter& stream);
21
static
void
WriteXml
(
const
rpg::Rect& ref, XmlWriter& stream);
22
static
void
BeginXml
(rpg::Rect& ref, XmlReader& stream);
23
};
24
28
void
RawStruct<rpg::Rect>::ReadLcf
(rpg::Rect& ref, LcfReader& stream, uint32_t length) {
29
assert(length == 16);
30
(void)length;
31
stream.Read(ref.l);
32
stream.Read(ref.t);
33
stream.Read(ref.r);
34
stream.Read(ref.b);
35
}
36
37
void
RawStruct<rpg::Rect>::WriteLcf
(
const
rpg::Rect& ref, LcfWriter& stream) {
38
stream.Write(ref.l);
39
stream.Write(ref.t);
40
stream.Write(ref.r);
41
stream.Write(ref.b);
42
}
43
44
int
RawStruct<rpg::Rect>::LcfSize
(
const
rpg::Rect&
/* ref */
, LcfWriter&
/* stream */
) {
45
return
4 * 4;
46
}
47
48
void
RawStruct<rpg::Rect>::WriteXml
(
const
rpg::Rect& ref, XmlWriter& stream) {
49
stream.BeginElement(
"Rect"
);
50
stream.WriteNode<int32_t>(
"l"
, ref.l);
51
stream.WriteNode<int32_t>(
"t"
, ref.t);
52
stream.WriteNode<int32_t>(
"r"
, ref.r);
53
stream.WriteNode<int32_t>(
"b"
, ref.b);
54
stream.EndElement(
"Rect"
);
55
}
56
57
class
RectXmlHandler
:
public
XmlHandler {
58
private
:
59
rpg::Rect&
ref
;
60
uint32_t*
field
;
61
public
:
62
RectXmlHandler
(rpg::Rect&
ref
) :
ref
(
ref
),
field
(NULL) {}
63
void
StartElement
(XmlReader&
/* stream */
,
const
char
*
name
,
const
char
**
/* atts */
) {
64
if
(strcmp(
name
,
"l"
) == 0)
65
field
= &
ref
.l;
66
else
if
(strcmp(
name
,
"t"
) == 0)
67
field
= &
ref
.t;
68
else
if
(strcmp(
name
,
"r"
) == 0)
69
field
= &
ref
.r;
70
else
if
(strcmp(
name
,
"b"
) == 0)
71
field
= &
ref
.b;
72
else
{
73
Log::Error
(
"XML: Unrecognized field '%s'"
,
name
);
74
field
= NULL;
75
}
76
}
77
void
EndElement
(XmlReader&
/* stream */
,
const
char
*
/* name */
) {
78
field
= NULL;
79
}
80
void
CharacterData
(XmlReader&
/* stream */
,
const
std::string& data) {
81
if
(
field
!= NULL)
82
XmlReader::Read(*
field
, data);
83
}
84
};
85
86
void
RawStruct<rpg::Rect>::BeginXml
(rpg::Rect& ref, XmlReader& stream) {
87
stream.SetHandler(
new
WrapperXmlHandler
(
"Rect"
,
new
RectXmlHandler
(ref)));
88
}
89
90
}
//namespace lcf
lcf::RectXmlHandler
Definition
lmt_rect.cpp:57
lcf::RectXmlHandler::ref
rpg::Rect & ref
Definition
lmt_rect.cpp:59
lcf::RectXmlHandler::CharacterData
void CharacterData(XmlReader &, const std::string &data)
Definition
lmt_rect.cpp:80
lcf::RectXmlHandler::field
uint32_t * field
Definition
lmt_rect.cpp:60
lcf::RectXmlHandler::RectXmlHandler
RectXmlHandler(rpg::Rect &ref)
Definition
lmt_rect.cpp:62
lcf::RectXmlHandler::StartElement
void StartElement(XmlReader &, const char *name, const char **)
Definition
lmt_rect.cpp:63
lcf::RectXmlHandler::EndElement
void EndElement(XmlReader &, const char *)
Definition
lmt_rect.cpp:77
lcf::WrapperXmlHandler
Definition
reader_struct.h:755
lcf::Log::Error
void Error(const char *fmt,...) LIKE_PRINTF
Definition
log_handler.cpp:90
lcf::rpg
Definition
rpg_actor.cpp:16
lcf
Definition
dbarray.cpp:13
lcf::name
const char *const Struct< rpg::Actor >::name
Definition
fwd_struct_impl.h:16
reader_struct.h
lcf::RawStruct
Definition
reader_struct.h:117
lcf::RawStruct::WriteXml
static void WriteXml(const T &ref, XmlWriter &stream)
lcf::RawStruct::BeginXml
static void BeginXml(T &ref, XmlReader &stream)
lcf::RawStruct::ReadLcf
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
lcf::RawStruct::WriteLcf
static void WriteLcf(const T &ref, LcfWriter &stream)
lcf::RawStruct::LcfSize
static int LcfSize(const T &ref, LcfWriter &stream)
src
lmt_rect.cpp
Generated on
for liblcf by
1.17.0