Mini.Project 01-02. Deploy: Integrated CMake, Docker and CI/CD
Mini.Project 01-02. Deploy: Integrated CMake, Docker and CI/CD
Mini.Project 01-02. Deploy: Integrated CMake, Docker and CI/CD
Prerequisites
1
C++
1. Design of hierarchy
C++ Project
1
2
3
4
5
6
7
8
9
10
11
12
/Project:
- main.cpp
- /tests:
- test_svstring.cpp
- /lib:
- /structlib:
- /src:
- SVBase.cpp
- SVString.cpp
- /include:
- SVBase.h
- SVString.h
- Project/lib/structlib: Create a library (.lib)
- Project/lib: Collect multiple libraries
- Project/main.cpp: Entry point that depends on libraries
2. Design of this project
In this post, I create basic C++ code. The code don’t contain meaningful logic. So I will attach the last section.
I mainly explain the dependency between files.
- SVBase.cpp < SVBase.h
- SVString.cpp < SVString.h < SVBase.h
- main.cpp < SVString.h
- test_svstring.cpp < SVString.h
this meaning is:
- The SVBase cpp has independent from all of source
- The SVString cpp has dependent from SVBase class because of inheritance structure
- The main cpp has dependent from library that consists of SVBase and SVString
- The test_svstring cpp is same level of main cpp
3. Why I consist this hierarchy
The executable program can depend on multiple libraries. Therefore the main cpp depends on the library. Test program follows the same structure.
Libraries can be created and extended independently. Considering scalability, I seperated them /lib and sub-library directories such as /XXXlib
The source files of library can be dependent on each sources. Therefore I explicitly designed the dependency between source files
4. Code
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include "SVString.h"
int main()
{
CSVString str1;
str1.setSize(10);
std::cout << "Size of str1: " << str1.getSize() << std::endl;
std::cin.get();
return 0;
}
SVBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class CSVBase
{
public:
CSVBase();
CSVBase(const CSVBase& obj);
CSVBase(const CSVBase* pOj);
virtual ~CSVBase();
CSVBase& operator=(const CSVBase& obj);
public:
virtual bool clear();
bool assign(const CSVBase& obj);
bool assign(const CSVBase* pObj);
private:
static int m_i32ID;
};
SVString.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "SVBase.h"
class CSVString : CSVBase
{
public:
CSVString();
CSVString(const CSVString& obj);
CSVString(const CSVString* pOj);
virtual ~CSVString();
CSVString& operator=(const CSVString& obj);
public:
virtual bool clear() override;
bool assign(const CSVString& obj);
bool assign(const CSVString* pObj);
bool setSize(int i32Size);
int getSize();
private:
char* m_pS8String;
int m_i32Size;
};
SVBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "../include/SVBase.h"
int CSVBase::m_i32ID = 0;
CSVBase::CSVBase()
{
++m_i32ID;
clear();
}
CSVBase::CSVBase(const CSVBase& obj)
{
assign(obj);
}
CSVBase::CSVBase(const CSVBase* pObj)
{
assign(pObj);
}
CSVBase::~CSVBase()
{
clear();
}
CSVBase& CSVBase::operator=(const CSVBase& obj)
{
assign(obj);
return *this;
}
bool CSVBase::clear()
{
return true;
}
bool CSVBase::assign(const CSVBase& obj)
{
assign(&obj);
return true;
}
bool CSVBase::assign(const CSVBase* pObj)
{
bool bReturn = false;
do
{
if(!pObj)
break;
bReturn = true;
}
while(false);
return bReturn;
}
SVString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "../include/SVString.h"
#include <iostream>
CSVString::CSVString() : CSVBase()
{
m_pS8String = nullptr;
clear();
}
CSVString::CSVString(const CSVString& obj) : CSVBase(obj)
{
assign(obj);
}
CSVString::CSVString(const CSVString* pOj) : CSVBase(pOj)
{
assign(pOj);
}
CSVString::~CSVString()
{
clear();
}
CSVString& CSVString::operator=(const CSVString& obj)
{
CSVBase::operator=(obj);
assign(obj);
return *this;
}
bool CSVString::clear()
{
bool bReturn = false;
do
{
if(!CSVBase::clear())
break;
if(m_pS8String)
{
free(m_pS8String);
m_pS8String = nullptr;
}
bReturn = true;
}
while(false);
return bReturn;
}
bool CSVString::assign(const CSVString& obj)
{
return assign(&obj);
}
bool CSVString::assign(const CSVString* pObj)
{
bool bReturn = false;
do
{
if(!pObj)
break;
if(!CSVBase::assign(pObj))
break;
bReturn = true;
}
while(false);
return bReturn;
}
bool CSVString::setSize(int i32Size)
{
bool bReturn = false;
do
{
if(i32Size <= 0)
break;
if(m_pS8String)
{
free(m_pS8String);
m_pS8String = nullptr;
}
m_pS8String = (char*)malloc(sizeof(char) * i32Size);
if(!m_pS8String)
break;
m_i32Size = i32Size;
bReturn = true;
}
while(false);
return bReturn;
}
int CSVString::getSize()
{
return m_i32Size;
}
test_svstring.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include "SVString.h"
int main()
{
CSVString str;
int i32Size = 10;
str.setSize(i32Size);
if (str.getSize() != i32Size)
{
std::cerr << i32Size << "Test failed: expected 10\n" << str.getSize();
return 1;
}
std::cout << "Test passed\n";
return 0;
}
This post is licensed under CC BY 4.0 by the author.