@@ -20,10 +20,10 @@ namespace utils {
20
20
21
21
// WARNING: this only works with 4 byte types
22
22
template <class T >
23
- bool createTestFileImpl (const string& file_name , uint64_t count,
23
+ bool CreateTestFileImpl (const string& fileName , uint64_t count,
24
24
function<T(int )> factory) {
25
25
// Open file
26
- ofstream of (file_name , ios::binary);
26
+ ofstream of (fileName , ios::binary);
27
27
if (!of.is_open () || !of.good ())
28
28
return false ;
29
29
@@ -46,9 +46,9 @@ bool createTestFileImpl(const string& file_name, uint64_t count,
46
46
}
47
47
48
48
template <class T >
49
- bool foreachInFileImpl (const string& file_name , function<void (T)> callback) {
49
+ bool ForeachInFileImpl (const string& fileName , function<void (T)> callback) {
50
50
// Open file
51
- ifstream in (file_name , ios::binary);
51
+ ifstream in (fileName , ios::binary);
52
52
if (!in.is_open () || !in.good ())
53
53
return false ;
54
54
@@ -63,52 +63,52 @@ bool foreachInFileImpl(const string& file_name, function<void(T)> callback) {
63
63
return true ;
64
64
}
65
65
66
- bool CreateTestFile (const string& file_name , uint64_t count,
66
+ bool CreateTestFile (const string& fileName , uint64_t count,
67
67
function<int32_t (int32_t )> factory) {
68
- return createTestFileImpl <int32_t >(file_name , count, factory);
68
+ return CreateTestFileImpl <int32_t >(fileName , count, factory);
69
69
}
70
70
71
- bool ForeachInFile (const string& file_name , function<void (uint32_t )> callback) {
72
- return foreachInFileImpl <uint32_t >(file_name , callback);
71
+ bool ForeachInFile (const string& fileName , function<void (uint32_t )> callback) {
72
+ return ForeachInFileImpl <uint32_t >(fileName , callback);
73
73
}
74
74
75
- bool CreateDirectory (const string& directory_name ) {
76
- return mkdir (directory_name .c_str (), 0666 ) == 0 ;
75
+ bool CreateDirectory (const string& dirName ) {
76
+ return mkdir (dirName .c_str (), 0666 ) == 0 ;
77
77
}
78
78
79
- bool CreateFile (const string& file_name , const uint64_t bytes) {
80
- int file_fd = open (file_name .c_str (), O_CREAT | O_WRONLY, 0666 );
81
- if (file_fd < 0 ) {
79
+ bool CreateFile (const string& fileName , const uint64_t bytes) {
80
+ int fileFd = open (fileName .c_str (), O_CREAT | O_WRONLY, 0666 );
81
+ if (fileFd < 0 ) {
82
82
return false ; // Use strerror(errno) to find error
83
83
}
84
84
85
- if (ftruncate (file_fd , bytes) != 0 ) {
85
+ if (ftruncate (fileFd , bytes) != 0 ) {
86
86
return false ; // Use strerror(errno) to find error
87
87
}
88
88
89
- if (close (file_fd ) != 0 ) {
89
+ if (close (fileFd ) != 0 ) {
90
90
return false ; // Use strerror(errno) to find error
91
91
}
92
92
93
93
return true ;
94
94
}
95
95
96
- bool CreateFile (const string& file_name , const string& content) {
97
- int file_fd = open (file_name .c_str (), O_CREAT | O_TRUNC | O_WRONLY, 0666 );
98
- if (file_fd < 0 ) {
96
+ bool CreateFile (const string& fileName , const string& content) {
97
+ int fileFd = open (fileName .c_str (), O_CREAT | O_TRUNC | O_WRONLY, 0666 );
98
+ if (fileFd < 0 ) {
99
99
return false ; // Use strerror(errno) to find error
100
100
}
101
101
102
- size_t written_bytes = write (file_fd , content.data (), content.size ());
103
- return written_bytes == content.size ();
102
+ size_t writtenBytes = write (fileFd , content.data (), content.size ());
103
+ return writtenBytes == content.size ();
104
104
}
105
105
106
- void DeleteFile (const std::string& file_name ) {
107
- remove (file_name .c_str ());
106
+ void DeleteFile (const std::string& fileName ) {
107
+ remove (fileName .c_str ());
108
108
}
109
109
110
- uint64_t GetFileLength (const string& file_name ) {
111
- int fileFD = open (file_name .c_str (), O_RDWR);
110
+ uint64_t GetFileLength (const string& fileName ) {
111
+ int fileFD = open (fileName .c_str (), O_RDWR);
112
112
if (fileFD < 0 ) {
113
113
cout << " Unable to open file"
114
114
<< endl; // You can POSIX_CHECK errno to see what happend
@@ -125,35 +125,35 @@ uint64_t GetFileLength(const string& file_name) {
125
125
return st.st_size ;
126
126
}
127
127
128
- bool fileExists (const string& file_name ) {
128
+ bool FileExists (const string& fileName ) {
129
129
struct stat buffer;
130
- bool exists = (stat (file_name .c_str (), &buffer) == 0 );
130
+ bool exists = (stat (fileName .c_str (), &buffer) == 0 );
131
131
return exists && (buffer.st_mode & S_IFREG);
132
132
}
133
133
134
- bool directoryExists (const string& file_name ) {
134
+ bool DirectoryExists (const string& fileName ) {
135
135
struct stat buffer;
136
- bool exists = (stat (file_name .c_str (), &buffer) == 0 );
136
+ bool exists = (stat (fileName .c_str (), &buffer) == 0 );
137
137
return exists && (buffer.st_mode & S_IFDIR);
138
138
}
139
139
140
- bool pathExists (const string& file_name ) {
140
+ bool PathExists (const string& fileName ) {
141
141
struct stat buffer;
142
- bool exists = (stat (file_name .c_str (), &buffer) == 0 );
142
+ bool exists = (stat (fileName .c_str (), &buffer) == 0 );
143
143
return exists;
144
144
}
145
145
146
- string LoadFileToMemory (const string& file_name ) {
147
- uint64_t length = GetFileLength (file_name );
146
+ string LoadFileToMemory (const string& fileName ) {
147
+ uint64_t length = GetFileLength (fileName );
148
148
string data (length, ' a' );
149
- ifstream in (file_name );
149
+ ifstream in (fileName );
150
150
in.read (&data[0 ], length);
151
151
return data;
152
152
}
153
153
154
154
namespace {
155
155
156
- uint64_t applyPrecision (uint64_t input, uint32_t precision) {
156
+ uint64_t ApplyPrecision (uint64_t input, uint32_t precision) {
157
157
uint32_t digits = log10 (input) + 1 ;
158
158
if (digits <= precision)
159
159
return input;
@@ -166,7 +166,7 @@ uint64_t applyPrecision(uint64_t input, uint32_t precision) {
166
166
string FormatTime (chrono::nanoseconds ns, uint32_t precision) {
167
167
ostringstream os;
168
168
169
- uint64_t timeSpan = applyPrecision (ns.count (), precision);
169
+ uint64_t timeSpan = ApplyPrecision (ns.count (), precision);
170
170
171
171
// Convert to right unit
172
172
if (timeSpan < 1000ll )
@@ -203,10 +203,10 @@ void PinThread(int socket) {
203
203
(void )socket;
204
204
}
205
205
206
- void RunMultithreaded (uint32_t thread_count , function<void (uint32_t )> foo) {
206
+ void RunMultithreaded (uint32_t threadCount , function<void (uint32_t )> foo) {
207
207
atomic<bool > start (false );
208
- vector<unique_ptr<thread>> threads (thread_count );
209
- for (uint32_t i = 0 ; i < thread_count ; i++) {
208
+ vector<unique_ptr<thread>> threads (threadCount );
209
+ for (uint32_t i = 0 ; i < threadCount ; i++) {
210
210
threads[i] = make_unique<thread>([i, &foo, &start]() {
211
211
while (!start)
212
212
;
@@ -230,8 +230,8 @@ uint8_t* AlignedAlloc(uint64_t alignment, uint64_t size) {
230
230
231
231
namespace {
232
232
233
- array<char , 16 > NUM_TO_HEX {{' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' ,
234
- ' a ' , ' b' , ' c' , ' d' , ' e' , ' f' }};
233
+ array<char , 16 > numToHex {{' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' a ' ,
234
+ ' b' , ' c' , ' d' , ' e' , ' f' }};
235
235
uint8_t HexToNum (char c) {
236
236
if (' a' <= c && c <= ' f' ) {
237
237
return 10 + (c - ' a' );
@@ -247,8 +247,8 @@ uint8_t HexToNum(char c) {
247
247
const string DataToHex (const uint8_t * data, uint32_t len, bool spaces) {
248
248
string result;
249
249
for (uint32_t i = 0 ; i < len; i++) {
250
- result += NUM_TO_HEX [*(data + i) >> 4 ];
251
- result += NUM_TO_HEX [*(data + i) & 0x0f ];
250
+ result += numToHex [*(data + i) >> 4 ];
251
+ result += numToHex [*(data + i) & 0x0f ];
252
252
if (spaces && i != len - 1 )
253
253
result += ' ' ;
254
254
}
@@ -262,8 +262,8 @@ const string StringToHex(const string& str, bool spaces) {
262
262
const vector<uint8_t > HexToData (const string& str, bool spaces) {
263
263
assert (spaces || str.size () % 2 == 0 );
264
264
265
- uint32_t result_size = spaces ? ((str.size () + 1 ) / 3 ) : (str.size () / 2 );
266
- vector<uint8_t > result (result_size );
265
+ uint32_t resultSize = spaces ? ((str.size () + 1 ) / 3 ) : (str.size () / 2 );
266
+ vector<uint8_t > result (resultSize );
267
267
for (uint32_t i = 0 , out = 0 ; i < str.size (); i += 2 , out++) {
268
268
result[out] = (HexToNum (str[i]) << 4 ) | HexToNum (str[i + 1 ]);
269
269
i += spaces ? 1 : 0 ;
@@ -275,8 +275,8 @@ const vector<uint8_t> HexToData(const string& str, bool spaces) {
275
275
const string HexToString (const string& str, bool spaces) {
276
276
assert (spaces || str.size () % 2 == 0 );
277
277
278
- uint32_t result_size = spaces ? ((str.size () + 1 ) / 3 ) : (str.size () / 2 );
279
- string result (result_size , ' x' );
278
+ uint32_t resultSize = spaces ? ((str.size () + 1 ) / 3 ) : (str.size () / 2 );
279
+ string result (resultSize , ' x' );
280
280
for (uint32_t i = 0 , out = 0 ; i < str.size (); i += 2 , out++) {
281
281
result[out] = (char )((HexToNum (str[i]) << 4 ) | HexToNum (str[i + 1 ]));
282
282
i += spaces ? 1 : 0 ;
0 commit comments