-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtility.h
More file actions
54 lines (45 loc) · 1.12 KB
/
Utility.h
File metadata and controls
54 lines (45 loc) · 1.12 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Utility.h
* Author: rakhasan
*
* Created on March 11, 2016, 5:07 PM
*/
#ifndef UTILITY_H
#define UTILITY_H
#include <string>
#include <iostream>
#include <sstream>
#include <sys/stat.h>
class Utility
{
public:
// following method was copied from http://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c
template <typename T>
static string NumberToString ( T Number )
{
ostringstream ss;
ss << Number;
return ss.str();
}
static void CreateDirectory(const string& dir_name)
{
struct stat sb;
if (stat(dir_name.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode))
{
cout<<dir_name<<" already exists."<<endl;
return;
}
const int dir_err = mkdir(dir_name.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (-1 == dir_err)
{
cout<<"Error creating directory: "<<dir_name<<endl;
exit(1);
}
}
};
#endif /* UTILITY_H */