#ifndef VCZH_STREAM_CHARFORMAT
#define VCZH_STREAM_CHARFORMAT
#include "Interfaces.h"
#include "MemoryStream.h"
#include "MemoryWrapperStream.h"
namespace
{
namespace
{
class
:
public
,
public
{
protected
:
*
;
[
sizeof
(
wchar_t
)];
;
virtual
(
wchar_t
*
,
)=
0
;
public
:
();
void
(
*
);
void
();
(
void
*
,
);
};
class
:
public
,
public
{
protected
:
*
;
[
sizeof
(
wchar_t
)];
;
virtual
(
wchar_t
*
,
)=
0
;
public
:
();
void
(
*
);
void
();
(
void
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
(
wchar_t
*
,
);
};
class
:
public
{
protected
:
#if defined VCZH_MSVC
wchar_t
;
bool
;
#endif
(
wchar_t
*
,
);
public
:
();
};
class
:
public
,
public
{
public
:
enum
{
,
,
,
};
protected
:
;
*
;
public
:
(
);
();
void
(
*
);
void
();
(
void
*
,
);
};
class
:
public
,
public
{
private
:
class
:
public
,
public
{
protected
:
*
;
char
[
3
];
;
;
public
:
(
*
,
char
*
,
);
bool
()
const
;
bool
()
const
;
bool
()
const
;
bool
()
const
;
bool
()
const
;
bool
()
const
;
void
();
()
const
;
()
const
;
void
(
);
void
(
);
void
(
);
(
void
*
,
);
(
void
*
,
);
(
void
*
,
);
};
protected
:
*
;
*
;
public
:
();
();
void
(
*
);
void
();
(
void
*
,
);
};
extern
void
(
unsigned
char
*
,
,
::
&
,
bool
&
);
namespace
{
template
<
typename
>
struct
{
stream
::
&
;
;
(
stream
::
&
)
:input(
)
, context(
nullptr
)
{
}
};
template
<
typename
>
struct
{
stream
::
&
;
;
(
stream
::
&
)
:output(
)
, context(
nullptr
)
{
}
};
using
=
<
void
*>;
using
=
<
void
*>;
template
<
typename
>
struct
{
template
<
typename
>
static
void
(
&
,
&
);
};
template
<
typename
,
typename
>
<
>&
(
<
>&
,
&
)
{
<
>::
(
,
);
return
;
}
template
<
typename
,
typename
>
<
>&
(
<
>&
,
&
)
{
<
>::
(
,
);
return
;
}
template
<>
struct
<
>
{
template
<
typename
>
static
void
(
<
>&
,
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
}
template
<
typename
>
static
void
(
<
>&
,
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
}
};
template
<>
struct
<
>
{
template
<
typename
>
static
void
(
<
>&
,
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
}
template
<
typename
>
static
void
(
<
>&
,
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
}
};
template
<>
struct
<
>
{
template
<
typename
>
static
void
(
<
>&
,
&
)
{
=
0
;
<
>::
(
,
v
);
= (
)
v
;
}
template
<
typename
>
static
void
(
<
>&
,
&
)
{
= (
)
;
<
>::
(
,
v
);
}
};
template
<>
struct
<
>
{
template
<
typename
>
static
void
(
<
>&
,
&
)
{
=
0
;
<
>::
(
,
v
);
= (
)
v
;
}
template
<
typename
>
static
void
(
<
>&
,
&
)
{
= (
)
;
<
>::
(
,
v
);
}
};
template
<>
struct
<
double
>
{
template
<
typename
>
static
void
(
<
>&
,
double
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
}
template
<
typename
>
static
void
(
<
>&
,
double
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
}
};
template
<>
struct
<
float
>
{
template
<
typename
>
static
void
(
<
>&
,
float
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
}
template
<
typename
>
static
void
(
<
>&
,
float
&
)
{
if
(
.
.
(&
,
sizeof
(
)) !=
sizeof
(
))
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
}
};
template
<>
struct
<
bool
>
{
template
<
typename
>
static
void
(
<
>&
,
bool
&
)
{
=
0
;
if
(
.
.
(&
v
,
sizeof
(
v
)) !=
sizeof
(
v
))
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
else
{
=
v
== -
1
;
}
}
template
<
typename
>
static
void
(
<
>&
,
bool
&
)
{
=
? -
1
:
0
;
if
(
.
.
(&
v
,
sizeof
(
v
)) !=
sizeof
(
v
))
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
}
};
template
<
typename
>
struct
<
<
>>
{
template
<
typename
>
static
void
(
<
>&
,
<
>&
)
{
bool
=
false
;
notNull
;
if
(
notNull
)
{
new
;
<
>::
(
, *
.
());
}
else
{
0
;
}
}
template
<
typename
>
static
void
(
<
>&
,
<
>&
)
{
bool
=
;
notNull
;
if
(
notNull
)
{
<
>::
(
, *
.
());
}
}
};
template
<
typename
>
struct
<
<
>>
{
template
<
typename
>
static
void
(
<
>&
,
<
>&
)
{
bool
=
false
;
notNull
;
if
(
notNull
)
{
;
<
>::
(
,
data
);
<
>(
data
);
}
else
{
<
>();
}
}
template
<
typename
>
static
void
(
<
>&
,
<
>&
)
{
bool
=
;
notNull
;
if
(
notNull
)
{
=
.
();
<
>::
(
,
data
);
}
}
};
template
<>
struct
<
>
{
template
<
typename
>
static
void
(
<
>&
,
&
)
{
= -
1
;
count
;
if
(
count
>
0
)
{
;
(
&)
stream
;
;
decoder
.
(&
stream
);
collections
::
<
wchar_t
>
(
count
+
1
);
=
decoder
.
(&
stringBuffer
0
],
count
*
sizeof
(
wchar_t
));
stringBuffer
stringSize
/
sizeof
(
wchar_t
)] =
0
;
= &
stringBuffer
0
];
}
else
{
=
L""
;
}
}
template
<
typename
>
static
void
(
<
>&
,
&
)
{
=
.
();
count
;
if
(
count
>
0
)
{
;
{
;
encoder
.
(&
stream
);
encoder
.
((
void
*)
.
(),
count
*
sizeof
(
wchar_t
));
}
(
&)
stream
;
}
}
};
template
<
typename
>
struct
<
collections
::
<
>>
{
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
>&
)
{
= -
1
;
count
;
.
();
for
(
=
0
;
i
<
count
;
i
++)
{
;
<<
t
;
.
(
t
);
}
}
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
>&
)
{
= (
)
.
();
count
;
for
(
=
0
;
i
<
count
;
i
++)
{
<<
i
];
}
}
};
template
<
typename
>
struct
<
collections
::
<
>>
{
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
>&
)
{
= -
1
;
count
;
.
(
count
);
for
(
=
0
;
i
<
count
;
i
++)
{
<<
i
];
}
}
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
>&
)
{
= (
)
.
();
count
;
for
(
=
0
;
i
<
count
;
i
++)
{
<<
i
];
}
}
};
template
<
typename
,
typename
>
struct
<
collections
::
<
,
>>
{
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
,
>&
)
{
= -
1
;
count
;
.
();
for
(
=
0
;
i
<
count
;
i
++)
{
;
;
<<
k
<<
v
;
.
(
k
,
v
);
}
}
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
,
>&
)
{
= (
)
.
();
count
;
for
(
=
0
;
i
<
count
;
i
++)
{
=
.
()
i
];
=
.
()
i
];
<<
k
<<
v
;
}
}
};
template
<
typename
,
typename
>
struct
<
collections
::
<
,
>>
{
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
,
>&
)
{
= -
1
;
count
;
.
();
for
(
=
0
;
i
<
count
;
i
++)
{
;
collections
::
<
>
;
<<
k
<<
v
;
for
(
=
0
;
j
<
v
.
();
j
++)
{
.
(
k
,
v
j
]);
}
}
}
template
<
typename
>
static
void
(
<
>&
,
collections
::
<
,
>&
)
{
= (
)
.
();
count
;
for
(
=
0
;
i
<
count
;
i
++)
{
=
.
()
i
];
collections
::
<
>&
=
const_cast
<
collections
::
<
>&>(
.
(
i
));
<<
k
<<
v
;
}
}
};
template
<>
struct
<
stream
::
>
{
template
<
typename
>
static
void
(
<
>&
,
stream
::
&
)
{
=
0
;
.
.
(&
count
,
sizeof
(
count
));
if
(
count
>
0
)
{
=
0
;
collections
::
<
>
(
count
);
.
(
0
);
length
=
.
.
(&
buffer
0
],
count
);
if
(
length
!=
count
)
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
length
=
.
(&
buffer
0
],
count
);
if
(
length
!=
count
)
{
CHECK_FAIL(L"Deserialization failed.");
do
{
throw
(
L"Deserialization failed."
);}
while
(
0
);
}
.
(
0
);
}
}
template
<
typename
>
static
void
(
<
>&
,
stream
::
&
)
{
= (
)
.
();
.
.
(&
count
,
sizeof
(
count
));
if
(
count
>
0
)
{
=
0
;
collections
::
<
>
(
count
);
.
(
0
);
length
=
.
(&
buffer
0
],
count
);
if
(
length
!=
count
)
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
length
=
.
.
(&
buffer
0
],
count
);
if
(
length
!=
count
)
{
CHECK_FAIL(L"Serialization failed.");
do
{
throw
(
L"Serialization failed."
);}
while
(
0
);
}
.
(
0
);
}
}
};
#define BEGIN_SERIALIZATION(TYPE)\
template<>\
struct Serialization<TYPE>\
{\
template<typename TIO>\
static void IO(TIO& op, TYPE& value)\
{\
op\
#define SERIALIZE(FIELD)\
<< value.FIELD\
#define END_SERIALIZATION\
;\
}\
};\
#define SERIALIZE_ENUM(TYPE)\
template<>\
struct Serialization<TYPE>\
{\
template<typename TContext>\
static void IO(Reader<TContext>& reader, TYPE& value)\
{\
vint32_t v = 0;\
Serialization<vint32_t>::IO(reader, v);\
value = (TYPE)v;\
}\
template<typename TContext>\
static void IO(Writer<TContext>& writer, TYPE& value)\
{\
vint32_t v = (vint32_t)value;\
Serialization<vint32_t>::IO(writer, v);\
}\
};\
}
}
}
#endif