Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xorz57/servicelocator
Service Locator written in C++11
https://github.com/xorz57/servicelocator
cpp service-locator service-locator-pattern
Last synced: about 1 month ago
JSON representation
Service Locator written in C++11
- Host: GitHub
- URL: https://github.com/xorz57/servicelocator
- Owner: xorz57
- License: mit
- Created: 2023-05-09T19:55:44.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-17T09:14:15.000Z (10 months ago)
- Last Synced: 2024-03-17T10:26:36.905Z (10 months ago)
- Topics: cpp, service-locator, service-locator-pattern
- Language: C++
- Homepage: https://xorz57.github.io/ServiceLocator
- Size: 183 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ServiceLocator
[![Build](https://github.com/xorz57/ServiceLocator/actions/workflows/Build.yml/badge.svg)](https://github.com/xorz57/ServiceLocator/actions/workflows/Build.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xorz57_ServiceLocator&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=xorz57_ServiceLocator)## Example
```cpp
#include "ServiceLocator/ServiceLocator.hpp"#include
class A {
public:
A() {
std::cout << __func__ << std::endl;
}
~A() {
std::cout << __func__ << std::endl;
}A(const A &other) = delete;
A(A &&other) = delete;A &operator=(const A &other) = delete;
A &operator=(A &&other) = delete;
};class B {
public:
B() {
std::cout << __func__ << std::endl;
}
~B() {
std::cout << __func__ << std::endl;
}B(const B &other) = delete;
B(B &&other) = delete;B &operator=(const B &other) = delete;
B &operator=(B &&other) = delete;
};int main() {
service_locator_t sl;sl.set_instance();
sl.set_instance();std::cout << sl.get_instance() << std::endl;
std::cout << sl.get_instance() << std::endl;std::cout << sl.get_instance() << std::endl;
std::cout << sl.get_instance() << std::endl;sl.clear();
std::cout << sl.get_instance() << std::endl;
std::cout << sl.get_instance() << std::endl;return 0;
}
```## Output
```console
A
B
00000241A0CA9850
00000241A0CA9550
00000241A0CA9850
00000241A0CA9550
~B
~A
0000000000000000
0000000000000000
```## How to Build
#### Linux & macOS
```bash
git clone https://github.com/microsoft/vcpkg.git ~/vcpkg
~/vcpkg/bootstrap-vcpkg.shgit clone https://github.com/xorz57/ServiceLocator.git
cd ServiceLocator
cmake -B build -DCMAKE_BUILD_TYPE=Release -S . -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --build-config Release
```#### Windows
```powershell
git clone https://github.com/microsoft/vcpkg.git C:/vcpkg
C:/vcpkg/bootstrap-vcpkg.bat
C:/vcpkg/vcpkg.exe integrate installgit clone https://github.com/xorz57/ServiceLocator.git
cd ServiceLocator
cmake -B build -DCMAKE_BUILD_TYPE=Release -S . -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
ctest --build-config Release
```