Scorum
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
api_documentation_standin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #include <iomanip>
25 #include <boost/algorithm/string/join.hpp>
26 #include <scorum/wallet/wallet.hpp>
28 
29 namespace scorum {
30 namespace wallet {
31 namespace detail {
32 namespace {
33 template <typename... Args> struct types_to_string_list_helper;
34 
35 template <typename First, typename... Args> struct types_to_string_list_helper<First, Args...>
36 {
37  std::list<std::string> operator()() const
38  {
39  std::list<std::string> argsList = types_to_string_list_helper<Args...>()();
40  argsList.push_front(fc::get_typename<typename std::decay<First>::type>::name());
41  return argsList;
42  }
43 };
44 
45 template <> struct types_to_string_list_helper<>
46 {
47  std::list<std::string> operator()() const
48  {
49  return std::list<std::string>();
50  }
51 };
52 
53 template <typename... Args> std::list<std::string> types_to_string_list()
54 {
55  return types_to_string_list_helper<Args...>()();
56 }
57 } // end anonymous namespace
58 
60 {
61  std::vector<method_description> method_descriptions;
62 
63  template <typename R, typename... Args> void operator()(const char* name, std::function<R(Args...)>& memb)
64  {
65  method_description this_method;
66  this_method.method_name = name;
67  std::ostringstream ss;
68  ss << std::setw(40) << std::left << fc::get_typename<R>::name() << " " << name << "(";
69  ss << boost::algorithm::join(types_to_string_list<Args...>(), ", ");
70  ss << ")\n";
71  this_method.brief_description = ss.str();
72  method_descriptions.push_back(this_method);
73  }
74 };
75 } // end namespace detail
76 
78 {
79  fc::api<wallet_api> tmp;
80  detail::help_visitor visitor;
81  tmp->visit(visitor);
82  std::copy(visitor.method_descriptions.begin(), visitor.method_descriptions.end(),
83  std::inserter(method_descriptions, method_descriptions.end()));
84 }
85 }
86 } // end namespace scorum::wallet
Definition: asset.cpp:15
std::vector< method_description > method_descriptions
void operator()(const char *name, std::function< R(Args...)> &memb)