Compare commits
5 Commits
7ac9576710
...
3928379d6f
Author | SHA1 | Date | |
---|---|---|---|
3928379d6f | |||
45bfeca806 | |||
8e7f3d1bb0 | |||
2cd107225b | |||
2f5dee3406 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.build/
|
||||||
|
.cache/
|
||||||
|
bin/
|
||||||
|
compile_commands.json
|
@ -17,7 +17,15 @@
|
|||||||
cmake
|
cmake
|
||||||
ninja
|
ninja
|
||||||
sccache
|
sccache
|
||||||
|
|
||||||
|
# pre-commit
|
||||||
|
pre-commit
|
||||||
|
commitizen
|
||||||
];
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
pre-commit install --allow-missing-config --hook-type pre-commit --hook-type commit-msg
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
29
.pre-commit-config.yaml
Normal file
29
.pre-commit-config.yaml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/commitizen-tools/commitizen
|
||||||
|
rev: v3.15.0
|
||||||
|
hooks:
|
||||||
|
- id: commitizen
|
||||||
|
stages: [commit-msg]
|
||||||
|
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
|
rev: v4.0.0-alpha.8
|
||||||
|
hooks:
|
||||||
|
- id: prettier
|
||||||
|
name: check markdown/yaml formatting
|
||||||
|
types_or:
|
||||||
|
- markdown
|
||||||
|
- yaml
|
||||||
|
args: [--no-config]
|
||||||
|
exclude: CHANGELOG.md
|
||||||
|
|
||||||
|
- repo: https://github.com/pocc/pre-commit-hooks
|
||||||
|
rev: v1.3.5
|
||||||
|
hooks:
|
||||||
|
- id: clang-format
|
||||||
|
- id: clang-tidy
|
||||||
|
|
||||||
|
- repo: https://github.com/cheshirekow/cmake-format-precommit
|
||||||
|
rev: v0.6.13
|
||||||
|
hooks:
|
||||||
|
- id: cmake-format
|
||||||
|
- id: cmake-lint
|
21
Builder/CMakeLists.txt
Normal file
21
Builder/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
project(
|
||||||
|
Builder
|
||||||
|
VERSION 0.1.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../cmake")
|
||||||
|
|
||||||
|
include(ExportCompileCommands)
|
||||||
|
include(sccache)
|
||||||
|
|
||||||
|
add_executable(Builder main.cpp)
|
||||||
|
|
||||||
|
target_compile_features(Builder PUBLIC cxx_std_20)
|
||||||
|
|
||||||
|
set_target_properties(
|
||||||
|
Builder
|
||||||
|
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
|
4
Builder/bootstrap.sh
Executable file
4
Builder/bootstrap.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
cmake -S . -B .build -G Ninja -D CMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
ln -s .build/compile_commands.json
|
3
Builder/build.sh
Executable file
3
Builder/build.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
cmake --build .build
|
8
Builder/main.cpp
Normal file
8
Builder/main.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
std::cout << "Builder" << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
21
Singleton/CMakeLists.txt
Normal file
21
Singleton/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
project(
|
||||||
|
Singleton
|
||||||
|
VERSION 0.1.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../cmake")
|
||||||
|
|
||||||
|
include(ExportCompileCommands)
|
||||||
|
include(sccache)
|
||||||
|
|
||||||
|
add_executable(Singleton main.cpp)
|
||||||
|
|
||||||
|
target_compile_features(Singleton PUBLIC cxx_std_20)
|
||||||
|
|
||||||
|
set_target_properties(
|
||||||
|
Singleton
|
||||||
|
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
|
4
Singleton/bootstrap.sh
Executable file
4
Singleton/bootstrap.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
cmake -S . -B .build -G Ninja -D CMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
ln -s .build/compile_commands.json
|
3
Singleton/build.sh
Executable file
3
Singleton/build.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
cmake --build .build
|
42
Singleton/main.cpp
Normal file
42
Singleton/main.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include <cstdlib>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
class Singleton {
|
||||||
|
private:
|
||||||
|
static Singleton *singleton;
|
||||||
|
static std::mutex mutex;
|
||||||
|
|
||||||
|
Singleton() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Singleton(const Singleton &other) = delete;
|
||||||
|
Singleton &operator=(const Singleton &) = delete;
|
||||||
|
|
||||||
|
static Singleton *GetInstance() {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
|
||||||
|
if (singleton == nullptr) {
|
||||||
|
singleton = new Singleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Singleton *Singleton::singleton = nullptr;
|
||||||
|
std::mutex Singleton::mutex;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
std::cout << "Singleton" << std::endl;
|
||||||
|
|
||||||
|
auto singleton1 = Singleton::GetInstance();
|
||||||
|
auto singleton2 = Singleton::GetInstance();
|
||||||
|
|
||||||
|
std::cout << std::setw(20) << "Singleton 1: " << singleton1 << std::endl;
|
||||||
|
std::cout << std::setw(20) << "Singleton 2: " << singleton2 << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Reference in New Issue
Block a user