|
Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
|
Small String Optimization (SSO) implementation. More...
#include <small_string.h>

Classes | |
| union | data_union |
| struct | memory_stats |
| Get memory usage statistics. More... | |
Public Member Functions | |
| small_string () noexcept | |
| Default constructor. | |
| small_string (const char *str) | |
| Construct from C-string. | |
| small_string (const std::string &str) | |
| Construct from std::string. | |
| small_string (std::string_view str) | |
| Construct from string_view. | |
| small_string (const small_string &other) | |
| Copy constructor. | |
| small_string (small_string &&other) noexcept | |
| Move constructor. | |
| ~small_string () | |
| Destructor. | |
| small_string & | operator= (const small_string &other) |
| Copy assignment. | |
| small_string & | operator= (small_string &&other) noexcept |
| Move assignment. | |
| void | assign (const char *str, size_t len) |
| Assign from string data. | |
| const char * | c_str () const noexcept |
| Get C-string pointer. | |
| const char * | data () const noexcept |
| Get data pointer. | |
| size_t | size () const noexcept |
| Get size. | |
| size_t | length () const noexcept |
| Get length (same as size) | |
| bool | empty () const noexcept |
| Check if empty. | |
| bool | is_small () const noexcept |
| Check if using small string optimization. | |
| size_t | capacity () const noexcept |
| Get capacity. | |
| void | clear () noexcept |
| Clear the string. | |
| void | reserve (size_t new_capacity) |
| Reserve capacity. | |
| void | append (const char *str, size_t len) |
| Append a string. | |
| void | append (const std::string &str) |
| Append a string. | |
| small_string & | operator+= (const char *str) |
| Append operator. | |
| small_string & | operator+= (const std::string &str) |
| Append operator. | |
| std::string | to_string () const |
| Convert to std::string. | |
| operator std::string_view () const noexcept | |
| Implicit conversion to string_view. | |
| bool | operator== (const small_string &other) const noexcept |
| Equality comparison. | |
| bool | operator!= (const small_string &other) const noexcept |
| Inequality comparison. | |
| bool | operator== (const std::string &str) const noexcept |
| Comparison with std::string. | |
| memory_stats | get_memory_stats () const noexcept |
Static Public Attributes | |
| static constexpr size_t | SSO_CAPACITY = SSO_SIZE - 1 |
Static Private Member Functions | |
| static size_t | calculate_capacity (size_t required) |
| Calculate capacity for heap allocation. | |
Private Attributes | |
| union kcenon::logger::small_string::data_union | data_ |
| size_t | size_ |
| bool | is_small_ |
Small String Optimization (SSO) implementation.
This class implements a string with Small String Optimization. Strings smaller than SSO_CAPACITY are stored inline, avoiding heap allocation. Larger strings use heap allocation like std::string.
| SSO_SIZE | Size threshold for SSO (default 256 bytes) |
Definition at line 32 of file small_string.h.
|
inlinenoexcept |
Default constructor.
Definition at line 39 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_, and kcenon::logger::small_string< SSO_SIZE >::data_union::small.
|
inline |
Construct from C-string.
Definition at line 46 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::assign().

|
inline |
Construct from std::string.
Definition at line 55 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::assign().

|
inline |
Construct from string_view.
Definition at line 62 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::assign().

|
inline |
Copy constructor.
Definition at line 69 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::is_small_.
|
inlinenoexcept |
Move constructor.
Definition at line 82 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, kcenon::logger::small_string< SSO_SIZE >::size_, and kcenon::logger::small_string< SSO_SIZE >::data_union::small.
|
inline |
Destructor.
Definition at line 98 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, and kcenon::logger::small_string< SSO_SIZE >::data_union::ptr.
|
inline |
Append a string.
Definition at line 267 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::calculate_capacity(), kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::data(), kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, kcenon::logger::small_string< SSO_SIZE >::size_, kcenon::logger::small_string< SSO_SIZE >::data_union::small, and kcenon::logger::small_string< SSO_SIZE >::SSO_CAPACITY.
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::operator+=(), and kcenon::logger::small_string< SSO_SIZE >::operator+=().


|
inline |
Append a string.
Definition at line 308 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::append().

|
inline |
Assign from string data.
Definition at line 143 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::calculate_capacity(), kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, kcenon::logger::small_string< SSO_SIZE >::size_, kcenon::logger::small_string< SSO_SIZE >::data_union::small, and kcenon::logger::small_string< SSO_SIZE >::SSO_CAPACITY.
Referenced by kcenon::logger::small_string< SSO_SIZE >::operator=(), kcenon::logger::small_string< SSO_SIZE >::small_string(), kcenon::logger::small_string< SSO_SIZE >::small_string(), and kcenon::logger::small_string< SSO_SIZE >::small_string().


|
inlinenoexcept |
Get C-string pointer.
Definition at line 176 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data().

|
inlinestaticprivate |
Calculate capacity for heap allocation.
Definition at line 390 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::capacity().
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::assign(), and kcenon::logger::small_string< SSO_SIZE >::reserve().


|
inlinenoexcept |
Get capacity.
Definition at line 218 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, and kcenon::logger::small_string< SSO_SIZE >::SSO_CAPACITY.
Referenced by kcenon::logger::small_string< SSO_SIZE >::calculate_capacity(), kcenon::logger::small_string< SSO_SIZE >::get_memory_stats(), and kcenon::logger::small_string< SSO_SIZE >::reserve().

|
inlinenoexcept |
Clear the string.
Definition at line 225 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, kcenon::logger::small_string< SSO_SIZE >::size_, and kcenon::logger::small_string< SSO_SIZE >::data_union::small.
|
inlinenoexcept |
Get data pointer.
Definition at line 183 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, and kcenon::logger::small_string< SSO_SIZE >::data_union::small.
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::c_str(), kcenon::logger::small_string< SSO_SIZE >::operator std::string_view(), kcenon::logger::small_string< SSO_SIZE >::operator=(), kcenon::logger::small_string< SSO_SIZE >::operator==(), kcenon::logger::small_string< SSO_SIZE >::operator==(), kcenon::logger::small_string< SSO_SIZE >::reserve(), content_filter::should_log(), and kcenon::logger::small_string< SSO_SIZE >::to_string().

|
inlinenoexcept |
Check if empty.
Definition at line 204 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::size_.
|
inlinenoexcept |
Definition at line 376 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::capacity(), kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::memory_stats::capacity, kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::memory_stats::heap_bytes_used, kcenon::logger::small_string< SSO_SIZE >::memory_stats::is_small, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::size_, kcenon::logger::small_string< SSO_SIZE >::memory_stats::string_size, and kcenon::logger::small_string< SSO_SIZE >::memory_stats::total_bytes.

|
inlinenoexcept |
Check if using small string optimization.
Definition at line 211 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::is_small_.
|
inlinenoexcept |
Get length (same as size)
Definition at line 197 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::size_.
|
inlinenoexcept |
Implicit conversion to string_view.
Definition at line 338 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data(), and kcenon::logger::small_string< SSO_SIZE >::size_.

|
inlinenoexcept |
Inequality comparison.
Definition at line 353 of file small_string.h.
|
inline |
Append operator.
Definition at line 315 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::append().

|
inline |
Append operator.
Definition at line 323 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::append().

|
inline |
Copy assignment.
Definition at line 107 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::assign(), kcenon::logger::small_string< SSO_SIZE >::data(), and kcenon::logger::small_string< SSO_SIZE >::size().

|
inlinenoexcept |
Move assignment.
Definition at line 117 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, kcenon::logger::small_string< SSO_SIZE >::size_, and kcenon::logger::small_string< SSO_SIZE >::data_union::small.
|
inlinenoexcept |
Equality comparison.
Definition at line 345 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data(), and kcenon::logger::small_string< SSO_SIZE >::size_.

|
inlinenoexcept |
Comparison with std::string.
Definition at line 360 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data(), and kcenon::logger::small_string< SSO_SIZE >::size_.

|
inline |
Reserve capacity.
Definition at line 237 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::calculate_capacity(), kcenon::logger::small_string< SSO_SIZE >::capacity(), kcenon::logger::small_string< SSO_SIZE >::data_union::capacity, kcenon::logger::small_string< SSO_SIZE >::data(), kcenon::logger::small_string< SSO_SIZE >::data_, kcenon::logger::small_string< SSO_SIZE >::data_union::heap, kcenon::logger::small_string< SSO_SIZE >::is_small_, kcenon::logger::small_string< SSO_SIZE >::data_union::ptr, kcenon::logger::small_string< SSO_SIZE >::size_, and kcenon::logger::small_string< SSO_SIZE >::SSO_CAPACITY.

|
inlinenoexcept |
Get size.
Definition at line 190 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::size_.
Referenced by kcenon::logger::small_string< SSO_SIZE >::operator=(), and content_filter::should_log().

|
inline |
Convert to std::string.
Definition at line 331 of file small_string.h.
References kcenon::logger::small_string< SSO_SIZE >::data(), and kcenon::logger::small_string< SSO_SIZE >::size_.
Referenced by kcenon::logger::buffered_writer::copy_entry(), kcenon::logger::copy_log_entry(), kcenon::logger::compact_formatter::format(), kcenon::logger::json_formatter::format(), kcenon::logger::logfmt_formatter::format(), kcenon::logger::timestamp_formatter::format(), kcenon::logger::console_writer::format_entry(), kcenon::logger::file_writer::format_entry(), kcenon::logger::network_writer::format_for_network(), kcenon::logger::base_writer::format_log_entry(), kcenon::logger::template_formatter::resolve_placeholder(), kcenon::logger::filters::regex_filter::should_log(), kcenon::logger::log_filter::should_log(), security_filter::should_log(), kcenon::logger::sampling::log_sampler::should_sample(), kcenon::logger::async::high_performance_async_writer::write(), kcenon::logger::encrypted_writer::write(), kcenon::logger::network_writer::write(), kcenon::logger::otlp_writer::write(), and kcenon::logger::critical_writer::write_to_wal().


|
private |
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::assign(), kcenon::logger::small_string< SSO_SIZE >::capacity(), kcenon::logger::small_string< SSO_SIZE >::clear(), kcenon::logger::small_string< SSO_SIZE >::data(), kcenon::logger::small_string< SSO_SIZE >::get_memory_stats(), kcenon::logger::small_string< SSO_SIZE >::operator=(), kcenon::logger::small_string< SSO_SIZE >::reserve(), kcenon::logger::small_string< SSO_SIZE >::small_string(), kcenon::logger::small_string< SSO_SIZE >::small_string(), and kcenon::logger::small_string< SSO_SIZE >::~small_string().
|
private |
Definition at line 414 of file small_string.h.
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::assign(), kcenon::logger::small_string< SSO_SIZE >::capacity(), kcenon::logger::small_string< SSO_SIZE >::clear(), kcenon::logger::small_string< SSO_SIZE >::data(), kcenon::logger::small_string< SSO_SIZE >::get_memory_stats(), kcenon::logger::small_string< SSO_SIZE >::is_small(), kcenon::logger::small_string< SSO_SIZE >::operator=(), kcenon::logger::small_string< SSO_SIZE >::reserve(), kcenon::logger::small_string< SSO_SIZE >::small_string(), kcenon::logger::small_string< SSO_SIZE >::small_string(), and kcenon::logger::small_string< SSO_SIZE >::~small_string().
|
private |
Definition at line 413 of file small_string.h.
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::assign(), kcenon::logger::small_string< SSO_SIZE >::clear(), kcenon::logger::small_string< SSO_SIZE >::empty(), kcenon::logger::small_string< SSO_SIZE >::get_memory_stats(), kcenon::logger::small_string< SSO_SIZE >::length(), kcenon::logger::small_string< SSO_SIZE >::operator std::string_view(), kcenon::logger::small_string< SSO_SIZE >::operator=(), kcenon::logger::small_string< SSO_SIZE >::operator==(), kcenon::logger::small_string< SSO_SIZE >::operator==(), kcenon::logger::small_string< SSO_SIZE >::reserve(), kcenon::logger::small_string< SSO_SIZE >::size(), kcenon::logger::small_string< SSO_SIZE >::small_string(), and kcenon::logger::small_string< SSO_SIZE >::to_string().
|
staticconstexpr |
Definition at line 34 of file small_string.h.
Referenced by kcenon::logger::small_string< SSO_SIZE >::append(), kcenon::logger::small_string< SSO_SIZE >::assign(), kcenon::logger::small_string< SSO_SIZE >::capacity(), and kcenon::logger::small_string< SSO_SIZE >::reserve().