A library of practical C++ examples.
This project collects practical examples in various C++ programming, covering many fields such as system programming, encryption algorithms, multi-threading, crash handling, design patterns, etc. Each example strives to be concise and clear, making it easy to learn and use in actual projects.
1.Breakpad
A simple wrapper for Google Breakpad for application crash reporting and stack tracing.
- core file:
breakpad.hpp/breakpad.cc- Breakpad encapsulation classexample.cc- Usage examplesbreakpad_unittest.cc- unit testing
System byte order detection tool.
- core file:
byteorder.cc- Use multiple methods to determine the byte order of the system (big endian/little endian)
3.Crashpad
A simple wrapper for Google Crashpad, a modern crash reporting system.
- core file:
crashpad.hpp/crashpad.cc- Crashpad encapsulation classexample.cc- Usage examplescrashpad_server.py- Crash reporting server script
4.Memcpy
Memory copy function implementation and related tests.
- core file:
mymemcpy.hpp/mymemcpy.cc- Custom memcpy function implementationmymemcpy_unittest.cc- unit testing
Cross-platform directory monitoring implementation, supporting Windows, macOS and Linux.
- core file:
monitordir.hpp- Directory monitoring interfacemonitordir_win.cc- Windows implementation (usingReadDirectoryChangesW)monitordir_mac.cc- macOS implementation (usingFSEvents)monitordir_linux_inotify.cc- Linux inotify implementationmonitordir_linux_fanotify.cc- Linux fanotify implementationmain.cc- Usage examples
Linux platform instructions:
fanotifyUse global mode (FAN_MARK_FILESYSTEM), can monitor events of the entire file system- need
CAP_SYS_ADMINCapabilities (root permissions) - Recommended for ordinary users
inotifyaccomplish
Directory monitoring example based on efsw library.
- core file:
main.cc- Directory monitoring example using efsw
7.OpenSSL
OpenSSL encryption algorithm usage example.
- core file:
openssl_common.hpp/openssl_common.cc- Public utility functionsopenssl_aes.cc- AES encryption and decryption exampleopenssl_base64.cc- Base64 encoding and decoding exampleopenssl_hash.cc- SHA256 hash calculation exampleopenssl_rsa.cc- RSA encryption and decryption example
A modern thread-safe implementation of the Singleton pattern using C++11 features to ensure cross-platform compatibility.
- core file:
singleton.hpp- Templated singleton base class, providing thread-safe instance accesssingleton_unitest.cc- Complete unit testing to verify the uniqueness, thread safety and other characteristics of the singleton
9.Thread
Threads and thread pools implemented based on std::jthread (note: not supported by Apple Clang).
- core file:
thread.hpp- Thread class encapsulationthreadpool.hpp-Thread pool implementationqueue.hpp- Thread safe queuethread_unittest.cc- Thread unit testingthreadpool_unittest.cc- Thread pool unit testingqueue_unittest.cc- Queue unit testing
10.utils
General tool class.
- core file:
scopeguard.hpp- RAII range guardobject.hpp- Object tool classutils.hpp/utils.cc- Common tool functions
s