-
Notifications
You must be signed in to change notification settings - Fork 6
/
Support.h
73 lines (57 loc) · 1.61 KB
/
Support.h
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
65
66
67
68
69
70
71
72
73
/*
* Support.h
*
* Created on: 11/lug/2013
* Author: Stefano Ceccherini
*/
#ifndef SUPPORT_H_
#define SUPPORT_H_
#include <algorithm>
#include <sstream>
#include <stdio.h>
#include <streambuf>
#include <string>
class CommandStreamBuffer : public std::streambuf {
public:
CommandStreamBuffer();
CommandStreamBuffer(const char* fileName, const char* mode);
virtual ~CommandStreamBuffer();
CommandStreamBuffer* open(const char* command, const char* mode);
void close();
std::streamsize xsgetn(char_type* ptr, std::streamsize n);
int_type underflow();
std::streamsize showmanyc();
private:
FILE* fFile;
char_type* fBuffer;
};
bool CommandExists(const char* command);
std::string RAM_type_from_description(const std::string& description);
unsigned int convert_to_MBytes(const std::string& string);
static inline std::string& ltrim(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
static inline std::string& rtrim(std::string& s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;
}
static inline std::string& trim(std::string& s) {
return ltrim(rtrim(s));
}
static inline std::string trimmed(const std::string& s) {
std::string newString = s;
ltrim(rtrim(newString));
return newString;
}
static inline std::string int_to_string(int i) {
std::ostringstream stream;
stream << i;
return stream.str();
}
static inline std::string uint_to_string(unsigned int i) {
std::ostringstream stream;
stream << i;
return stream.str();
}
#endif /* SUPPORT_H_ */