acl  3.5.3.0
gsoner.hpp
浏览该文件的文档.
1 /**
2  * Copyright (C) 2015-2018
3  * All rights reserved.
4  *
5  * AUTHOR(S)
6  * E-mail: niukey@qq.com
7  *
8  * VERSION
9  * Sat 08 Oct 2016 09:07:14 PM CST
10  */
11 
12 #pragma once
13 #include "../acl_cpp_define.hpp"
14 #include <list>
15 #include <map>
16 #include <vector>
17 #include <string>
18 
19 #ifndef ACL_CLIENT_ONLY
20 
21 namespace acl
22 {
23 
25 {
26 public:
27  gsoner ();
28  bool read_file(const char *filepath);
29  bool read_multi_file(const std::vector<std::string>& files);
30  void parse_code();
31  void gen_gson();
32  void set_default_required();
33  void set_default_optional();
34  void set_header_filename(const std::string &filename);
35  void set_source_filename(const std::string &filename);
36 
37 private:
38  enum code_parser_status_t
39  {
40  e_uninit,
41  e_comment,
42  e_struct_begin,
43  e_struct_end,
44  };
45 
46  struct field_t
47  {
48  enum type_t
49  {
50  e_bool,
51  e_bool_ptr,
52  e_number,
53  e_double,
54  e_cstr, //char *
55  e_ccstr, //const char *
56  e_string,
57  e_list,
58  e_vector,
59  e_map,
60  e_set,
61  e_object,
62  };
63 
64  type_t type_;
65  std::string name_;
66  bool required_;
67 
68  field_t();
69  field_t(type_t t, const std::string &name,bool required);
70 
71  virtual ~field_t();
72  };
73 
74  struct parent_obj_t
75  {
76  enum level_t
77  {
78  e_error = 0,
79  e_public,
80  e_protect,
81  e_private,
82  };
83  level_t level_;
84  std::string name_;
85  };
86 
87  struct object_t
88  {
89  typedef std::list<field_t> fields_t;
90  fields_t fields_;
91  std::string name_;
92  std::list<parent_obj_t> parent_obj_;
93  void reset ();
94  };
95 
96  struct function_code_t
97  {
98  std::string declare_;
99  std::string declare_ptr_;
100  std::string declare2_;
101  std::string definition_;
102  std::string definition_ptr_;
103  std::string definition2_;
104  };
105 
106  parent_obj_t::level_t get_level(std::string str);
107  std::string get_node_func (const field_t &field);
108  std::string get_gson_func_laber (const field_t &field);
109  function_code_t gen_pack_code (const object_t &obj);
110  std::string get_unpack_code(const std::string &obj_name,
111  const field_t &field)const ;
112  std::string get_node_name(const std::string &name);
113  std::string next_token(std::string delimiters);
114  std::string get_namespace();
115  function_code_t gen_unpack_code(const object_t &obj);
116  std::string get_static_string(const std::string &str, int &index);
117  std::string get_include_files();
118  std::string get_filename(const char *filepath);
119 
120  bool skip_space_comment();
121 
122  bool check_use_namespace();
123  bool check_namespace();
124  bool check_namespace_end();
125  bool check_struct_begin ();
126  bool check_struct_end ();
127  bool check_include();
128  bool check_comment ();
129  bool check_function();
130  bool check_member();
131  bool skip_space ();
132  std::pair<bool, std::string> get_function_declare();
133 
134  std::string add_4space(const std::string &code);
135  void flush();
136  void write_header(const std::string &data);
137  void write_source(const std::string &data);
138 
139  bool check_define();
140  bool check_pragma();
141  std::list<std::string> get_initializelist ();
142  //char cc;
143  int pos_;
144  int max_pos_;
145  std::string comment_begin_;
146  std::string comment_end_;
147  std::string codes_;
148  code_parser_status_t status_;
149  std::string tab_ ;
150  bool required_;
151  bool skip_;
152  bool default_;
153  std::string newname_;
154  object_t current_obj_;
155  std::map<std::string,object_t> objs_;
156  std::list<std::string> namespaces_;
157  std::list<std::string> includes_;
158  std::list<std::string> files_;
159  std::ofstream *gen_header_;
160  std::ofstream *gen_source_;
161  std::string gen_header_filename_;
162  std::string gen_source_filename_;
163  std::string default_delimiters_;
164 };
165 
166 }//end of acl
167 
168 #endif // ACL_CLIENT_ONLY
HTTP_API void const char * name
Definition: lib_http.h:620
#define ACL_CPP_API