Skip to content

Commit 8cf7f98

Browse files
authored
Merge pull request #23 from wsjcpp/version-0.2.1
Version 0.2.1
2 parents e9e98ec + 8291cd3 commit 8cf7f98

27 files changed

+201
-279
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ list (APPEND WSJCPP_INCLUDE_DIRS "src")
1717

1818
list (APPEND WSJCPP_SOURCES "src/wsjcpp_core.h")
1919
list (APPEND WSJCPP_SOURCES "src/wsjcpp_core.cpp")
20-
list (APPEND WSJCPP_SOURCES "src/wsjcpp_resources_manager.h")
21-
list (APPEND WSJCPP_SOURCES "src/wsjcpp_resources_manager.cpp")
2220

2321
list (APPEND WSJCPP_SOURCES "src/main.cpp")
2422

scripts.wsjcpp/generate.WsjcppUnitTest renamed to scripts.wsjcpp/generate.WsjcppUnitTest.wsjcpp-script

+11-44
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,21 @@
66
make_dir "./unit-tests.wsjcpp"
77
make_dir "./unit-tests.wsjcpp/src"
88

9-
var user_class_name
10-
set_value user_class_name arg1
11-
normalize_class_name user_class_name
129
var class_name
13-
set_value class_name "UnitTest"
14-
concat class_name user_class_name
15-
16-
var base_filename
17-
convert_CamelCase_to_snake_case class_name base_filename
18-
# log_info base_filename
10+
set_value class_name arg1
11+
normalize_class_name class_name
1912

2013
var filename_cpp
21-
concat filename_cpp "./unit-tests.wsjcpp/src/" base_filename ".cpp"
22-
23-
var filename_h
24-
concat filename_h "./unit-tests.wsjcpp/src/" base_filename ".h"
25-
26-
var ifndef_header
27-
set_value ifndef_header base_filename
28-
concat ifndef_header "_H"
29-
30-
to_upper_case ifndef_header
31-
32-
var content_header
33-
concat content_header "#ifndef " ifndef_header "
34-
#define " ifndef_header "
14+
set_value filename_cpp arg2
3515

16+
var content_source
17+
concat content_source "
18+
#include <wsjcpp_core.h>
3619
#include <wsjcpp_unit_tests.h>
3720

21+
// ---------------------------------------------------------------------
22+
// " class_name "
23+
3824
class " class_name " : public WsjcppUnitTestBase {
3925
public:
4026
" class_name "();
@@ -43,17 +29,6 @@ class " class_name " : public WsjcppUnitTestBase {
4329
virtual bool doAfterTest() override;
4430
};
4531

46-
#endif // " ifndef_header
47-
48-
49-
var content_source
50-
concat content_source "
51-
#include \"" base_filename ".h\"
52-
#include <wsjcpp_core.h>
53-
54-
// ---------------------------------------------------------------------
55-
// " class_name "
56-
5732
REGISTRY_WSJCPP_UNIT_TEST(" class_name ")
5833

5934
" class_name "::" class_name "()
@@ -63,7 +38,7 @@ REGISTRY_WSJCPP_UNIT_TEST(" class_name ")
6338
// ---------------------------------------------------------------------
6439

6540
bool " class_name "::doBeforeTest() {
66-
// nothing
41+
// do something before test
6742
return true;
6843
}
6944

@@ -77,27 +52,19 @@ void " class_name "::executeTest() {
7752
// ---------------------------------------------------------------------
7853

7954
bool " class_name "::doAfterTest() {
80-
// nothing
55+
// do somethig after test
8156
return true;
8257
}
8358

8459
"
8560

86-
var file_source
87-
concat file_source "src/" filename_cpp
88-
89-
write_file filename_h content_header
9061
write_file filename_cpp content_source
9162

9263
log_info "
9364
======
9465
Generated class:
9566
- " class_name "
9667
Generated files:
97-
- " filename_h "
9868
- " filename_cpp "
9969
======
10070
"
101-
102-
wsjcpp_yml_unit_test_add user_class_name filename_h
103-
wsjcpp_yml_unit_test_add user_class_name filename_cpp

src.wsjcpp/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Automaticly generated by wsjcpp@v0.1.7
22
cmake_minimum_required(VERSION 3.0)
33

4-
add_definitions(-DWSJCPP_APP_VERSION="v0.2.0")
4+
add_definitions(-DWSJCPP_APP_VERSION="v0.2.1")
55
add_definitions(-DWSJCPP_APP_NAME="wsjcpp-core")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

src/wsjcpp_core.cpp

+118
Original file line numberDiff line numberDiff line change
@@ -1213,4 +1213,122 @@ void WsjcppLog::add(WsjcppColorModifier &clr, const std::string &sType, const st
12131213
}
12141214
}
12151215

1216+
// ---------------------------------------------------------------------
1217+
// WsjcppResourceFile
1218+
1219+
WsjcppResourceFile::WsjcppResourceFile() {
1220+
WsjcppResourcesManager::add(this);
1221+
}
1222+
1223+
// ---------------------------------------------------------------------
1224+
1225+
1226+
// ---------------------------------------------------------------------
1227+
// WsjcppResourcesManager
1228+
1229+
std::vector<WsjcppResourceFile*> *g_pWsjcppResourceFiles = nullptr;
1230+
1231+
void WsjcppResourcesManager::initGlobalVariables() {
1232+
if (g_pWsjcppResourceFiles == nullptr) {
1233+
g_pWsjcppResourceFiles = new std::vector<WsjcppResourceFile*>();
1234+
}
1235+
}
1236+
1237+
// ---------------------------------------------------------------------
1238+
1239+
void WsjcppResourcesManager::add(WsjcppResourceFile* pStorage) {
1240+
WsjcppResourcesManager::initGlobalVariables();
1241+
g_pWsjcppResourceFiles->push_back(pStorage);
1242+
}
1243+
1244+
// ---------------------------------------------------------------------
1245+
1246+
bool WsjcppResourcesManager::has(const std::string &sFilename) {
1247+
WsjcppResourcesManager::initGlobalVariables();
1248+
for (int i = 0; i < WsjcppResourcesManager::list().size(); i++) {
1249+
if (WsjcppResourcesManager::list()[i]->getFilename() == sFilename) {
1250+
return true;
1251+
}
1252+
}
1253+
return false;
1254+
}
1255+
1256+
// ---------------------------------------------------------------------
1257+
1258+
WsjcppResourceFile* WsjcppResourcesManager::get(const std::string &sFilename) {
1259+
WsjcppResourcesManager::initGlobalVariables();
1260+
for (int i = 0; i < WsjcppResourcesManager::list().size(); i++) {
1261+
if (WsjcppResourcesManager::list()[i]->getFilename() == sFilename) {
1262+
return WsjcppResourcesManager::list()[i];
1263+
}
1264+
}
1265+
return nullptr;
1266+
}
1267+
1268+
// ---------------------------------------------------------------------
1269+
1270+
const std::vector<WsjcppResourceFile*> &WsjcppResourcesManager::list() {
1271+
return *g_pWsjcppResourceFiles;
1272+
}
1273+
1274+
// ---------------------------------------------------------------------
1275+
1276+
/*
1277+
bool WsjcppResourcesManager::make(const std::string &sWorkspace) {
1278+
if (!WsjcppResourcesManager::createFolders(sWorkspace)) {
1279+
return false;
1280+
}
1281+
return WsjcppResourcesManager::extractFiles(sWorkspace);
1282+
}
1283+
1284+
// ---------------------------------------------------------------------
1285+
1286+
bool WsjcppResourcesManager::createFolders(const std::string &sWorkspace) {
1287+
// prepare folders
1288+
std::vector<std::string> vCreateDirs;
1289+
vCreateDirs.push_back(sWorkspace + "/logs");
1290+
vCreateDirs.push_back(sWorkspace + "/teams");
1291+
vCreateDirs.push_back(sWorkspace + "/checkers");
1292+
vCreateDirs.push_back(sWorkspace + "/html");
1293+
vCreateDirs.push_back(sWorkspace + "/html/css");
1294+
vCreateDirs.push_back(sWorkspace + "/html/js");
1295+
vCreateDirs.push_back(sWorkspace + "/html/images");
1296+
vCreateDirs.push_back(sWorkspace + "/html/images/teams");
1297+
vCreateDirs.push_back(sWorkspace + "/html/images/states");
1298+
1299+
for(int i = 0; i < vCreateDirs.size(); i++) {
1300+
std::string sPath = vCreateDirs[i];
1301+
// check dir existing
1302+
if (!FS::dirExists(sPath)) {
1303+
// try make dir
1304+
if (!FS::makeDir(sPath)) {
1305+
std::cout << "Could not create folder " << sPath << std::endl;
1306+
return false;
1307+
} else {
1308+
std::cout << "Created folder " << sPath << std::endl;
1309+
}
1310+
}
1311+
}
1312+
return true;
1313+
}
1314+
1315+
// ---------------------------------------------------------------------
1316+
1317+
bool WsjcppResourcesManager::extractFiles(const std::string &sWorkspace) {
1318+
// TODO mkdir -p for files
1319+
const std::vector<WsjcppResourceFile*> list = WsjcppResourcesManager::list();
1320+
for(int i = 0; i < list.size(); i++) {
1321+
std::string sFilename = sWorkspace + "/" + list[i]->filename();
1322+
if (!FS::fileExists(sFilename)) {
1323+
if (!FS::writeFile(sFilename, list[i]->buffer(), list[i]->bufferSize())) {
1324+
std::cout << "Could not write file " << sFilename << std::endl;
1325+
return false;
1326+
} else {
1327+
std::cout << "Created file " << sFilename << std::endl;
1328+
}
1329+
}
1330+
}
1331+
return true;
1332+
}
1333+
*/
12161334

src/wsjcpp_core.h

+36
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,42 @@ class WsjcppLog {
194194
static void add(WsjcppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage);
195195
};
196196

197+
// ---------------------------------------------------------------------
198+
// WsjcppResourceFile
199+
200+
class WsjcppResourceFile {
201+
public:
202+
WsjcppResourceFile();
203+
virtual const std::string &getFilename() const = 0;
204+
virtual const std::string &getPackAs() const = 0;
205+
virtual int getBufferSize() const = 0;
206+
virtual const char *getBuffer() const = 0;
207+
};
208+
209+
210+
// ---------------------------------------------------------------------
211+
// WsjcppResourcesManager
212+
213+
extern std::vector<WsjcppResourceFile*> *g_pWsjcppResourceFiles;
214+
215+
class WsjcppResourcesManager {
216+
public:
217+
static void initGlobalVariables();
218+
static void add(WsjcppResourceFile*);
219+
static const std::vector<WsjcppResourceFile*> &list();
220+
static bool has(const std::string &sFilename);
221+
static WsjcppResourceFile* get(const std::string &sFilename);
222+
static bool make(const std::string &sWorkspace);
223+
// static bool createFolders(const std::string &sWorkspace);
224+
// static bool extractFiles(const std::string &sWorkspace);
225+
};
226+
227+
// ---------------------------------------------------------------------
228+
// Registry WsjcppResourceFile
229+
#define REGISTRY_WSJCPP_RESOURCE_FILE( classname ) \
230+
static classname * pRegistryWsjcppResourceFile ## classname = new classname(); \
231+
232+
197233
#endif // WSJCPP_CORE_H
198234

199235

0 commit comments

Comments
 (0)