MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / write_functions

Function write_functions

src/api_builder/build_csharp.cpp:120–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120void write_functions( std::ostream& out, json_value* function_root, const std::map< std::string, std::string>& typeMap, const std::string& _template, const std::unordered_set< std::string >& includes, const std::unordered_set< std::string >& excludes ) {
121 assert(function_root->type == json_array);
122
123 for (auto& it: jsonArrayIterator(function_root))
124 {
125 std::string comment = get_object_string_key(it, "_comment");
126 if (!comment.empty()) {
127 out << "\n// " << comment << "\n";
128 }
129 std::string funcname = get_object_string_key(it, "functionname");
130 std::string returntype = get_object_string_key(it, "returntype");
131
132 if (!funcname.empty() && !returntype.empty()) {
133
134 json_value* params = get_object_key(it, "params");
135 json_value* options = get_object_key(it, "options");
136
137 if( ! excludes.empty() && has_any_options( options, excludes ) )
138 continue;
139
140 if( !includes.empty() && !has_any_options( options, includes ) )
141 continue;
142
143 std::stringstream ss;
144
145 if (params) {
146 ss << "(";
147 std::stringstream argss;
148 for (auto& pit : jsonArrayIterator(params))
149 {
150 std::string paramtype = get_object_string_key(pit, "paramtype");
151 auto typeIt = typeMap.find( paramtype );
152 if( typeIt != typeMap.end() ) {
153 paramtype = typeIt->second;
154 }
155
156 std::string paramname = get_object_string_key(pit, "paramname");
157 ss << " " << paramtype << " " << paramname << ",";
158 }
159 ss.seekp(-1, std::ios_base::cur);
160 ss << " )";
161 } else {
162 ss << "()";
163 }
164
165 std::map< std::string, std::string > data;
166 data.emplace( "functionname", funcname );
167
168 auto typeIt = typeMap.find( returntype );
169 if( typeIt != typeMap.end() ) {
170 returntype = typeIt->second;
171 }
172
173 data.emplace( "returntype", returntype );
174 data.emplace( "params", ss.str() );
175
176 auto processToken = [data] ( std::ostream& out, const std::string& token ) {
177 if( data.find( token ) != data.end() )

Callers 1

buildCSharpFunction · 0.85

Calls 8

jsonArrayIteratorClass · 0.85
get_object_string_keyFunction · 0.85
get_object_keyFunction · 0.85
has_any_optionsFunction · 0.85
template_replace_tokensFunction · 0.85
findMethod · 0.80
strMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected