diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-21 15:10:31 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-21 15:11:09 +0200 |
| commit | 23d52c3cb72d595c971f189363c6cf9b222581c7 (patch) | |
| tree | cc070f3fc9342d227e405ef78ae09ac1560800a7 /dev/lib/utility | |
| parent | 5966f5da72f63dcd6d6203366a996a0c1b9f16fb (diff) | |
feat: chunk_string: new work in progress string container.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/utility')
| -rw-r--r-- | dev/lib/utility/cgi_writer.hpp (renamed from dev/lib/utility/cgi.hpp) | 2 | ||||
| -rw-r--r-- | dev/lib/utility/chunk_string.hpp | 79 |
2 files changed, 80 insertions, 1 deletions
diff --git a/dev/lib/utility/cgi.hpp b/dev/lib/utility/cgi_writer.hpp index 57625b8..2c30adf 100644 --- a/dev/lib/utility/cgi.hpp +++ b/dev/lib/utility/cgi_writer.hpp @@ -1,5 +1,5 @@ /* - * File: cgi.hpp + * File: cgi_writer.hpp * Author: Amlal El Mahrouss, * Copyright 2023-2025, Amlal El Mahrouss. */ diff --git a/dev/lib/utility/chunk_string.hpp b/dev/lib/utility/chunk_string.hpp new file mode 100644 index 0000000..ae52c39 --- /dev/null +++ b/dev/lib/utility/chunk_string.hpp @@ -0,0 +1,79 @@ +/* +* File: core/chunk_string.hpp + * Purpose: String implementation for the SOCL C++ library. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#ifndef SOCL_UTILITY_CHUNK_STRING_HPP +#define SOCL_UTILITY_CHUNK_STRING_HPP + +#include <lib/core/includes.hpp> +#include <boost/container/flat_set.hpp> + +namespace snu +{ + template <typename char_type> + class basic_chunk_string; + + template <typename char_type> + struct basic_chunk_string final + { + private: + std::unique_ptr<basic_chunk_string<char_type>> next_chunk_string_{}; + basic_chunk_string<char_type>* prev_chunk_string_{nullptr}; + + std::basic_string<char_type> packed_chunks_{}; + int64_t chunk_total{}; + + constexpr const static auto max_chunk_size = 4096; + + public: + explicit basic_chunk_string() = default; + virtual ~basic_chunk_string() = default; + + basic_chunk_string& operator=(const basic_chunk_string&) = default; + basic_chunk_string(const basic_chunk_string&) = default; + + basic_chunk_string& operator+=(const std::basic_string<char_type>& in) + { + if (in.empty()) + return *this; + + if (chunk_total > max_chunk_size) + { + next_chunk_string_ = std::make_unique<basic_chunk_string<char_type>>(); + *next_chunk_string_ += in; + + next_chunk_string_->prev_chunk_string_ = this; + + return *next_chunk_string_; + } + + packed_chunks_ += in; + chunk_total += in.size(); + + return *this; + } + + const std::basic_string<char_type>& str() noexcept + { + return packed_chunks_; + } + + inline void print() noexcept + { + snu::io::print(packed_chunks_); + + if (next_chunk_string_) + this->next_chunk_string_->print(); + } + }; + + template <typename char_type> + inline void print(basic_chunk_string<char_type>& fmt) noexcept + { + std::cout << fmt.print(); + } +} // namespace snu +#endif // ifndef SOCL_UTILITY_CHUNK_STRING_HPP
\ No newline at end of file |
