2626#include < set>
2727#include < stdexcept>
2828
29+ #include " traits.h"
2930#include " util.h"
3031#include " xreader.h"
3132
5455#include " go_writer.h"
5556#endif
5657
57- #include " traits.h"
5858
5959// #include <iostream>
6060// using namespace std;
@@ -163,6 +163,8 @@ class X {
163163};
164164
165165} // namespace
166+ #else
167+ #include " traits.h"
166168#endif // XTOSTRUCT_MACRO_TEST
167169
168170#define X_STRUCT_FUNC_COMMON \
@@ -174,13 +176,24 @@ public: \
174176 return __x_has_string.find (name)!=__x_has_string.end (); \
175177 }
176178
179+ #ifndef X_SUPPORT_C0X
177180#define X_STRUCT_FUNC_TOX_BEGIN \
178181 template <typename DOC> \
179182 void __x_to_struct (DOC& obj) {
183+ #else
184+ #define X_STRUCT_FUNC_TOX_BEGIN \
185+ template <typename DOC> \
186+ void __x_to_struct (DOC& obj) { auto X_SELF = this ;
187+
188+ #define X_STRUCT_FUNC_TOX_BEGIN_OUT (NAME ) \
189+ template <typename DOC> \
190+ void x_str_to_struct (DOC& obj, NAME& __xval__) { x2struct::x_fake_set __x_has_string; auto X_SELF = &__xval__;
191+
192+ #endif
180193
181194// optional
182195#define X_STRUCT_ACT_TOX_O (M ) \
183- if (obj.convert (#M, M) && obj.set_has ()) { \
196+ if (obj.convert (#M, X_SELF-> M ) && obj.set_has ()) { \
184197 __x_has_string.insert (#M); \
185198 }
186199
@@ -192,13 +205,13 @@ public: \
192205 if (obj.set_has ()) { \
193206 __x_has_string.insert (#M); \
194207 } \
195- M = __tmp; \
208+ X_SELF-> M = __tmp; \
196209 } \
197210 }
198211
199212// mandatory
200213#define X_STRUCT_ACT_TOX_M (M ) \
201- if (obj.convert (#M, M)) { \
214+ if (obj.convert (#M, X_SELF-> M )) { \
202215 if (obj.set_has ()) __x_has_string.insert (#M); \
203216 } else { \
204217 obj.md_exception (#M); \
@@ -210,9 +223,9 @@ public: \
210223 bool md = false ; \
211224 std::string __alias__name__ = obj.hasa (#M, A_NAME, &md); \
212225 const char *__an = __alias__name__.c_str (); \
213- if (obj.convert (__an, M)) { \
226+ if (obj.convert (__an, X_SELF-> M )) { \
214227 if (obj.set_has ()) __x_has_string.insert (#M); \
215- } else if (obj.convert (#M, M)) { \
228+ } else if (obj.convert (#M, X_SELF-> M )) { \
216229 if (obj.set_has ()) __x_has_string.insert (#M); \
217230 } else if (md) { \
218231 obj.md_exception (__an); \
@@ -229,15 +242,26 @@ public: \
229242
230243
231244// struct to string
245+ #ifndef X_SUPPORT_C0X
232246#define X_STRUCT_FUNC_TOS_BEGIN \
233247 template <class CLASS > \
234248 void __struct_to_str (CLASS& obj, const char *root) const { (void )root;
249+ #else
250+ #define X_STRUCT_FUNC_TOS_BEGIN \
251+ template <class CLASS > \
252+ void __struct_to_str (CLASS& obj, const char *root) const { (void )root;auto X_SELF = this ;
253+
254+ #define X_STRUCT_FUNC_TOS_BEGIN_OUT (NAME ) \
255+ template <class CLASS > \
256+ void x_struct_to_str (CLASS& obj, const char *root, const NAME&__xval__) { (void )root;auto X_SELF = &__xval__;
257+
258+ #endif
235259
236260#define X_STRUCT_ACT_TOS_O (M ) \
237- obj.convert (#M, M);
261+ obj.convert (#M, X_SELF-> M );
238262
239263#define X_STRUCT_ACT_TOS_A (M, A_NAME ) \
240- obj.convert (x2struct::Util::alias_parse (#M, A_NAME, obj.type (), 0 ).c_str (), M);
264+ obj.convert (x2struct::Util::alias_parse (#M, A_NAME, obj.type (), 0 ).c_str (), X_SELF-> M );
241265
242266// Inheritance
243267#define X_STRUCT_ACT_TOS_I (B ) B::__struct_to_str(obj, root);
@@ -482,6 +506,11 @@ public: \
482506 X_STRUCT_FUNC_TOS_BEGIN X_STRUCT_N (X_STRUCT_L1, X_STRUCT_L1_TOS, __VA_ARGS__) X_STRUCT_FUNC_TOS_END
483507#endif
484508
509+ // for class/struct that could not modify(could not add XTOSTUCT macro)
510+ #define XTOSTRUCT_OUT (NAME, ...) \
511+ X_STRUCT_FUNC_TOX_BEGIN_OUT (NAME) X_STRUCT_N (X_STRUCT_L1, X_STRUCT_L1_TOX, __VA_ARGS__) X_STRUCT_FUNC_TOX_END \
512+ X_STRUCT_FUNC_TOS_BEGIN_OUT (NAME) X_STRUCT_N (X_STRUCT_L1, X_STRUCT_L1_TOS, __VA_ARGS__) X_STRUCT_FUNC_TOS_END
513+
485514// ///////////////////////////////////////////////////////////////////
486515// for local class, gen code without template (no template) BEGIN
487516// ///////////////////////////////////////////////////////////////////
0 commit comments