forked from ismrmrd/siemens_to_ismrmrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed.cpp
43 lines (33 loc) · 1.38 KB
/
embed.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "base64.h"
#include "boost/filesystem.hpp"
int main(int argc, char *argv[])
{
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " [files to embed] <output file>" << std::endl;
return 1;
}
char *outfile_name = argv[argc - 1];
std::ofstream output(outfile_name, std::ofstream::out);
output << "#include <iostream>" << std::endl;
output << "#include <map>" << std::endl << std::endl;
output << "#include <string>" << std::endl << std::endl;
std::string map_name = "global_embedded_files";
output << "std::map<std::string, std::string> "<< map_name << ";" << std::endl << std::endl;
output << "void initializeEmbeddedFiles(void) {" << std::endl;
for (int i = 1; i < argc - 1; i++) {
char *infile_name = argv[i];
std::ifstream infile(infile_name);
std::string contents((std::istreambuf_iterator<char>)(infile), std::istreambuf_iterator<char>());
std::string encoded = base64_encode(reinterpret_cast<const unsigned char*>(contents.c_str()), contents.length());
boost::filesystem::path path(infile_name);
std::string keyname = path.filename().string();
output << "{" << std::endl;
output << " std::string v; " << std::endl;
splitBigString(output, encoded, 12);
output << map_name << "[\"" << keyname << "\"] = v;" << std::endl;
output << "}" << std::endl;
}
output << "}" << std::endl;
output.close();
return 0;
}