Skip to content

Commit 9d7a691

Browse files
committed
整理;
0 parents  commit 9d7a691

29 files changed

+1624
-0
lines changed

.clang-format

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
BasedOnStyle: LLVM
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: DontAlign
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
AllowShortBlocksOnASingleLine: true
12+
AllowShortCaseLabelsOnASingleLine: true
13+
AllowShortFunctionsOnASingleLine: Inline
14+
AllowShortIfStatementsOnASingleLine: false
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: false
18+
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BraceWrapping:
22+
AfterClass: true
23+
AfterControlStatement: false
24+
AfterEnum: false
25+
AfterFunction: true
26+
AfterNamespace: false
27+
AfterObjCDeclaration: false
28+
AfterStruct: true
29+
AfterUnion: false
30+
AfterExternBlock: false
31+
BeforeCatch: false
32+
BeforeElse: false
33+
IndentBraces: false
34+
SplitEmptyFunction: false
35+
SplitEmptyRecord: false
36+
SplitEmptyNamespace: false
37+
BreakAfterJavaFieldAnnotations: false
38+
BreakBeforeBinaryOperators: All
39+
BreakBeforeBraces: Custom
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializers: BeforeComma
42+
BreakInheritanceList: BeforeColon
43+
BreakStringLiterals: true
44+
ColumnLimit: 100
45+
CommentPragmas: '^ IWYU pragma:'
46+
CompactNamespaces: false
47+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
48+
ConstructorInitializerIndentWidth: 4
49+
ContinuationIndentWidth: 4
50+
Cpp11BracedListStyle: true
51+
DerivePointerAlignment: false
52+
DisableFormat: false
53+
ExperimentalAutoDetectBinPacking: false
54+
FixNamespaceComments: true
55+
ForEachMacros:
56+
- forever
57+
- foreach
58+
- BOOST_FOREACH
59+
IncludeBlocks: Preserve
60+
IncludeCategories:
61+
- Regex: '^<Q.*'
62+
Priority: 200
63+
SortPriority: 0
64+
IncludeIsMainRegex: '(Test)?$'
65+
IndentCaseLabels: false
66+
IndentPPDirectives: None
67+
IndentWidth: 4
68+
IndentWrappedFunctionNames: false
69+
JavaScriptQuotes: Leave
70+
JavaScriptWrapImports: true
71+
KeepEmptyLinesAtTheStartOfBlocks: false
72+
Language: Cpp
73+
MacroBlockBegin: ''
74+
MacroBlockEnd: ''
75+
MaxEmptyLinesToKeep: 1
76+
NamespaceIndentation: None
77+
ObjCBinPackProtocolList: Auto
78+
ObjCBlockIndentWidth: 4
79+
ObjCSpaceAfterProperty: false
80+
ObjCSpaceBeforeProtocolList: true
81+
PenaltyBreakAssignment: 150
82+
PenaltyBreakBeforeFirstCallParameter: 300
83+
PenaltyBreakComment: 500
84+
PenaltyBreakFirstLessLess: 400
85+
PenaltyBreakString: 600
86+
PenaltyBreakTemplateDeclaration: 10
87+
PenaltyExcessCharacter: 50
88+
PenaltyReturnTypeOnItsOwnLine: 300
89+
PointerAlignment: Right
90+
ReflowComments: false
91+
SortIncludes: true
92+
SortUsingDeclarations: true
93+
SpaceAfterCStyleCast: true
94+
SpaceAfterTemplateKeyword: false
95+
SpaceBeforeAssignmentOperators: true
96+
SpaceBeforeCpp11BracedList: false
97+
SpaceBeforeCtorInitializerColon: true
98+
SpaceBeforeInheritanceColon: true
99+
SpaceBeforeParens: ControlStatements
100+
SpaceBeforeRangeBasedForLoopColon: true
101+
SpaceInEmptyParentheses: false
102+
SpacesBeforeTrailingComments: 1
103+
SpacesInAngles: false
104+
SpacesInCStyleCastParentheses: false
105+
SpacesInContainerLiterals: false
106+
SpacesInParentheses: false
107+
SpacesInSquareBrackets: false
108+
TabWidth: 4
109+
UseTab: Never

.github/workflows/build.yml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: CMake Build
2+
3+
on:
4+
# push代码时触发workflow
5+
push:
6+
paths-ignore: # 下列文件的变更不触发部署,可以自行添加
7+
- '.clang-format'
8+
- '.gitignore'
9+
- 'LICENSE'
10+
- 'README*'
11+
pull_request:
12+
paths-ignore: # 下列文件的变更不触发部署,可以自行添加
13+
- '.clang-format'
14+
- '.gitignore'
15+
- 'LICENSE'
16+
- 'README*'
17+
18+
jobs:
19+
build:
20+
name: Build
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os:
26+
- windows-latest
27+
- macos-latest
28+
- ubuntu-latest
29+
build_type:
30+
- "Release"
31+
generators:
32+
- "Ninja"
33+
34+
steps:
35+
- name: cache vcpkg
36+
uses: actions/cache@v3
37+
with:
38+
path: |
39+
C:\vcpkg\installed
40+
/usr/local/share/vcpkg/installed
41+
key: ${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-${{ github.sha }}
42+
restore-keys: |
43+
${{ runner.os }}-vcpkg-installed-${{ matrix.os }}-
44+
${{ runner.os }}-vcpkg-installed-
45+
- name: Install dependencies on windows
46+
if: startsWith(matrix.os, 'windows')
47+
run: |
48+
choco install ninja
49+
ninja --version
50+
cmake --version
51+
vcpkg install glog --triplet x64-windows
52+
- name: Install dependencies on macos
53+
if: startsWith(matrix.os, 'macos')
54+
shell: bash
55+
run: |
56+
brew install ninja
57+
ninja --version
58+
cmake --version
59+
clang --version
60+
vcpkg install glog --triplet x64-osx
61+
- name: Install dependencies on ubuntu
62+
if: startsWith(matrix.os, 'ubuntu')
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install ninja-build
66+
ninja --version
67+
cmake --version
68+
gcc --version
69+
vcpkg install glog --triplet x64-linux
70+
71+
- uses: actions/checkout@v3
72+
with:
73+
fetch-depth: 1
74+
75+
- name: Configure Windows
76+
if: startsWith(matrix.os, 'windows')
77+
shell: bash
78+
run: |
79+
cmake \
80+
-S . \
81+
-B ./build \
82+
-A x64 \
83+
-DCMAKE_INSTALL_PREFIX:PATH=instdir
84+
- name: Configure macos or ubuntu
85+
if: startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu')
86+
shell: bash
87+
run: |
88+
cmake \
89+
-S . \
90+
-B ./build \
91+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
92+
-G "${{ matrix.generators }}" \
93+
-DCMAKE_INSTALL_PREFIX:PATH=instdir
94+
- name: Build
95+
shell: bash
96+
run: |
97+
cmake --build ./build --config ${{ matrix.build_type }}
98+

.gitignore

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Specific files
35+
.vscode
36+
build
37+
bin-*

CMakeLists.txt

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# 设定版本号
2+
cmake_minimum_required(VERSION 3.5)
3+
4+
if(CMAKE_HOST_WIN32)
5+
set(CMAKE_TOOLCHAIN_FILE
6+
"C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
7+
CACHE STRING "Vcpkg toolchain file")
8+
elseif(CMAKE_HOST_APPLE)
9+
set(CMAKE_TOOLCHAIN_FILE
10+
"/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake"
11+
CACHE STRING "Vcpkg toolchain file")
12+
elseif(CMAKE_HOST_UNIX)
13+
set(CMAKE_TOOLCHAIN_FILE
14+
"/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake"
15+
CACHE STRING "Vcpkg toolchain file")
16+
endif()
17+
18+
# 设定工程名
19+
project(
20+
Cpp-Example
21+
VERSION 0.1
22+
LANGUAGES C CXX)
23+
24+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
25+
26+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
27+
set(CMAKE_CURRENT_SOURCE_DIR ON)
28+
29+
# set(CMAKE_CXX_FLAGS_DEBUG "-O0") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
30+
31+
set(CMAKE_CXX_STANDARD 17)
32+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33+
34+
set(CMAKE_DEBUG_POSTFIX d)
35+
36+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
37+
message("Setting build type to 'RelWithDebInfo' as none was specified.")
38+
set(CMAKE_BUILD_TYPE
39+
RelWithDebInfo
40+
CACHE STRING "Choose the type of build." FORCE)
41+
# Set the possible values of build type for cmake-gui
42+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
43+
"MinSizeRel" "RelWithDebInfo")
44+
endif()
45+
46+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
47+
set(CURRENT_PLATFORM "-64")
48+
else()
49+
set(CURRENT_PLATFORM "-32")
50+
endif()
51+
52+
message(STATUS "Current Platform is ${CURRENT_PLATFORM}")
53+
54+
# 设定可执行二进制文件的目录
55+
set(EXECUTABLE_OUTPUT_PATH
56+
${PROJECT_SOURCE_DIR}/bin${CURRENT_PLATFORM}/${CMAKE_BUILD_TYPE}) # 源文件目录
57+
# SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) #输出文件目录
58+
59+
# 设定存放编译出来的库文件的目录
60+
set(LIBRARY_OUTPUT_PATH
61+
${PROJECT_SOURCE_DIR}/lib${CURRENT_PLATFORM}/${CMAKE_BUILD_TYPE})
62+
# SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
63+
64+
# 并且把该目录设为连接目录
65+
link_directories(
66+
${PROJECT_SOURCE_DIR}/lib${CURRENT_PLATFORM}/${CMAKE_BUILD_TYPE})
67+
# LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lib)
68+
69+
include_directories(${PROJECT_SOURCE_DIR})
70+
71+
message("CMAKE_MAJOR_VERSION: ${CMAKE_MAJOR_VERSION}")
72+
message("CMAKE_MINOR_VERSION: ${CMAKE_MINOR_VERSION}")
73+
message("CMAKE_PATCH_VERSION: ${CMAKE_PATCH_VERSION}")
74+
message("CMAKE_TWEAK_VERSION: ${CMAKE_TWEAK_VERSION}")
75+
message("CMAKE_VERSION: ${CMAKE_VERSION}")
76+
message("CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
77+
message("CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}")
78+
message("CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
79+
80+
find_package(glog CONFIG REQUIRED)
81+
if(glog_FOUND)
82+
message(STATUS "found glog")
83+
endif()
84+
85+
add_subdirectory(DesignPattern)
86+
add_subdirectory(Glog)
87+
add_subdirectory(Mutex)

DesignPattern/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_subdirectory(Factory)
2+
add_subdirectory(MVC)
3+
add_subdirectory(Observer)
4+
add_subdirectory(Singleton)

DesignPattern/Factory/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_executable(Factory main.cpp factory.cc factory.hpp)

DesignPattern/Factory/factory.cc

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "factory.hpp"
2+
3+
#include <iostream>
4+
5+
Factory::Factory() {}
6+
7+
Factory::~Factory()
8+
{
9+
std::cout << "~Factory" << std::endl;
10+
}
11+
12+
void Factory::name()
13+
{
14+
std::cout << "Factory" << std::endl;
15+
}
16+
17+
class ComputerFactory : public Factory
18+
{
19+
public:
20+
ComputerFactory()
21+
: Factory()
22+
{}
23+
virtual ~ComputerFactory() { std::cout << "~ComputerFactory" << std::endl; }
24+
25+
virtual void name() { std::cout << "ComputerFactory" << std::endl; }
26+
};
27+
28+
class PhoneFactory : public Factory
29+
{
30+
public:
31+
PhoneFactory()
32+
: Factory()
33+
{}
34+
virtual ~PhoneFactory() { std::cout << "~PhoneFactory" << std::endl; }
35+
36+
virtual void name() { std::cout << "PhoneFactory" << std::endl; }
37+
};
38+
39+
Factory *createFactory(FactoryType type)
40+
{
41+
switch (type) {
42+
case Computer: return new ComputerFactory;
43+
case Phone: return new PhoneFactory;
44+
default: break;
45+
}
46+
return new Factory;
47+
}

0 commit comments

Comments
 (0)