diff options
Diffstat (limited to 'dev/lib')
| -rw-r--r-- | dev/lib/core/includes.hpp | 1 | ||||
| -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 |
3 files changed, 81 insertions, 1 deletions
diff --git a/dev/lib/core/includes.hpp b/dev/lib/core/includes.hpp index 6bddba9..4beec1c 100644 --- a/dev/lib/core/includes.hpp +++ b/dev/lib/core/includes.hpp @@ -11,6 +11,7 @@ #include <boost/core/nvp.hpp> #include <boost/core/demangle.hpp> #include <boost/core/null_deleter.hpp> +#include <boost/container/allocator.hpp> #include <filesystem> #include <utility> 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 |
