Skip to content

Commit

Permalink
Merge branch 'Vita3K:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
backgamon authored Mar 2, 2024
2 parents c8439d6 + a817310 commit d15c59f
Show file tree
Hide file tree
Showing 13 changed files with 1,348 additions and 38 deletions.
3 changes: 3 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ target_include_directories(stb INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/stb")
add_library(ddspp INTERFACE)
target_include_directories(ddspp INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/ddspp")

add_library(cppcommon STATIC CppCommon/source/cpu.cpp CppCommon/source/environment.cpp)
target_include_directories(cppcommon PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/CppCommon")

add_library(glad STATIC "${CMAKE_CURRENT_SOURCE_DIR}/glad/src/gl.c")
target_include_directories(glad PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/glad/include")

Expand Down
21 changes: 21 additions & 0 deletions external/CppCommon/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016-2024 Ivan Shynkarenka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
115 changes: 115 additions & 0 deletions external/CppCommon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# CppCommon

[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Release](https://img.shields.io/github/release/chronoxor/CppCommon.svg?sort=semver)](https://github.com/chronoxor/CppCommon/releases)
<br/>
[![Linux (clang)](https://github.com/chronoxor/CppCommon/actions/workflows/build-linux-clang.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-linux-clang.yml)
[![Linux (gcc)](https://github.com/chronoxor/CppCommon/actions/workflows/build-linux-gcc.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-linux-gcc.yml)
[![MacOS](https://github.com/chronoxor/CppCommon/actions/workflows/build-macos.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-macos.yml)
<br/>
[![Windows (Cygwin)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-cygwin.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-cygwin.yml)
[![Windows (MSYS2)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-msys2.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-msys2.yml)
[![Windows (MinGW)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-mingw.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-mingw.yml)
[![Windows (Visual Studio)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-vs.yml/badge.svg)](https://github.com/chronoxor/CppCommon/actions/workflows/build-windows-vs.yml)

C++ Common Library contains reusable components and patterns for error and
exceptions handling, filesystem manipulations, math, string format and
encoding, shared memory, threading, time management and others.

[CppCommon API reference](https://chronoxor.github.io/CppCommon/index.html)

# Contents
* [Features](#features)
* [Requirements](#requirements)
* [How to build?](#how-to-build)

# Features
* Cross platform (Linux, MacOS, Windows)
* Exception handling model
* Filesystem manipulations
* String encoding converters
* String format using [{fmt} library](http://fmtlib.net)
* CPU, memory, environment
* Shared memory
* Stack trace
* UUID generator
* Thread extensions (priority, affinity, yield)
* Thread barrier, latch
* Synchronization primitives
* Named synchronization primitives
* Producer/consumer queues
* Time management
* Utilities

# Requirements
* Linux
* MacOS
* Windows
* [cmake](https://www.cmake.org)
* [gcc](https://gcc.gnu.org)
* [git](https://git-scm.com)
* [gil](https://github.com/chronoxor/gil.git)
* [python3](https://www.python.org)

Optional:
* [clang](https://clang.llvm.org)
* [CLion](https://www.jetbrains.com/clion)
* [Cygwin](https://cygwin.com)
* [MSYS2](https://www.msys2.org)
* [MinGW](https://mingw-w64.org/doku.php)
* [Visual Studio](https://www.visualstudio.com)

# How to build?

### Linux: install required packages
```shell
sudo apt-get install -y binutils-dev uuid-dev
```

### Install [gil (git links) tool](https://github.com/chronoxor/gil)
```shell
pip3 install gil
```

### Setup repository
```shell
git clone https://github.com/chronoxor/CppCommon.git
cd CppCommon
gil update
```

### Linux
```shell
cd build
./unix.sh
```

### MacOS
```shell
cd build
./unix.sh
```

### Windows (Cygwin)
```shell
cd build
unix.bat
```

### Windows (MSYS2)
```shell
cd build
unix.bat
```

### Windows (MinGW)
```shell
cd build
mingw.bat
```

### Windows (Visual Studio)
```shell
cd build
vs.bat
```
53 changes: 53 additions & 0 deletions external/CppCommon/include/cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*!
\file cpu.h
\brief CPU management definition
\author Ivan Shynkarenka
\date 27.07.2016
\copyright MIT License
*/

#ifndef CPPCOMMON_SYSTEM_CPU_H
#define CPPCOMMON_SYSTEM_CPU_H

#include <string>

namespace CppCommon {

//! CPU management static class
/*!
Provides CPU management functionality such as architecture, cores count,
clock speed, Hyper-Threading feature.
Thread-safe.
*/
class CPU {
public:
CPU() = delete;
CPU(const CPU &) = delete;
CPU(CPU &&) = delete;
~CPU() = delete;

CPU &operator=(const CPU &) = delete;
CPU &operator=(CPU &&) = delete;

//! CPU architecture string
static std::string Architecture();
//! CPU affinity count
static int Affinity();
//! CPU logical cores count
static int LogicalCores();
//! CPU physical cores count
static int PhysicalCores();
//! CPU total cores count
static std::pair<int, int> TotalCores();
//! CPU clock speed in Hz
static int64_t ClockSpeed();
//! Is CPU Hyper-Threading enabled?
static bool HyperThreading();
};

/*! \example system_cpu.cpp CPU management example */

} // namespace CppCommon

#endif // CPPCOMMON_SYSTEM_CPU_H
34 changes: 34 additions & 0 deletions external/CppCommon/include/environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
\file environment.h
\brief Environment management definition
\author Ivan Shynkarenka
\date 27.07.2016
\copyright MIT License
*/

#ifndef CPPCOMMON_SYSTEM_ENVIRONMENT_H
#define CPPCOMMON_SYSTEM_ENVIRONMENT_H

#include <string>

namespace CppCommon {

//! Environment management static class
/*!
Provides environment management functionality to get OS bit version, process bit version,
debug/release mode.
Thread-safe.
*/

class Environment {
public:
//! Get OS version string
static std::string OSVersion();
};

/*! \example system_environment.cpp Environment management example */

} // namespace CppCommon

#endif // CPPCOMMON_SYSTEM_ENVIRONMENT_H
68 changes: 68 additions & 0 deletions external/CppCommon/include/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*!
\file resource.h
\brief Resource smart cleaner pattern definition
\author Ivan Shynkarenka
\date 01.10.2016
\copyright MIT License
*/

#ifndef CPPCOMMON_UTILITY_RESOURCE_H
#define CPPCOMMON_UTILITY_RESOURCE_H

#include <memory>

namespace CppCommon {

//! Resource smart cleaner pattern
/*!
Resource smart cleaner pattern allows to create unique smart pointer with
a given resource and cleaner delegate which is used to automatic resource
clean when it goes out of scope.
Thread-safe.
Example:
\code{.cpp}
int test()
{
// Create a file resource
auto file = CppCommon::resource(fopen("test", "rb"), [](FILE* file) { fclose(file); });
// Work with the file resource
int result = fgetc(file.get());
// File resource will be cleaned automatically when we go out of scope
return result;
}
\endcode
\param handle - Resource handle
\param cleaner - Cleaner function
*/
template <typename T, typename TCleaner>
auto resource(T handle, TCleaner cleaner) {
return std::unique_ptr<typename std::remove_pointer<T>::type, TCleaner>(handle, cleaner);
}

//! Resource smart cleaner pattern (void* specialization)
/*!
\param handle - Resource handle
\param cleaner - Cleaner function
*/
template <typename TCleaner>
auto resource(void *handle, TCleaner cleaner) {
return std::unique_ptr<void, TCleaner>(handle, cleaner);
}

//! Resource smart cleaner pattern for empty resource handle
/*!
\param cleaner - Cleaner function
*/
template <typename TCleaner>
auto resource(TCleaner cleaner) {
return std::unique_ptr<void, TCleaner>(&cleaner, cleaner);
}

} // namespace CppCommon

#endif // CPPCOMMON_UTILITY_RESOURCE_H
Loading

0 comments on commit d15c59f

Please sign in to comment.