1#include "binary_io_reflection_handlers.h"
9bool binary_reflection_handler::reflect_header()
24binary_reflection_handler::binary_reflection_handler(
const std::string& _content,
unsigned _ver) :
io_reflection_handler(_content, _ver)
29void binary_reflection_handler::close()
34bool binary_read_reflection_handler::read_reflect_header(
const std::string& _content,
unsigned _ver)
39 if (_content != file_content)
40 last_error = RE_CONTENT_MISMATCH;
41 else if (_ver != version)
42 last_error = RE_VERSION_MISMATCH;
47binary_read_reflection_handler::binary_read_reflection_handler(
const std::string& file_name,
const std::string& _content,
unsigned _ver) :
48 binary_reflection_handler(_content, _ver)
50 fp = fopen(file_name.c_str(),
"rb");
52 last_error = RE_FILE_OPEN_ERROR;
54 read_reflect_header(_content, _ver);
58binary_read_reflection_handler::binary_read_reflection_handler(FILE* _fp,
const std::string& _content,
unsigned _ver) :
59 binary_reflection_handler(_content, _ver)
62 read_reflect_header(_content, _ver);
71 std::string& str = *((std::string*)member_ptr);
74 last_error = RE_FILE_READ_ERROR;
78 if (fread(&str[0],
sizeof(
char), s, fp) != s) {
79 last_error = RE_FILE_READ_ERROR;
86 std::wstring& str = *((std::wstring*)member_ptr);
89 last_error = RE_FILE_READ_ERROR;
94 last_error = RE_FILE_READ_ERROR;
100 if (fread(member_ptr, rt->
size(), 1, fp) != 1) {
101 last_error = RE_FILE_READ_ERROR;
112 fp = fopen(file_name.c_str(),
"wb");
114 last_error = RE_FILE_OPEN_ERROR;
133 const std::string& str = *((std::string*)member_ptr);
136 last_error = RE_FILE_WRITE_ERROR;
139 if (fwrite(&str[0],
sizeof(
char), s, fp) != s) {
140 last_error = RE_FILE_WRITE_ERROR;
147 const std::wstring& str = *((std::wstring*)member_ptr);
150 last_error = RE_FILE_WRITE_ERROR;
154 last_error = RE_FILE_WRITE_ERROR;
160 if (fwrite(member_ptr, rt->
size(), 1, fp) != 1) {
161 last_error = RE_FILE_WRITE_ERROR;
bool reflect_member_void(const std::string &member_name, void *member_ptr, cgv::reflect::abst_reflection_traits *rt)
abstract interface to reflect a member variable, where the member type is specified as a string.
bool is_creative() const
this should return true
reflect to and from binary file
binary_write_reflection_handler(const std::string &file_name, const std::string &_content, unsigned _ver)
construct from file_name by opening file in ascii mode
bool reflect_member_void(const std::string &member_name, void *member_ptr, cgv::reflect::abst_reflection_traits *rt)
abstract interface to reflect a member variable, where the member type is specified as a string.
common base for all io reflection handlers
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
in this namespace reflection of types is implemented
@ TI_STRING
wide character type
wchar_t wchar_type
wide character type
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
abstract interface for type reflection with basic type management and optional string conversion
virtual unsigned size() const =0
return the size of the type
virtual cgv::type::info::TypeId get_type_id() const =0
return the type id