cgv
Loading...
Searching...
No Matches
ascii_io_reflection_handlers.h
1#pragma once
2
3#include <iostream>
4#include <fstream>
5#include "io_reflection_handler.h"
6
7#include "lib_begin.h"
8
9namespace cgv {
10 namespace data {
11
13 enum NamingConvention { NC_NONE, NC_SHORT, NC_LONG };
14 }
15}
16
17namespace cgv {
18 namespace reflect {
20 }
21}
22
23namespace cgv {
24 namespace data {
25
26
28class CGV_API ascii_reflection_handler : public io_reflection_handler
29{
30public:
31protected:
32 unsigned nr_idents;
33
34 NamingConvention naming_convention;
35 unsigned tab_size;
36
37 std::string extend_name(const std::string& name, bool assign = true);
38public:
40 bool reflect_header();
42 ascii_reflection_handler(const std::string& _content, unsigned _ver, unsigned _tab = 3);
44 int reflect_group_begin(GroupKind group_kind, const std::string& group_name, void* group_ptr, cgv::reflect::abst_reflection_traits* rt, unsigned grp_size);
46 void reflect_group_end(GroupKind group_kind);
47};
48
50class CGV_API ascii_read_reflection_handler : public ascii_reflection_handler
51{
52protected:
53 std::ifstream file_is;
54 std::istream& is;
55
56 bool read_reflect_header(const std::string& _content, unsigned _ver);
57public:
58 ascii_read_reflection_handler(const std::string& file_name, const std::string& _content, unsigned _ver, NamingConvention _nc = NC_SHORT, unsigned _tab = 3);
60 ascii_read_reflection_handler(std::istream& _is, const std::string& _content, unsigned _ver, NamingConvention _nc = NC_SHORT, unsigned _tab = 3);
62 bool is_creative() const;
64 void close();
65 int reflect_group_begin(GroupKind group_kind, const std::string& group_name, void* group_ptr, cgv::reflect::abst_reflection_traits* rt, unsigned grp_size);
67 bool reflect_member_void(const std::string& member_name,
68 void* member_ptr, cgv::reflect::abst_reflection_traits* rt);
69};
70
71
73class CGV_API ascii_write_reflection_handler : public ascii_reflection_handler
74{
75protected:
76 std::ofstream file_os;
77 std::ostream& os;
78public:
80 ascii_write_reflection_handler(const std::string& file_name, const std::string& _content, unsigned _ver, NamingConvention _nc = NC_SHORT, unsigned _tab = 3);
82 ascii_write_reflection_handler(std::ostream& _os, const std::string& _content, unsigned _ver, NamingConvention _nc = NC_SHORT, unsigned _tab = 3);
84 bool failed() const;
86 void close();
88 int reflect_group_begin(GroupKind group_kind, const std::string& group_name, void* group_ptr, cgv::reflect::abst_reflection_traits* rt, unsigned grp_size);
90 bool reflect_member_void(const std::string& member_name,
91 void* member_ptr, cgv::reflect::abst_reflection_traits* rt);
92};
93
94
95 }
96}
97
98#include <cgv/config/lib_end.h>
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.
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
GroupKind
different support group types
namespace for data management components
NamingConvention
different naming conventions for member names
in this namespace reflection of types is implemented
this header is dependency free
Definition print.h:11
abstract interface for type reflection with basic type management and optional string conversion
this type specific reflection traits class is used by the reflect_enum function to reflect enum types