MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / main

Function main

CMakeModules/bin2cpp.cpp:255–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253}
254
255int main(int argc, const char *const *const argv) {
256 vector<string> args(argv, argv + argc);
257
258 if (argc == 1) {
259 print_usage();
260 return 0;
261 }
262 opt_t &&options = parse_options(args);
263
264 // Save default cout buffer. Need this to prevent crash.
265 auto bak = cout.rdbuf();
266 unique_ptr<ofstream> outfile;
267
268 // Set defaults
269 if (options["--name"] == "") { options["--name"] = "var"; }
270 if (options["--output"] != "") {
271 // redirect stream if output file is specified
272 outfile.reset(new ofstream(options["--output"]));
273 cout.rdbuf(outfile->rdbuf());
274 }
275
276 cout << "#pragma once\n";
277 cout << "#include <cstddef>\n"; // defines size_t
278 cout << "#include <common/Source.hpp>\n"; // defines common::Source
279
280 int ns_cnt = 0;
281 int level = 0;
282 if (options["--namespace"] != "") {
283 stringstream namespaces(options["--namespace"]);
284 string name;
285 namespaces >> name;
286 do {
287 add_tabs(level++);
288 cout << "namespace " << name << " { \n";
289 ns_cnt++;
290 namespaces >> name;
291 } while (!namespaces.fail());
292 }
293
294 if (options["--type"] == "") { options["--type"] = "char"; }
295 add_tabs(level);
296
297 // Always create unsigned char to avoid narrowing
298 cout << "static const "
299 << "unsigned char"
300 << " " << options["--name"] << "_uchar [] = {\n";
301
302 ifstream input(options["--file"],
303 (binary ? std::ios::binary : std::ios::in));
304 size_t char_cnt = 0;
305 stringstream ss = removeComments(input, options["--file"]);
306 add_tabs(++level);
307 for (char i; ss.get(i);) {
308 cout << "0x" << std::hex << static_cast<int>(i & 0xff) << ",\t";
309 char_cnt++;
310 if (!(char_cnt % 10)) {
311 cout << endl;
312 add_tabs(level);

Callers

nothing calls this directly

Calls 7

print_usageFunction · 0.85
parse_optionsFunction · 0.85
add_tabsFunction · 0.85
removeCommentsFunction · 0.85
deterministicHashFunction · 0.85
resetMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected