forked from lthn/blockchain
Implemented auto documentation
This commit is contained in:
parent
e5afb6b0c6
commit
cfb4e481b4
4 changed files with 56 additions and 21 deletions
|
|
@ -40,6 +40,7 @@ typename_t get_documentation_json_struct()
|
|||
return AUTO_VAL_INIT_T(typename_t);
|
||||
}
|
||||
|
||||
|
||||
template<typename request_t, typename response_t>
|
||||
bool auto_doc_t(const std::string& prefix_name, std::string& generate_reference)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ namespace epee
|
|||
#define BEGIN_KV_SERIALIZE_MAP() \
|
||||
public: \
|
||||
template<class t_storage> \
|
||||
bool store(t_storage& st, typename t_storage::hsection hparent_section = nullptr, bool auto_doc_mode = false) const\
|
||||
bool store(t_storage& st, typename t_storage::hsection hparent_section = nullptr) const\
|
||||
{\
|
||||
return serialize_map<true>(*this, st, hparent_section, auto_doc_mode); \
|
||||
return serialize_map<true>(*this, st, hparent_section); \
|
||||
}\
|
||||
template<class t_storage> \
|
||||
bool _load(t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\
|
||||
|
|
@ -62,7 +62,7 @@ public: \
|
|||
}\
|
||||
}\
|
||||
template<bool is_store, class this_type, class t_storage> \
|
||||
static bool serialize_map(this_type& this_ref, t_storage& stg, typename t_storage::hsection hparent_section, bool auto_doc_mode = false) \
|
||||
static bool serialize_map(this_type& this_ref, t_storage& stg, typename t_storage::hsection hparent_section) \
|
||||
{
|
||||
|
||||
#define KV_SERIALIZE_N(varialble, val_name) \
|
||||
|
|
@ -72,22 +72,43 @@ public: \
|
|||
epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name, auto_doc_mode, substitute, description);
|
||||
|
||||
#define KV_SERIALIZE_N_DOC2(varialble, val_name) \
|
||||
{using var_type = decltype(this_ref.varialble); \
|
||||
{ using var_type = decltype(this_ref.varialble); \
|
||||
epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name); \
|
||||
if constexpr (t_storage::use_descriptions::value) \
|
||||
{ \
|
||||
epee::serialization::selector<is_store>::set_descr(this_ref.varialble, stg, hparent_section, val_name); \
|
||||
epee::serialization::selector<is_store>::serialize_and_doc<var_type>(stg, hparent_section, val_name
|
||||
|
||||
/*
|
||||
{using var_type = decltype(this_ref.varialble); \
|
||||
epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name); \
|
||||
if constexpr (t_storage::use_descriptions::value) \
|
||||
{ \
|
||||
epee::serialization::selector<is_store>::set_descr<var_type>(stg, hparent_section, val_name, description, default = var_type()); \
|
||||
} \
|
||||
}
|
||||
|
||||
*/
|
||||
#define DOC_DSCR(description) , description
|
||||
#define DOC_EXMP(substitute) , substitute
|
||||
#define DOC_EXMP_AUTO_1(arg_1) , var_type(arg_1)
|
||||
#define DOC_EXMP_AUTO_2(arg_1, arg_2) , var_type(arg_1, arg_2)
|
||||
#define DOC_END ); } }
|
||||
|
||||
|
||||
|
||||
#define DOC_EXMP_AUTO(...) epee::create_t_object<var_type>(__VA_ARGS__)
|
||||
|
||||
|
||||
// Function template to create an object with forwarded constructor arguments
|
||||
template<typename T, typename... Args>
|
||||
T create_t_object(Args&&... args) {
|
||||
return T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
//substitute, description);
|
||||
#define DOC_EXAMPLE(substitute) substitute,
|
||||
#define DOC_EX(substitute__) var_type(substitute__),
|
||||
#define DOC_DSCR(description) description); }
|
||||
//#define DOC_EXAMPLE(substitute) substitute,
|
||||
//#define DOC_EX(substitute__) var_type(substitute__),
|
||||
|
||||
//#define DOC_COMMAND(command_general_description) static const char* explain_yourseflf = command_general_description;
|
||||
|
||||
|
||||
#define KV_SERIALIZE_CUSTOM_N(varialble, stored_type, from_v_to_stored, from_stored_to_v, val_name) \
|
||||
|
|
|
|||
|
|
@ -317,15 +317,26 @@ namespace epee
|
|||
template<class t_type, class t_storage>
|
||||
static bool serialize(const t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||
{
|
||||
stg.set_entry_description(hparent_section, pname, description);
|
||||
return kv_serialize( (doc_mode ? doc_substitute:d), stg, hparent_section, pname);
|
||||
if constexpr (!t_storage::use_descriptions::value)
|
||||
{
|
||||
return kv_serialize(d, stg, hparent_section, pname);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
//bool doc_mode = false, const t_type& doc_substitute = t_type(), const std::string& description = std::string()
|
||||
//const t_type& doc_substitute = t_type(), const std::string& description = std::string()
|
||||
template<class t_type, class t_storage>
|
||||
static bool set_descr(t_storage& stg, typename t_storage::hsection hparent_section, const char* pname, const std::string& description = std::string(), const t_type& doc_substitute = t_type())
|
||||
static bool serialize_and_doc(t_storage& stg, typename t_storage::hsection hparent_section, const char* pname, const std::string& description = std::string(), const t_type& doc_substitute = t_type())
|
||||
{
|
||||
stg.set_entry_description(hparent_section, pname, description);
|
||||
return kv_serialize((doc_mode ? doc_substitute : d), stg, hparent_section, pname);
|
||||
if constexpr (t_storage::use_descriptions::value)
|
||||
{
|
||||
stg.set_entry_description(hparent_section, pname, description);
|
||||
return kv_serialize(doc_substitute, stg, hparent_section, pname);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
template<class t_type, class t_storage>
|
||||
|
|
|
|||
|
|
@ -137,6 +137,9 @@ namespace currency
|
|||
|
||||
struct COMMAND_RPC_GET_HEIGHT
|
||||
{
|
||||
DOC_COMMAND("Return current blockchain height");
|
||||
|
||||
|
||||
struct request
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
@ -149,8 +152,8 @@ namespace currency
|
|||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_DOC2(height) DOC_EX(11111) DOC_DSCR("Some height of the block")
|
||||
KV_SERIALIZE_DOC2(status) DOC_EX("OK") DOC_DSCR("Status of the operation")
|
||||
KV_SERIALIZE_DOC2(height) DOC_DSCR("Some height of the block") DOC_EXMP(11111) DOC_END
|
||||
KV_SERIALIZE_DOC2(status) DOC_DSCR("Status of the operation") DOC_EXMP("OK") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
|
@ -202,7 +205,6 @@ namespace currency
|
|||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
struct response
|
||||
{
|
||||
std::list<std::string> txs_as_hex; //transactions blobs as hex
|
||||
|
|
@ -210,9 +212,9 @@ namespace currency
|
|||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_DOC(txs_as_hex, std::list<std::string>(1, "97d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc97d914497d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc2f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc"), "Transactions stored as blobs")
|
||||
KV_SERIALIZE_DOC(missed_tx, std::list<std::string>(1, "97d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc"), "Missed transactions hashes")
|
||||
KV_SERIALIZE_DOC(status, std::string("OK"), "Command response status")
|
||||
KV_SERIALIZE_DOC2(txs_as_hex) DOC_DSCR("Transactions stored as blobs") DOC_EXMP_AUTO(1, "7d914497d91442f8f3c2268397d914497d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc2f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc") DOC_END
|
||||
KV_SERIALIZE_DOC2(missed_tx) DOC_DSCR("Missed transactions hashes") DOC_EXMP_AUTO(1, "97d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc") DOC_END
|
||||
KV_SERIALIZE_DOC2(status) DOC_DSCR("Command response status") DOC_EXMP_AUTO("OK") DOC_END
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue