Other languages: 中文
Author: Tianming (GitHub)
Project Page: GitHub Repository
Note
This library is a dependency for many of my projects. You need to install it first to use those projects, or utilize automatic dependency fetching.
Warning
If you encounter some strange behavior, just MAKE SURE you are using the right build configuration (Debug/Release) for both the library and your project. This is a common mistake that can cause the old bugs to appear even after you updated the library, since this library was configured to keep the binaries at the same time for both Debug and Release (for easier development).
Free software with NO WARRANTY. Some modules may be incomplete.
You may use this library for personal or commercial purposes. Attribution is appreciated but not required.
A collection of modern C++ utility libraries designed for performance and ease of use. Built with C++23 standard.
Some modules of this project are basically re-inventing the wheel. The purpose is to learn something.
This library is building on top of the standard library, with its own convenient set of APIs. The SharedCppLib2 API is designed for extremely easy use, and it is not hard to learn. Check API Reference for details.
I still tried to make the API design as good (friendly, easy-to-use) as possible.
ansiio- ANSI terminal output and formattingstringlist- Enhanced string manipulation with Qt-inspired APIarguments- Type-safe command-line argument parsing (argparse-inspired)Base64- Base64 encoding and decoding utilitiesbytearray- Binary data management and serializationsha256- SHA-256 cryptographic hash implementationhmac- Header-only HMAC implementation based on hash providerslogt- High-performance asynchronous logginglogc- Colored console output for logtindexer- Data indexing and search utilitieshpcalc- High-precision arithmetic operationsregexfilter- Regex-based blacklist/whitelist filteringatxsort- Universal sorting algorithmsini- INI configuration parser and writerplatform- Cross-platform utilities and abstractionsxml- XML parsing and serialization library (in development) (Warning: Though the module is basically functional, some functions are yet unsafe and cause crashes.)html- HTML parsing and manipulation library (in development)
logd- Simple console logger (deprecated)logf- Simple file logger (deprecated)
eventloop- Moved to separate projecttasker- Sub-thread task manager (unmaintained)
git clone https://github.com/Tianming-Wu/SharedCppLib2
cd SharedCppLib2For Debug:
cmake -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
cmake --install buildFor Release:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install buildNote
On Windows, run in Administrator prompt or use sudo on Windows 11. The --config parameter is only needed for multi-configuration generators like Visual Studio.
CMakeLists.txt:
find_package(SharedCppLib2 REQUIRED)
target_link_libraries(your_target SharedCppLib2::basic)Available targets: variant, logd, logf, sha256, basic, indexer, regexfilter, logt, logc, Base64, platform, arguments, ini, abstract, xml, debug, stream, console, keydb, types, api, hmac, logh, rerr, bits, cache, exexception, engineering, multindex, percentage, RAII, singleinst, structural_binding, typemask
#include <SharedCppLib2/stringlist.hpp>
int main(int argc, char** argv) {
std::stringlist args(argc, argv);
// Process command line arguments
return 0;
}hmac is provider-agnostic. The sample below uses sha256 as provider.
#include <SharedCppLib2/hmac.hpp>
#include <SharedCppLib2/sha256.hpp>
std::bytearray key(std::string("secret-key"));
std::bytearray payload(std::string("binary-message"));
std::bytearray tag = scl2::hmac<scl2::sha256>::compute(payload, key);For tag verification, use constant-time comparison:
Detailed documentation is available in header files as Doxygen comments.
Full Changelog: WhatsNew
Microsoft is doing a bad job at there api (windows.h explicitly).
It contains SO MANY macros that pollute the global namespace. Some of them can not even work with the C++ standard.
In development, if you are using VSCode for example, be careful when some of your code turned blue, which probably indicates that some macro is messing with your code.
I have no idea how to fix these. I tried to re-package some of the windows.h content in a more modern, standard and namespace nested way in another project, but it is just too much work and it is almost impossible to cover all the use cases.
If you are developing something on Windows, espeacially some shared modules, I recommend that you avoid including windows.h in any of your header files. Only include them in the .cpp files.
And always define NOMINMAX and WIN32_LEAN_AND_MEAN before including windows.h, to reduce the pollution. If some names are really unusable, like Process32First and Process32Next that somehow Microsoft developers completely covered the ANSI version, you can just #undef them.
Note that it would ALWAYS be a good habit of using A and W suffix version of Windows API. I think the macros defined in windows.h is completely for compatibility with old codes (which is a main goal for them). But it has nothing good with modern C++ code. So just use the A and W version directly, and you can avoid a lot of problems.
I added some warnings in the code. You can experience some of my fixes in the platform_windows module. They are hardly enough, so add your thing if you also finds something.