| 221 | |
| 222 | |
| 223 | void buildCSharp(const std::string& input, const std::string& _template, const std::string& output) |
| 224 | { |
| 225 | std::ofstream outfile(output.c_str()); |
| 226 | |
| 227 | std::string jsBuff = loadFile(input); |
| 228 | |
| 229 | std::string tpl = loadFile( _template ); |
| 230 | if( tpl.empty() ) { |
| 231 | die("Unable to load template file"); |
| 232 | } |
| 233 | |
| 234 | json_value *root = json_parse(jsBuff.c_str(), jsBuff.size()); |
| 235 | if (root) { |
| 236 | std::map< std::string, std::string > typeMap; |
| 237 | |
| 238 | json_value *typedef_root = get_object_key(root, "typedefs"); |
| 239 | if( typedef_root ) |
| 240 | parseTypedefs( typedef_root, typeMap ); |
| 241 | |
| 242 | auto processToken = [root,typeMap] ( std::ostream& out, const std::string& token ) { |
| 243 | |
| 244 | if( ! token.compare( 0, 9, "functions" ) ) { |
| 245 | |
| 246 | std::unordered_set<std::string> includes; |
| 247 | std::unordered_set<std::string> excludes; |
| 248 | |
| 249 | for( auto& option : split( token.substr(10), ' ' ) ) { |
| 250 | if( option.length() < 3 ) |
| 251 | continue; |
| 252 | else if( option[0] == '-' ) { |
| 253 | excludes.insert( option.substr(1) ); |
| 254 | } else { // if( option[0] == '+' ) ) { include is implicit |
| 255 | includes.insert( option.substr(1) ); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | write_functions( out, get_object_key(root,"functions"), typeMap, function_template, includes, excludes ); |
| 260 | } else if( token == "enums" ) { |
| 261 | write_enums( out, get_object_key(root,"enums") ); |
| 262 | } |
| 263 | }; |
| 264 | |
| 265 | template_replace_tokens(outfile, tpl, processToken ); |
| 266 | |
| 267 | json_value_free(root); |
| 268 | } else { |
| 269 | die("Unable to parse JSON file"); |
| 270 | } |
| 271 | } |
no test coverage detected