Skip to content

Commit 68fd7b5

Browse files
ValeryStkAntonMrt
andauthored
Change style formatter (#176)
* fix multichart and date time multichart bug * add file name to legend * Update version.h * add auto delete on close option * arcstyle to clang-format migration Co-Authored-By: AntonMrt <104432560+AntonMrt@users.noreply.github.com> --------- Co-authored-by: AntonMrt <104432560+AntonMrt@users.noreply.github.com>
1 parent 78f435b commit 68fd7b5

46 files changed

Lines changed: 1394 additions & 1244 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

!Format + one_header.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
call auto_format.bat
1+
call format_all.bat
22
call make_one_header.bat

ResourceManager/include/ResourceManager/ResourceHandle.h

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,55 @@
1-
// Copyright (c) 2018 Johnny Borov <JohnnyBorov@gmail.com>. Released under MIT License.
1+
// Copyright (c) 2018 Johnny Borov <JohnnyBorov@gmail.com>. Released under MIT
2+
// License.
23

34
#ifndef RM_RESOURCE_HANDLE_H
45
#define RM_RESOURCE_HANDLE_H
56

67
#include <cstddef>
7-
#include <string>
88
#include <exception>
9+
#include <string>
910

10-
// This exception type is thrown if ResourceHandle constructor gets invalid resource name.
11-
// Compile with -DRM_NO_EXCEPTIONS to disable throwing on invalid resource name.
11+
// This exception type is thrown if ResourceHandle constructor gets invalid
12+
// resource name. Compile with -DRM_NO_EXCEPTIONS to disable throwing on invalid
13+
// resource name.
1214
class ResourceNotFound : public std::exception {
1315
public:
14-
ResourceNotFound(std::string resource_name) : m_message{"ResourceManager: Resource not found: " + resource_name} {}
15-
virtual const char* what() const noexcept { return m_message.c_str(); }
16+
ResourceNotFound(std::string resource_name)
17+
: m_message{"ResourceManager: Resource not found: " + resource_name} {}
18+
virtual const char *what() const noexcept { return m_message.c_str(); }
1619

1720
private:
1821
const std::string m_message;
1922
};
2023

21-
22-
// This class holds a pointer to the beginning of binary data for the requested resource
23-
// and the length/size (in bytes) of this data. (length and size are the same thing).
24+
// This class holds a pointer to the beginning of binary data for the requested
25+
// resource and the length/size (in bytes) of this data. (length and size are
26+
// the same thing).
2427
// -------------------------------------------------------------------------------------------
25-
// If constructor is called with an invalid resource name ResourceNotFound exception is thrown
26-
// Compile with -DRM_NO_EXCEPTIONS to disable throwing on invalid resource name.
28+
// If constructor is called with an invalid resource name ResourceNotFound
29+
// exception is thrown Compile with -DRM_NO_EXCEPTIONS to disable throwing on
30+
// invalid resource name.
2731
// -------------------------------------------------------------------------------------------
28-
// If exceptions are disabled and constructor is called with an invalid resource name
29-
// then the pointer to the data equials nullptr and length/size equals 0.
30-
// In this case you can use isValid() to determine whether construction was successful or not.
32+
// If exceptions are disabled and constructor is called with an invalid resource
33+
// name then the pointer to the data equials nullptr and length/size equals 0.
34+
// In this case you can use isValid() to determine whether construction was
35+
// successful or not.
3136
// ===========================================================================================
3237
// Avaliable functions:
3338
// -- const bool isValid() const noexcept:
3439
// # returns true if construction was successful, false otherwise.
3540
// #
3641
// -- const unsigned char* const data() const noexcept:
37-
// # returns the pointer to the beginning of binary data or nullptr if construction failed.
38-
// # The data is null-terminated in the end.
42+
// # returns the pointer to the beginning of binary data or nullptr if
43+
// construction failed. # The data is null-terminated in the end.
3944
// #
4045
// -- const char* const c_str() const noexcept:
41-
// # returns the pointer to the beginning of binary data or nullptr if construction failed.
42-
// # The data is null-terminated in the end.
46+
// # returns the pointer to the beginning of binary data or nullptr if
47+
// construction failed. # The data is null-terminated in the end.
4348
// #
4449
// -- std::string string() const:
4550
// # returns std::string based on the binary data with same length as the data.
46-
// # If there are zeroes in the middle of the data string will contain them anyway.
51+
// # If there are zeroes in the middle of the data string will contain them
52+
// anyway.
4753
// #
4854
// -- const size_t size() const noexcept:
4955
// # returns size of the data in bytes or 0 if construction failed.
@@ -57,18 +63,28 @@ class ResourceHandle {
5763
public:
5864
ResourceHandle(std::string resource_name);
5965

60-
const bool isValid() const noexcept { if (m_data_start) return true; else return false; }
66+
const bool isValid() const noexcept {
67+
if (m_data_start)
68+
return true;
69+
else
70+
return false;
71+
}
6172

6273
const size_t size() const noexcept { return m_data_len; }
6374
const size_t length() const noexcept { return m_data_len; }
6475

65-
const unsigned char* const data() const noexcept { return m_data_start; }
76+
const unsigned char *const data() const noexcept { return m_data_start; }
6677

67-
const char* const c_str() const noexcept { return reinterpret_cast<const char*>(m_data_start); }
68-
std::string string() const { return std::string(reinterpret_cast<const char*>(m_data_start), m_data_len); }
78+
const char *const c_str() const noexcept {
79+
return reinterpret_cast<const char *>(m_data_start);
80+
}
81+
std::string string() const {
82+
return std::string(reinterpret_cast<const char *>(m_data_start),
83+
m_data_len);
84+
}
6985

7086
private:
71-
const unsigned char* m_data_start;
87+
const unsigned char *m_data_start;
7288
size_t m_data_len;
7389
};
7490

ResourceManager/src/embed_resource.cpp

Lines changed: 95 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
// Copyright (c) 2018 Johnny Borov <JohnnyBorov@gmail.com>. Released under MIT License.
1+
// Copyright (c) 2018 Johnny Borov <JohnnyBorov@gmail.com>. Released under MIT
2+
// License.
23

34
#include <fstream>
45
#include <string>
56

6-
void generateResourceDataSourceFile(char* resource_name, char* resource_file_name, char* output_file_name);
7-
void generateResourcesConfigSourceFile(char* resource_names_list, char* config_file_name);
7+
void generateResourceDataSourceFile(char *resource_name,
8+
char *resource_file_name,
9+
char *output_file_name);
10+
void generateResourcesConfigSourceFile(char *resource_names_list,
11+
char *config_file_name);
812
std::string modifyFileName(std::string file_name);
913

10-
11-
int main(int argc, char* argv[]) {
14+
int main(int argc, char *argv[]) {
1215
// working directory = CMAKE_BINARY_DIR when called from cmake custom command
1316
if (std::string(argv[1]) == "-data") {
1417
if (argc == 5)
@@ -25,19 +28,26 @@ int main(int argc, char* argv[]) {
2528
return 0;
2629
}
2730

28-
29-
// generate a cpp file (e.g. resources/res.txt.cpp) containing global extern array of const unsigned char
30-
// of binary data read from the requested input file (CMAKE_SOURCE_DIR/resources/res.txt) plus null-terminator
31-
// in the end of data and a global extern const size_t size of this data in bytes (without null-terminator)
32-
void generateResourceDataSourceFile(char* resource_name, char* resource_file_name, char* output_file_name) {
33-
std::string name{ resource_name }; // e.g. "resources/res.txt"
34-
std::string modified_name = modifyFileName(name); // becomes "resources__slash__res__dot__txt"
35-
36-
std::ifstream ifs{ resource_file_name, std::ios::binary }; // e.g. reads from CMAKE_SOURCE_DIR/resources/res.txt
37-
std::ofstream ofs{ output_file_name }; // e.g. writes to resources/res.txt.cpp
31+
// generate a cpp file (e.g. resources/res.txt.cpp) containing global extern
32+
// array of const unsigned char of binary data read from the requested input
33+
// file (CMAKE_SOURCE_DIR/resources/res.txt) plus null-terminator in the end of
34+
// data and a global extern const size_t size of this data in bytes (without
35+
// null-terminator)
36+
void generateResourceDataSourceFile(char *resource_name,
37+
char *resource_file_name,
38+
char *output_file_name) {
39+
std::string name{resource_name}; // e.g. "resources/res.txt"
40+
std::string modified_name =
41+
modifyFileName(name); // becomes "resources__slash__res__dot__txt"
42+
43+
std::ifstream ifs{
44+
resource_file_name,
45+
std::ios::binary}; // e.g. reads from CMAKE_SOURCE_DIR/resources/res.txt
46+
std::ofstream ofs{output_file_name}; // e.g. writes to resources/res.txt.cpp
3847

3948
ofs << "#include <cstddef>\n";
40-
ofs << "extern const unsigned char _resource_" << modified_name << "_data[] = {\n";
49+
ofs << "extern const unsigned char _resource_" << modified_name
50+
<< "_data[] = {\n";
4151

4252
int line_count = 0;
4353
char c;
@@ -50,28 +60,31 @@ void generateResourceDataSourceFile(char* resource_name, char* resource_file_nam
5060
}
5161
}
5262

53-
ofs << "\'\\0\'"; // null-terminator in case data is going to be interprited as a c string
63+
ofs << "\'\\0\'"; // null-terminator in case data is going to be interprited
64+
// as a c string
5465
ofs << "};\n";
5566
// -1 excludes null-terminator
56-
ofs << "extern const size_t _resource_" << modified_name << "_len = sizeof(_resource_" << modified_name << "_data) - 1;\n";
67+
ofs << "extern const size_t _resource_" << modified_name
68+
<< "_len = sizeof(_resource_" << modified_name << "_data) - 1;\n";
5769
}
5870

59-
60-
// generate a cpp file (e.g. __resources__config.cpp) that defines ResourceHandle constructor.
61-
// The defenition contains the hardcoded mapping of original resource names (e.g. "resources/res.txt")
62-
// to their corresponding global extern variables names. Thus it returns a handle which contains pointer to
63-
// the beginning of global extern array of const unsigned char and its size (see -data option description)
64-
void generateResourcesConfigSourceFile(char* resource_names_list, char* config_file_name) {
71+
// generate a cpp file (e.g. __resources__config.cpp) that defines
72+
// ResourceHandle constructor. The defenition contains the hardcoded mapping of
73+
// original resource names (e.g. "resources/res.txt") to their corresponding
74+
// global extern variables names. Thus it returns a handle which contains
75+
// pointer to the beginning of global extern array of const unsigned char and
76+
// its size (see -data option description)
77+
void generateResourcesConfigSourceFile(char *resource_names_list,
78+
char *config_file_name) {
6579
std::ofstream ofs(config_file_name); // e.g. writes to __resources__config.cpp
6680

67-
ofs <<
68-
"#include \"ResourceManager/ResourceHandle.h\"\n"
69-
"\n"
70-
"ResourceHandle::ResourceHandle(std::string resource_name) {\n"
71-
" ";
72-
81+
ofs << "#include \"ResourceManager/ResourceHandle.h\"\n"
82+
"\n"
83+
"ResourceHandle::ResourceHandle(std::string resource_name) {\n"
84+
" ";
7385

74-
std::string resource_names{resource_names_list}; // e.g. "res.txt;res2.txt;resources/res.txt"
86+
std::string resource_names{
87+
resource_names_list}; // e.g. "res.txt;res2.txt;resources/res.txt"
7588
size_t length = resource_names.length();
7689
size_t start_pos = 0;
7790
do {
@@ -83,59 +96,66 @@ void generateResourcesConfigSourceFile(char* resource_names_list, char* config_f
8396
std::string name = resource_names.substr(start_pos, end_pos - start_pos);
8497
std::string modified_name = modifyFileName(name);
8598

86-
ofs <<
87-
"if (resource_name == \"" << name << "\") {\n"
88-
" extern const unsigned char _resource_" << modified_name << "_data[];\n"
89-
" extern const size_t _resource_" << modified_name << "_len;\n"
90-
" m_data_start = _resource_" << modified_name << "_data;\n"
91-
" m_data_len = _resource_" << modified_name << "_len;\n"
92-
" } else ";
93-
94-
start_pos = end_pos + 1; // e.g. start next read from res2... position in "res.txt;res2.txt;resources/res.txt"
99+
ofs << "if (resource_name == \"" << name
100+
<< "\") {\n"
101+
" extern const unsigned char _resource_"
102+
<< modified_name
103+
<< "_data[];\n"
104+
" extern const size_t _resource_"
105+
<< modified_name
106+
<< "_len;\n"
107+
" m_data_start = _resource_"
108+
<< modified_name
109+
<< "_data;\n"
110+
" m_data_len = _resource_"
111+
<< modified_name
112+
<< "_len;\n"
113+
" } else ";
114+
115+
start_pos = end_pos + 1; // e.g. start next read from res2... position in
116+
// "res.txt;res2.txt;resources/res.txt"
95117
} while (start_pos < length);
96118

97-
98-
ofs <<
99-
"{\n"
100-
"#ifdef RM_NO_EXCEPTIONS\n"
101-
" m_data_start = nullptr;\n"
102-
" m_data_len = 0;\n"
103-
"#else\n"
104-
" throw ResourceNotFound{resource_name};\n"
105-
"#endif\n"
106-
" }\n"
107-
"}\n";
119+
ofs << "{\n"
120+
"#ifdef RM_NO_EXCEPTIONS\n"
121+
" m_data_start = nullptr;\n"
122+
" m_data_len = 0;\n"
123+
"#else\n"
124+
" throw ResourceNotFound{resource_name};\n"
125+
"#endif\n"
126+
" }\n"
127+
"}\n";
108128
}
109129

110-
111130
// replace symbols that cant be used in c++ identeficator name
112131
// e.g. "resources/res.txt" -> "resources__slash__res__dot__txt"
113132
std::string modifyFileName(std::string file_name) {
114133
size_t search_from_pos = 0;
115134
size_t replace_from_pos;
116-
while ((replace_from_pos = file_name.find_first_of(".- /\\", search_from_pos)) != std::string::npos) {
117-
switch (file_name[replace_from_pos]) {
118-
case '.':
119-
file_name.replace(replace_from_pos, 1, "__dot__");
120-
search_from_pos = replace_from_pos + 7; // shift len(__dot__) = 5 symbols
121-
break;
122-
case '-':
123-
file_name.replace(replace_from_pos, 1, "__dash__");
124-
search_from_pos = replace_from_pos + 8;
125-
break;
126-
case ' ':
127-
file_name.replace(replace_from_pos, 1, "__space__");
128-
search_from_pos = replace_from_pos + 9;
129-
break;
130-
case '/':
131-
file_name.replace(replace_from_pos, 1, "__slash__");
132-
search_from_pos = replace_from_pos + 9;
133-
break;
134-
case '\\':
135-
file_name.replace(replace_from_pos, 1, "__bslash__");
136-
search_from_pos = replace_from_pos + 10;
137-
break;
138-
}
135+
while ((replace_from_pos = file_name.find_first_of(
136+
".- /\\", search_from_pos)) != std::string::npos) {
137+
switch (file_name[replace_from_pos]) {
138+
case '.':
139+
file_name.replace(replace_from_pos, 1, "__dot__");
140+
search_from_pos = replace_from_pos + 7; // shift len(__dot__) = 5 symbols
141+
break;
142+
case '-':
143+
file_name.replace(replace_from_pos, 1, "__dash__");
144+
search_from_pos = replace_from_pos + 8;
145+
break;
146+
case ' ':
147+
file_name.replace(replace_from_pos, 1, "__space__");
148+
search_from_pos = replace_from_pos + 9;
149+
break;
150+
case '/':
151+
file_name.replace(replace_from_pos, 1, "__slash__");
152+
search_from_pos = replace_from_pos + 9;
153+
break;
154+
case '\\':
155+
file_name.replace(replace_from_pos, 1, "__bslash__");
156+
search_from_pos = replace_from_pos + 10;
157+
break;
158+
}
139159
}
140160

141161
return file_name;

ResourceManager/test/src/test_main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// Copyright (c) 2018 Johnny Borov <JohnnyBorov@gmail.com>. Released under MIT License.
1+
// Copyright (c) 2018 Johnny Borov <JohnnyBorov@gmail.com>. Released under MIT
2+
// License.
23

3-
#include <iostream>
44
#include "ResourceManager/ResourceHandle.h"
5+
#include <iostream>
56

67
void testInvalidResource() {
7-
ResourceHandle rhdi("i_dont_exist"); // -DRM_NO_EXCEPTIONS to disable throw on invalid recource
8+
ResourceHandle rhdi("i_dont_exist"); // -DRM_NO_EXCEPTIONS to disable throw on
9+
// invalid recource
810
std::cout << "rhdi is valid = " << rhdi.isValid() << '\n';
911
}
1012

@@ -21,7 +23,7 @@ int main() {
2123
std::cout << "rh3 size = " << rh3.size() << '\n';
2224

2325
testInvalidResource();
24-
} catch (const ResourceNotFound& e) {
26+
} catch (const ResourceNotFound &e) {
2527
std::cout << e.what() << '\n';
2628
}
2729

0 commit comments

Comments
 (0)