File tree Expand file tree Collapse file tree 3 files changed +89
-4
lines changed Expand file tree Collapse file tree 3 files changed +89
-4
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,11 @@ project(design_patterns)
4
4
set (CMAKE_CXX_STANDARD 17)
5
5
FIND_PACKAGE (Boost 1.67.0 REQUIRED)
6
6
7
- set (CMAKE_CXX_FLAGS "-fsanitize=address -ggdb3 -Wall -Wextra" )
7
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -ggdb3 -Wall -Wextra" )
8
+
8
9
add_definitions (-std=c++17)
9
10
add_definitions (-DCMAKE_BUILD_TYPE=Debug)
10
11
11
- set (CXX_FLAGS "-fsanitize=address -ggdb3 -Wall -Wextra" )
12
-
13
12
add_subdirectory (Udemy)
14
13
15
14
# creational
Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ project(builder)
2
2
3
3
#add_executable(motivation src/motivation_demo.cpp)
4
4
#add_executable(motivation_v1 src/motivation_improved_v1.cpp)
5
- add_executable (fluent_builder src/fluent_builder.cpp)
5
+ #add_executable(fluent_builder src/fluent_builder.cpp)
6
+ add_executable (groovy_style_builder src/groovy_style_builder.cpp)
Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by sajith on 6/10/22.
3
+ //
4
+
5
+
6
+ #include < iostream>
7
+ #include < sstream>
8
+ #include < vector>
9
+ #include < memory>
10
+
11
+ using namespace std ;
12
+
13
+
14
+ struct Tag
15
+ {
16
+ string name;
17
+ string text;
18
+ vector<Tag> children;
19
+ vector<pair<string, string >> attributes;
20
+
21
+ friend ostream &operator <<(ostream &out, const Tag &tag)
22
+ {
23
+ out << " <" << tag.name ;
24
+
25
+ for (const auto &[first, second]: tag.attributes )
26
+ {
27
+ out << " " << first << " =\" " << second << " \" " ;
28
+ }
29
+
30
+ if (tag.children .empty () && tag.text .empty ())
31
+ {
32
+ out << " />" << endl;
33
+ }
34
+ else
35
+ {
36
+ out << " >" << endl;
37
+ if (!tag.text .empty ())
38
+ {
39
+ out << tag.text << endl;
40
+ }
41
+
42
+ for (const auto &child: tag.children )
43
+ {
44
+ out << child;
45
+ }
46
+ out << " </" << tag.name << " >" << endl;
47
+ }
48
+ return out;
49
+ }
50
+
51
+ protected:
52
+
53
+ public:
54
+
55
+ Tag (const string &n, const string &t) : name{n}, text{text} {}
56
+
57
+ Tag (const string &n, const vector<Tag> &c) : name{n}, children(c) {}
58
+ };
59
+
60
+ struct P : Tag
61
+ {
62
+ P (const string &text) : Tag{" p" , text} {}
63
+
64
+ P (initializer_list<Tag> children) : Tag{" p" , children} {}
65
+ };
66
+
67
+ struct IMG : Tag
68
+ {
69
+ explicit IMG (const string &url) : Tag{" img" , " " }
70
+ {
71
+ attributes.emplace_back (make_pair (" src" , url));
72
+ }
73
+ };
74
+
75
+ int main ()
76
+ {
77
+ cout <<
78
+ P{
79
+ IMG{" http.example.com/image.png" }
80
+ }
81
+ << endl;
82
+
83
+ return 0 ;
84
+ }
85
+
You can’t perform that action at this time.
0 commit comments