Skip to content

o-netusa/cppbase

Repository files navigation

workflow Language: C++17 License Open in Visual Studio Code

cppbase

C++17 cross-platform header-only library providing common features for C++ projects, such as variant, logging, serialization, task sequence, thread pool, TCP/UDP client and server, etc.

Features

Variant

Variant allows to store data of any type and convert between these types transparently. The current implementation is based on rttr to get Runtime Type Reflection. We also implemented a userful feature called PropertyPath, which defines a chained PropertyInfos that can be used to access a property of a type. Refer to tests/common/VariantTests.cpp for examples.

Logging

Logging is a wrapper on spdlog and integrated spdlog_setup for static logging configuration. User can create a config file (specified in spdlog_setup) and put it under config/log.conf of the current working directory to configure logging. To get the logger for the current module, just call cppbase::logging::GetLoggerForCurrentModule() and make sure to define MODULE_NAME at compile time.

Serialization

Serialization internally uses cereal to serialize and deserialize data. Serializer provides a set of convenient functions to serialize and deserialize objects to/from a string or a file in binary format, which can be easily changed to JSON or XML.

Sequence

Sequence is a set of classes (Processor, Sequence, Link) that allows user to execute a series of processing unit. It internally uses taskflow as the execution engine. Together with Variant, it provides an easy way to create a sequence that contains multiple processors with different functionalities to finish complex tasks. Refer to tests/common/SequenceTests.cpp and [tests/sequence/ProcessorTests.cpp] for examples.

Processor, Sequence and link

Thread Pool

There are two threadpools in this library: ThreadPool and ForkJoinPool. The former is based on https://github.com/progschj/ThreadPool.git and the latter is based on asio's fork join pool.

TCP/UDP Client and Server

Our implementation uses non-boost version asio internally.

Others

There are other features that are commonly used in C++ projects, such as BlockingQueue, Encoding, FileSystem (wraps up C++17 std::filesystem), Semaphore, Timer, Uuid.

Please create issues if you find any bugs or have any suggestions.

Thirdparty libraries

thirdparty/README.md

Setup clang-format in QtCreator

  • Enable "Help->Plugin->Beautifier" and restart QtCreator
  • Add the source code directory in "Tools->Options->Beautifier->Clang-Format" and choose command and style
  • Setup hotkeys from "Tools->Options->environment->keyboard->ClangFormat"