namespace strf {
template <typename CharT>
constexpr std::size_t min_space_after_recycle();
template <typename CharT>
class destination
{ /* ... */ };
template <typename CharT>
void put(destination<CharT>& ob, CharT c);
template <typename CharT>
class basic_cstr_writer final: public destination<CharT>
{ /* ... */};
template <typename CharT>
class discarded_destination final: public destination<CharT>
{ /* ... */};
template <typename CharT>
CharT* garbage_buff();
template <typename CharT>
CharT* garbage_buff_end();
using u8cstr_writer = basic_cstr_writer<char8_t>;
using cstr_writer = basic_cstr_writer<char>;
using u16cstr_writer = basic_cstr_writer<char16_t>;
using u32cstr_writer = basic_cstr_writer<char32_t>;
using wcstr_writer = basic_cstr_writer<wchar_t>;
} // namespace strf
1. Function template min_space_after_recycle
template <typename CharT>
constexpr std::size_t min_space_after_recycle();
Return value |
Implementation-defined value greater than or equal to 64. |
2. Class template destination
2.1. Synopsis
namespace strf {
template <typename CharT>
class destination;
{
public:
using char_type = CharT;
destination(const destination&) = delete;
destination(destination&&) = delete;
destination& operator=(const destination&) = delete;
destination& operator=(destination&&) = delete;
virtual ~destination() = default;
CharT* buffer_ptr() const noexcept;
CharT* buffer_end() const noexcept;
std::size_t buffer_space() const noexcept;
bool good() const noexcept;
void advance_to(CharT* p);
void advance(std::size_t n);
void ensure(std::size_t s);
void write(const CharT* str, std::size_t str_len);
virtual void recycle() = 0;
protected:
destination(CharT* buff, CharT* buff_end);
destination(CharT* buff, std::size_t buff_size);
void set_buffer_ptr(CharT* p) noexcept;
void set_buffer_end(CharT* e) noexcept;
void set_good(bool g) noexcept;
virtual void do_write(const CharT* str, std::size_t str_len);
};
// global functions
template <typename CharT>
void put(destination<CharT>& ob, CharT ch );
} // namespace strf
2.2. Member types
using char_type = CharT;
2.3. Public member functions
CharT* buffer_ptr() const noxcept;
Return |
The memory position where the content shall be written. |
CharT* buffer_end() const noxcept;
Return |
The end of memory position where the content shall be written.
Dereferencing |
std::size_t buffer_space() const noexcept;
Return |
|
virtual void recycle() = 0;
Posconditions |
|
void ensure(std::size_t s)
Effect |
Calls |
Precondition |
|
Postcondition |
|
void advance_to(CharT* p)
Effect |
Advance the buffer’s pointer to |
Precondition |
|
Postcondition |
|
void advance(std::size_t n)
Effect |
Equivalent to |
Precondition |
|
void advance()
Effect |
Equivalent to |
Precondition |
|
bool good() const;
Return |
The state of this object. |
Semantincs |
|
Note |
The range [ |
void write(const CharT* str, std::size_t str_len);
Effect |
If |
2.4. Protected Member functions
destination(CharT* buff_, CharT* buff_end_)
Preconditions |
|
Posconditions |
|
destination(CharT* buff_, std::size_t buff_size_)
Preconditions |
|
Posconditions |
|
void set_buffer_ptr(CharT* p) noexcept
Postconditions |
|
void set_buffer_end(CharT* e) noexcept
Postconditions |
|
void set_good(bool g) noexcept
Postconditions |
|
virtual void do_write(const CharT* str, std::size_t str_len);
Effect |
Writes the first |
Note |
This function is made virtual so that any derived classes can override it with an optimized version. |
2.5. Global functions
template <typename CharT>
void put(destination<CharT>& ob, CharT ch);
Effect |
Equivalent to:
|
3. Class template basic_cstr_writer
namespace strf {
template <typename CharT>
class basic_cstr_writer final: public {destination}<CharT> {
public:
basic_cstr_writer(CharT* dest, CharT* dest_end) noexcept;
basic_cstr_writer(CharT* dest, std::size_t len) noexcept;
template <std::size_t N>
basic_cstr_writer(CharT (&dest)[N]) noexcept;
basic_cstr_writer(const basic_cstr_writer&) = delete;
void recycle() noexcept override;
struct result {
CharT* ptr;
bool truncated;
};
result finish() noexcept;
};
} // namespace strf
3.1. Public member functions
basic_cstr_writer(CharT* dest, CharT* dest_end) noexcept;
Precondition |
|
Postconditions |
|
basic_cstr_writer(CharT* dest, std::size_t dest_size) noexcept;
Precondition |
|
Postconditions |
|
template <std::size_t N>
basic_cstr_writer(CharT (&dest)[N]) noexcept;
Postconditions |
|
void recycle() noexcept;
Postconditions |
|
result finish() noexcept;
Effects |
|
Return value |
|
Postconditions |
|
4. Class template basic_char_array_writer
namespace strf {
template <typename CharT>
class basic_char_array_writer final : public {destination}<CharT> {
public:
template <std::size_t N>
basic_char_array_writer(CharT (&dest)[N]) noexcept;
basic_char_array_writer(CharT* dest, CharT* dest_end) noexcept;
basic_char_array_writer(CharT* dest, std::size_t dest_size) noexcept;
basic_char_array_writer(const basic_char_array_writer&) noexcept;
basic_char_array_writer& operator=(const basic_char_array_writer&) noexcept;
bool operator==(const basic_char_array_writer&) noexcept;
void recycle() noexcept override;
struct result {
CharT* ptr;
bool truncated;
};
result finish() noexcept;
};
} // namespace strf
4.1. Public member functions
template <std::size_t N>
basic_char_array_writer(CharT (&dest)[N]) noexcept;
- Postconditions
-
-
good() == true
-
buffer_ptr() == dest
-
buffer_end() == dest + N
-
basic_char_array_writer(CharT* dest, CharT* dest_end) noexcept;
Precondition |
|
Postconditions |
|
basic_char_array_writer(CharT* dest, std::size_t dest_size) noexcept;
Precondition |
|
Postconditions |
|
void recycle() noexcept;
Postconditions |
|
result finish() noexcept;
- Return value
-
-
result.truncated
istrue
whenrecycle()
ordo_write(…)
has been previously called in this object, which means that the the range which with it was initialized is too small. -
result::ptr
is the one-past-the-end pointer of the characters written. However, whenresult.truncated
istrue
, the number of characters written is unspecified.
-
5. Class template discarded_destination
discarded_destination
it’s the library’s analogous to /dev/null
.
A discarded_destination
object ignores anything written to it.
namespace strf {
template <typename CharT>
class discarded_destination final: public destination<CharT>
{
public:
discarded_destination() noexcept;
void recycle() noexcept override;
};
} // namespace strf
discarded_destination() noexcept;
Postconditions |
|
void recycle() noexcept;
Postconditions |
|
6. Garbage buffer
These function templates return the begin and the end of a memory area that is never supposed to be read. It can be used when implementing a class that derives from destination
to set the buffer when the state is "bad".
template <typename CharT>
CharT* garbage_buff() noexcept;
template <typename CharT>
CharT* garbage_buff_end() noexcept;