リビジョン | 1e4997fec143b6c9079499f41ec6d9a4bb7a6d8c (tree) |
---|---|
日時 | 2020-11-19 23:04:22 |
作者 | dhrname <dhrname@user...> |
コミッター | dhrname |
Start Joestar project
@@ -0,0 +1,16 @@ | ||
1 | +CC = clang++ | |
2 | +DEBUGMODE = -std=c++20 -O0 -g -pg | |
3 | +NODEBUGMODE = -std=c++20 | |
4 | +SHELL = /bin/sh | |
5 | + | |
6 | + | |
7 | +all : main joestar.exe | |
8 | +.PHONY : all | |
9 | + | |
10 | + | |
11 | +joestar.exe: main.cpp | |
12 | + $(CC) $(NODEBUGMODE) $^ -o ../bin/$@ | |
13 | + | |
14 | + | |
15 | +clean: | |
16 | + rm -f startest.o star.o $(OBJECT) |
@@ -0,0 +1,118 @@ | ||
1 | +/* | |
2 | + * main.cpp | |
3 | + * | |
4 | + * Copyright 2020 dhrname <dhrname@MOUSE> | |
5 | + * | |
6 | + * This program is free software; you can redistribute it and/or modify | |
7 | + * it under the terms of the GNU General Public License as published by | |
8 | + * the Free Software Foundation; either version 2 of the License, or | |
9 | + * (at your option) any later version. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU General Public License | |
17 | + * along with this program; if not, write to the Free Software | |
18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | + * MA 02110-1301, USA. | |
20 | + * | |
21 | + * | |
22 | + */ | |
23 | + | |
24 | +#include <iostream> | |
25 | +#include <string> | |
26 | + | |
27 | +/*Nodeの抽象クラス | |
28 | + * 5方向リンクのリスト | |
29 | + * これを型として使う。*/ | |
30 | +class Node | |
31 | +{ | |
32 | +public: | |
33 | + virtual Node* getParent() = 0; | |
34 | + virtual Node* getNext() = 0; | |
35 | + virtual Node* getPrev() = 0; | |
36 | + virtual Node* getFirstChild() = 0; | |
37 | + virtual Node* getLastChild() = 0; | |
38 | + virtual Node* insertBefore(Node*) = 0; | |
39 | + virtual Node* appendChild(Node*) = 0; | |
40 | + virtual bool isNode() const = 0; | |
41 | +}; | |
42 | + | |
43 | +/*空のノードクラス*/ | |
44 | +class EmptyNode: public Node | |
45 | +{ | |
46 | +public: | |
47 | + Node* getParent(){return this;}; | |
48 | + Node* getNext(){return this;}; | |
49 | + Node* getPrev(){return this;}; | |
50 | + Node* getFirstChild(){return this;}; | |
51 | + Node* getLastChild(){return this;}; | |
52 | + Node* insertBefore(Node*){return this;}; | |
53 | + Node* appendChild(Node*){return this;}; | |
54 | + bool isNode() const | |
55 | + { | |
56 | + return false; | |
57 | + } | |
58 | +}; | |
59 | + | |
60 | +Node* const emptynode = new EmptyNode(); | |
61 | + | |
62 | +/*BaseNodeの基底クラス | |
63 | + * Node抽象クラスに対する内部実装*/ | |
64 | +class BaseNode: public Node | |
65 | +{ | |
66 | +private: | |
67 | + Node* parentNode; | |
68 | + Node* nextSibling; | |
69 | + Node* previousSibling; | |
70 | + Node* firstChild; | |
71 | + Node* lastChild; | |
72 | + | |
73 | +public: | |
74 | + BaseNode() | |
75 | + : parentNode(emptynode), | |
76 | + nextSibling(emptynode), | |
77 | + previousSibling(emptynode), | |
78 | + firstChild(emptynode), | |
79 | + lastChild(emptynode) | |
80 | + {} | |
81 | + | |
82 | + virtual ~BaseNode(){} | |
83 | + | |
84 | + virtual void setParent(Node* node); | |
85 | + virtual void setNext(Node* node); | |
86 | + virtual void setPrev(Node* node); | |
87 | + virtual void setFirstChild(Node* node); | |
88 | + virtual void setLastChild(Node* node); | |
89 | + bool isNode() | |
90 | + { | |
91 | + return true; | |
92 | + } | |
93 | +}; | |
94 | + | |
95 | + | |
96 | + | |
97 | +void BaseNode::setParent(Node* node){ | |
98 | + parentNode = node; | |
99 | +} | |
100 | +void BaseNode::setNext(Node* node){ | |
101 | + nextSibling = node; | |
102 | +} | |
103 | +void BaseNode::setPrev(Node* node){ | |
104 | + previousSibling = node; | |
105 | +} | |
106 | +void BaseNode::setFirstChild(Node* node){ | |
107 | + firstChild = node; | |
108 | +} | |
109 | +void BaseNode::setLastChild(Node* node){ | |
110 | + lastChild = node; | |
111 | +} | |
112 | + | |
113 | +int main(int argc, char **argv) | |
114 | +{ | |
115 | + std::string str1 = "ABCDE"; | |
116 | + std::cout << str1 << std::endl; | |
117 | + return 0; | |
118 | +} |