cgv
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 
9 namespace cgv {
10  namespace data {
11 
13  enum NamingConvention { NC_NONE, NC_SHORT, NC_LONG };
14  }
15 }
16 
17 namespace cgv {
18  namespace reflect {
19  extern CGV_API enum_reflection_traits<cgv::data::NamingConvention> get_reflection_traits(const cgv::data::NamingConvention&);
20  }
21 }
22 
23 namespace cgv {
24  namespace data {
25 
26 
29 {
30 public:
31 protected:
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);
38 public:
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 
51 {
52 protected:
53  std::ifstream file_is;
54  std::istream& is;
55 
56  bool read_reflect_header(const std::string& _content, unsigned _ver);
57 public:
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 
74 {
75 protected:
76  std::ofstream file_os;
77  std::ostream& os;
78 public:
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>
cgv::reflect::abst_reflection_traits
abstract interface for type reflection with basic type management and optional string conversion
Definition: reflection_traits.h:24
cgv::data::io_reflection_handler
Definition: io_reflection_handler.h:19
cgv::reflect::reflection_handler::GroupKind
GroupKind
different support group types
Definition: reflection_handler.h:85
cgv::data::NamingConvention
NamingConvention
different naming conventions for member names
Definition: ascii_io_reflection_handlers.h:13
cgv::data::ascii_write_reflection_handler
Definition: ascii_io_reflection_handlers.h:74
cgv::data::ascii_reflection_handler
Definition: ascii_io_reflection_handlers.h:29
cgv::math::reflect
vec< T > reflect(const vec< T > &v, const vec< T > &n)
calculates the reflected direction of v; n is the normal of the reflecting surface
Definition: vec.h:822
cgv::data::ascii_read_reflection_handler
Definition: ascii_io_reflection_handlers.h:51
cgv
the cgv namespace
Definition: vr_calib.cxx:9