-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_gen.cpp
More file actions
64 lines (59 loc) · 1.76 KB
/
Copy pathtemplate_gen.cpp
File metadata and controls
64 lines (59 loc) · 1.76 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @description: This is a template generator for CPP file.
* You could only input your function name, you will
* get a functionname.cpp and some template function.
* @author: wenlong.cao
* @create date: 2016-10-30
*
**/
#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
#include <time.h>
using namespace std;
#define FUNC_PARAM char*, const int size, int start
typedef void(*PF_RET_VOID)(FUNC_PARAM);
struct tm& today(std::ostream& out = std::cout)
{
time_t timesec = time(NULL);
return *localtime(×ec);
}
std::ostream & operator << (std::ostream &out,const struct tm &timeinfo)
{
out <<timeinfo.tm_year+1900<<"-" <<timeinfo.tm_mon+1<<"-"<<timeinfo.tm_mday;
return out;
}
int main(int argc, char const *argv[])
{
if(argc < 2)
{
std::cout << "Please input a filename"<<std::endl;
}
else
{
string s(argv[1]);
std::fstream fs;
string filename = s;
filename.append(".cpp");
fs.open(filename.c_str(), std::ofstream::out);
fs << "/**\n"
<< "* @author: wenlong.cao \n"
<< "* @description: The file description.\n";
fs <<"* @create Date:";
fs << today() << "\n**/\n";
fs <<"#include <iostream>"<<std::endl;
fs <<"#include <assert.h>"<<std::endl;
fs <<"#include <string.h>"<<std::endl;
fs <<"#define FUNC_PARAM char*, const int size, int start"<<std::endl;
fs <<"typedef void(*PF_RET_VOID)(FUNC_PARAM);" <<std::endl;
fs <<"void "<<s <<" (" <<"char*, const int size, int start"<<")\n";
fs <<"{\n";
fs <<"\t//The is your code\n";
fs <<"}\n";
fs << "void test_all(PF_RET_VOID p) \n{\n\tchar a[] = \"Hello\";\n\tint size = strlen(a);\n\t(*p)(a, size, 0);\n}\n";
fs << "int main(int argc, char const *argv[])\n{\n\ttest_all("<<s << ");\n\treturn 0;\n}\n";
fs.close();
}
return 0;
}