Repository navigation
Expand file tree
/
Copy pathYAML_Doc.cpp
More file actions
74 lines (66 loc) · 2.01 KB
/
Copy pathYAML_Doc.cpp
File metadata and controls
74 lines (66 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
8A61
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <ctime>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#ifdef REDSTORM
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include "YAML_Doc.hpp"
using namespace std;
//set the microapp_name and version which will become part of the YAML doc.
YAML_Doc::YAML_Doc(const std::string& miniApp_Name, const std::string& miniApp_Version, const std::string& destination_Directory, const std::string& destination_FileName){
miniAppName = miniApp_Name;
miniAppVersion = miniApp_Version;
destinationDirectory = destination_Directory;
destinationFileName = destination_FileName;
}
//inherits the destructor from YAML_Element
YAML_Doc::~YAML_Doc(void){
}
/*
* generates YAML from the elements of the document and saves it
* to a file
*/
string YAML_Doc::generateYAML(){
string yaml;
yaml = yaml + "Mini-Application Name: " + miniAppName + "\n";
yaml = yaml + "Mini-Application Version: " + miniAppVersion + "\n";
for(size_t i=0; i<children.size(); i++){
yaml = yaml + children[i]->printYAML("");
}
time_t rawtime;
tm * ptm;
time ( &rawtime );
ptm = localtime(&rawtime);
char sdate[25];
//use tm_mon+1 because tm_mon is 0 .. 11 instead of 1 .. 12
sprintf (sdate,"%04d:%02d:%02d-%02d:%02d:%02d",ptm->tm_year + 1900, ptm->tm_mon+1,
ptm->tm_mday, ptm->tm_hour, ptm->tm_min,ptm->tm_sec);
string filename;
if (destinationFileName=="")
filename = miniAppName + "-" + miniAppVersion + "_";
else
filename = destinationFileName;
filename = filename + string(sdate) + ".yaml";
if (destinationDirectory!="" && destinationDirectory!=".") {
string mkdir_cmd = "mkdir " + destinationDirectory;
#ifdef REDSTORM
mkdir(destinationDirectory.c_str(),0755);
#else
system(mkdir_cmd.c_str());
#endif
filename = destinationDirectory + "/" + destinationFileName;
}
else
filename = "./" + filename;
ofstream myfile;
myfile.open(filename.c_str());
myfile << yaml;
myfile.close();
return yaml;
}