Skip to content

Commit e7a6028

Browse files
committed
Updated wsjcpp-core and added generate.WsjcppEmploy
1 parent bf9665c commit e7a6028

19 files changed

+531
-321
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ project(wsjcpp-employees C CXX)
44

55
include(${CMAKE_CURRENT_SOURCE_DIR}/src.wsjcpp/CMakeLists.txt)
66

7+
#### BEGIN_WSJCPP_APPEND
8+
#### END_WSJCPP_APPEND
9+
710
set(CMAKE_CXX_STANDARD 11)
811
set(EXECUTABLE_OUTPUT_PATH ${wsjcpp-employees_SOURCE_DIR})
912

@@ -27,3 +30,4 @@ install(
2730
/usr/bin
2831
)
2932

33+

README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ or include this files:
2020

2121
## How use this
2222

23-
For init you must call `WSJCppEmployees::init({})`
23+
For init you must call `WsjcppEmployees::init({})`
2424

2525
Example main func:
2626
```
@@ -31,15 +31,15 @@ int main(int argc, const char* argv[]) {
3131
std::string TAG = "MAIN";
3232
std::string appName = std::string(WSJCPP_NAME);
3333
std::string appVersion = std::string(WSJCPP_VERSION);
34-
if (!WSJCppCore::dirExists(".logs")) {
35-
WSJCppCore::makeDir(".logs");
34+
if (!WsjcppCore::dirExists(".logs")) {
35+
WsjcppCore::makeDir(".logs");
3636
}
37-
WSJCppLog::setPrefixLogFile("wsjcpp-employees");
38-
WSJCppLog::setLogDirectory(".logs");
37+
WsjcppLog::setPrefixLogFile("wsjcpp-employees");
38+
WsjcppLog::setLogDirectory(".logs");
3939
4040
// init employees
41-
if (!WSJCppEmployees::init({})) {
42-
WSJCppLog::err(TAG, "Could not init employees");
41+
if (!WsjcppEmployees::init({})) {
42+
WsjcppLog::err(TAG, "Could not init employees");
4343
return -1;
4444
}
4545
return 0;
@@ -58,23 +58,29 @@ Now you can call from any place:
5858
#inluce <wsjcpp_employees.h>
5959
6060
void someFunc() {
61-
WJSCppEmployRuntimeGlobalCache *pCache = findWSJCppEmploy<WJSCppEmployRuntimeGlobalCache>();
61+
WJSCppEmployRuntimeGlobalCache *pCache = findWsjcppEmploy<WJSCppEmployRuntimeGlobalCache>();
6262
pCache->set("name", "value");
6363
}
6464
```
6565

66+
### Example of define you employ use a wsjcpp
67+
68+
```
69+
wsjcpp generate WsjcppEmploy MyImpl
70+
```
71+
6672
### Example of define you employ (simple)
6773

6874
(don't foget add to build)
6975

7076
Example Header `your_employ.h`:
7177
```
72-
#ifndef WSJCPP_EMPLOYEES_H
73-
#define WSJCPP_EMPLOYEES_H
78+
#ifndef YOUR_EMPLOY_H
79+
#define YOUR_EMPLOY_H
7480
7581
#include <wsjcpp_employees.h>
7682
77-
class YourEmploy : public WSJCppEmployBase {
83+
class YourEmploy : public WsjcppEmployBase {
7884
public:
7985
YourEmploy();
8086
static std::string name() { return "YourEmploy"; }
@@ -85,7 +91,7 @@ class YourEmploy : public WSJCppEmployBase {
8591
std::string TAG;
8692
};
8793
88-
#endif // WSJCPP_EMPLOYEES_H
94+
#endif // YOUR_EMPLOY_H
8995
```
9096

9197
Example source-code `your_employ.cpp`:
@@ -95,39 +101,39 @@ Example source-code `your_employ.cpp`:
95101
REGISTRY_WJSCPP_EMPLOY(YourEmploy)
96102
97103
YourEmploy::YourEmploy()
98-
: WSJCppEmployBase(YourEmploy::name(), {}) {
104+
: WsjcppEmployBase(YourEmploy::name(), {}) {
99105
TAG = YourEmploy::name();
100106
}
101107
102108
bool YourEmploy::init() {
103-
WSJCppLog::info(TAG, "init called");
109+
WsjcppLog::info(TAG, "init called");
104110
return true;
105111
}
106112
107113
bool YourEmploy::deinit() {
108-
WSJCppLog::info(TAG, "deinit called");
114+
WsjcppLog::info(TAG, "deinit called");
109115
return true;
110116
}
111117
112118
void YourEmploy::doSomething() {
113-
WSJCppLog::info(TAG, "doSomething called");
119+
WsjcppLog::info(TAG, "doSomething called");
114120
}
115121
```
116122

117-
1. For call ::init you must call `WSJCppEmployees::init({})` in main function
123+
1. For call ::init you must call `WsjcppEmployees::init({})` in main function
118124
2. find employ and call you method from any place
119125

120126
```
121127
#inluce <your_employ.h>
122128
123129
void someFunc() {
124-
YourEmploy *pYourEmploy = findWSJCppEmploy<YourEmploy>();
130+
YourEmploy *pYourEmploy = findWsjcppEmploy<YourEmploy>();
125131
pYourEmploy->doSomething();
126132
}
127133
128134
void main() {
129135
...
130-
WSJCppEmployees::init({});
136+
WsjcppEmployees::init({});
131137
someFunc();
132138
}
133139
```
@@ -140,7 +146,7 @@ void main() {
140146
141147
// second - will be init after
142148
SecondEmploy::SecondEmploy()
143-
: WSJCppEmployBase(SecondEmploy::name(), {"FirstEmploy"}) {
149+
: WsjcppEmployBase(SecondEmploy::name(), {"FirstEmploy"}) {
144150
TAG = SecondEmploy::name();
145151
}
146152
@@ -150,7 +156,7 @@ bool SecondEmploy::init() {
150156
151157
// first employ - will be init every time
152158
FirstEmploy::FirstEmploy()
153-
: WSJCppEmployBase(FirstEmploy::name(), {}) {
159+
: WsjcppEmployBase(FirstEmploy::name(), {}) {
154160
TAG = FirstEmploy::name();
155161
}
156162
@@ -171,7 +177,7 @@ UsersEmploy
171177

172178
Also you can define on init:
173179
```
174-
WSJCppEmployees::init({"server-start"})
180+
WsjcppEmployees::init({"server-start"})
175181
```
176182
So it will be call "::init" employees only there which has this requirements.
177183

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/wsjcpp-safe-scripting
2+
3+
# log_info rootdir
4+
# log_info script_filename
5+
6+
make_dir "src"
7+
8+
var employ_name
9+
set_value employ_name arg1
10+
normalize_class_name employ_name
11+
convert_CamelCase_to_snake_case employ_name employ_name
12+
13+
var class_name
14+
concat class_name "Employ" arg1
15+
normalize_class_name class_name
16+
17+
var base_filename
18+
convert_CamelCase_to_snake_case class_name base_filename
19+
# log_info base_filename
20+
21+
var filename_cpp
22+
concat filename_cpp "./src/" base_filename ".cpp"
23+
24+
var filename_h
25+
concat filename_h "./src/" base_filename ".h"
26+
27+
var ifndef_header
28+
set_value ifndef_header base_filename
29+
concat ifndef_header "_H"
30+
31+
to_upper_case ifndef_header
32+
33+
var content_header
34+
concat content_header "#ifndef " ifndef_header "
35+
#define " ifndef_header "
36+
37+
#include <wsjcpp_employees.h>
38+
39+
class " class_name " : public WsjcppEmployBase {
40+
public:
41+
" class_name "();
42+
static std::string name() { return \"" class_name "\"; }
43+
virtual bool init() override;
44+
virtual bool deinit() override;
45+
46+
private:
47+
std::string TAG;
48+
};
49+
50+
#endif // " ifndef_header
51+
52+
53+
var content_source
54+
concat content_source "
55+
#include \"" base_filename ".h\"
56+
#include <wsjcpp_core.h>
57+
58+
// ---------------------------------------------------------------------
59+
// " class_name "
60+
61+
REGISTRY_WJSCPP_EMPLOY(" class_name ")
62+
63+
" class_name "::" class_name "()
64+
: WsjcppEmployBase(" class_name "::name(), {}) {
65+
TAG = " class_name "::name();
66+
}
67+
68+
// ---------------------------------------------------------------------
69+
70+
bool " class_name "::init() {
71+
WsjcppLog::info(TAG, \"init\");
72+
return true;
73+
}
74+
75+
// ---------------------------------------------------------------------
76+
77+
bool " class_name "::deinit() {
78+
WsjcppLog::info(TAG, \"deinit\");
79+
return true;
80+
}
81+
82+
"
83+
84+
var file_source
85+
concat file_source "src/" filename_cpp
86+
87+
write_file filename_h content_header
88+
write_file filename_cpp content_source
89+
90+
log_info "
91+
======
92+
Generated class:
93+
- " class_name "
94+
Generated files:
95+
- " filename_h "
96+
- " filename_cpp "
97+
======
98+
"
99+
100+
cmakelists_txt_append_wsjcpp filename_h
101+
cmakelists_txt_append_wsjcpp filename_cpp

src.wsjcpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set (WSJCPP_SOURCES "")
1717
find_package(Threads REQUIRED)
1818
list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
1919

20-
# wsjcpp-core:v0.0.8
20+
# wsjcpp-core:v0.1.1
2121
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_core/")
2222
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
2323
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.h")

src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_cxx_standard: 11
33
cmake_minimum_required: 3.0
44

55
name: wsjcpp-core
6-
version: v0.0.8
6+
version: v0.1.1
77
description: Basic Utils for wsjcpp
88
issues: https://github.com/wsjcpp/wsjcpp-core/issues
99
repositories:
@@ -64,3 +64,7 @@ unit-tests:
6464
description: "Test create empty file"
6565
- name: "ReadFileToBuffer"
6666
description: "test for readFileToBuffer"
67+
- name: "Join"
68+
description: "Test join function"
69+
- name: "getHumanSizeBytes"
70+
description: "Test function get human size in bytes"

0 commit comments

Comments
 (0)