1#include "ascii_io_reflection_handlers.h"
18std::string ascii_reflection_handler::extend_name(
const std::string& name,
bool assign)
43 size_t p = res.find_last_of(
".");
44 if (p != std::string::npos) {
45 res = res.substr(p+1);
46 for (
size_t j=0; j<nr_idents*tab_size; ++j)
47 res = std::string(
" ") + res;
60bool ascii_reflection_handler::reflect_header()
71ascii_reflection_handler::ascii_reflection_handler(
const std::string& _content,
unsigned _ver,
unsigned _tab) : io_reflection_handler(_content, _ver)
86 if (group_kind != reflection_handler::GK_BASE_CLASS)
90bool ascii_read_reflection_handler::read_reflect_header(
const std::string& _content,
unsigned _ver)
95 if (_content != file_content)
96 last_error = RE_CONTENT_MISMATCH;
97 else if (_ver != version)
98 last_error = RE_VERSION_MISMATCH;
103ascii_read_reflection_handler::ascii_read_reflection_handler(
const std::string& file_name,
const std::string& _content,
unsigned _ver,
NamingConvention _nc,
unsigned _tab) :
104 ascii_reflection_handler(_content, _ver, _tab), is(file_is)
106#if defined (WIN32) && !defined(__MINGW32__)
109 file_is.open(file_name.c_str());
112 last_error = RE_FILE_OPEN_ERROR;
114 read_reflect_header(_content, _ver);
118ascii_read_reflection_handler::ascii_read_reflection_handler(std::istream& _is,
const std::string& _content,
unsigned _ver,
NamingConvention _nc,
unsigned _tab) :
119 ascii_reflection_handler(_content, _ver, _tab), is(_is)
121 read_reflect_header(_content, _ver);
124void ascii_read_reflection_handler::close()
132 if (group_kind != reflection_handler::GK_BASE_CLASS) {
134 is.getline(buffer, 10000);
136 last_error = RE_FILE_READ_ERROR;
148 is.getline(buffer, 10000);
150 last_error = RE_FILE_READ_ERROR;
154 std::string val_str(buffer + extend_name(member_name).size()+1);
158 std::string val_str(buffer + extend_name(member_name).size());
167 naming_convention = _nc;
168#if defined(WIN32) && !defined(__MINGW32__)
171 file_os.open(file_name.c_str());
174 last_error = RE_FILE_OPEN_ERROR;
181 naming_convention = _nc;
185bool ascii_write_reflection_handler::failed()
const {
return os.fail(); }
187void ascii_write_reflection_handler::close()
195 if (group_kind != reflection_handler::GK_BASE_CLASS) {
196 os << extend_name(group_name,
false) << std::endl;
198 last_error = RE_FILE_WRITE_ERROR;
209 os << extend_name(member_name);
219 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.
int reflect_group_begin(GroupKind group_kind, const std::string &group_name, void *group_ptr, cgv::reflect::abst_reflection_traits *rt, unsigned grp_size)
abstract interface to start reflection of a group of members.
bool is_creative() const
this should return true
int reflect_group_begin(GroupKind group_kind, const std::string &group_name, void *group_ptr, cgv::reflect::abst_reflection_traits *rt, unsigned grp_size)
abstract interface to start reflection of a group of members.
void reflect_group_end(GroupKind group_kind)
abstract interface to terminate reflection of a group of members
int reflect_group_begin(GroupKind group_kind, const std::string &group_name, void *group_ptr, cgv::reflect::abst_reflection_traits *rt, unsigned grp_size)
abstract interface to start reflection of a group of members.
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.
ascii_write_reflection_handler(const std::string &file_name, const std::string &_content, unsigned _ver, NamingConvention _nc=NC_SHORT, unsigned _tab=3)
construct from file_name by opening file in ascii mode
std::vector< nesting_info > nesting_info_stack
stack of nesting_info used during the reflection process
GroupKind
different support group types
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.
NamingConvention
different naming conventions for member names
in this namespace reflection of types is implemented
@ TI_STRING
wide character type
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
std::string interpret_special(const std::string &s)
interprets the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?,...
std::string escape_special(const std::string &s)
escapes the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?
std::wstring str2wstr(const std::string &s)
convert a 8-bit string to a 16-bit string
Helper functions to process strings.
abstract interface for type reflection with basic type management and optional string conversion
virtual bool has_string_conversions() const
whether type can be converted to string, defaults to false
virtual cgv::type::info::TypeId get_type_id() const =0
return the type id
virtual void get_to_string(const void *instance_ptr, std::string &str_val)
convert given instance into a string value
virtual bool set_from_string(void *instance_ptr, const std::string &str_val)
convert a given string value to the reflected type and store in the instance pointer
this type specific reflection traits class is used by the reflect_enum function to reflect enum types