MySQL 9.1.0
Source Code Documentation
raii::Targeted_stringstream Class Reference

Like std::stringstream, copying to a given target string at destruction. More...

#include <targeted_stringstream.h>

Public Member Functions

 Targeted_stringstream (std::string &target, const std::string &suffix="", const std::function< void(const std::string &)> &callback=nullptr)
 
 Targeted_stringstream (const Targeted_stringstream &)=delete
 
 Targeted_stringstream (Targeted_stringstream &&other) noexcept
 
Targeted_stringstreamoperator= (const Targeted_stringstream &)=delete
 
Targeted_stringstreamoperator= (Targeted_stringstream &&other) noexcept
 
 ~Targeted_stringstream ()
 

Private Attributes

bool m_active
 
std::string & m_target
 
std::string m_suffix
 
std::ostringstream m_stream
 
std::function< void(std::string &)> m_callback
 

Friends

template<class T >
Targeted_stringstreamoperator<< (Targeted_stringstream &stream, const T &value)
 
template<class T >
Targeted_stringstreamoperator<< (Targeted_stringstream &&stream, const T &value)
 

Detailed Description

Like std::stringstream, copying to a given target string at destruction.

This is a convenience helper, allowing the use of:

Targeted_stringstream(s) << foo << bar << baz;
Targeted_stringstream(std::string &target, const std::string &suffix="", const std::function< void(const std::string &)> &callback=nullptr)
Definition: targeted_stringstream.cc:28

instead of:

std::stringstream stream;
stream << foo << bar << baz;
s.assign(stream.str());

This can, for instance, be used by a class to export a stream interface to update private string members.

Constructor & Destructor Documentation

◆ Targeted_stringstream() [1/3]

raii::Targeted_stringstream::Targeted_stringstream ( std::string &  target,
const std::string &  suffix = "",
const std::function< void(const std::string &)> &  callback = nullptr 
)
explicit

◆ Targeted_stringstream() [2/3]

raii::Targeted_stringstream::Targeted_stringstream ( const Targeted_stringstream )
delete

◆ Targeted_stringstream() [3/3]

raii::Targeted_stringstream::Targeted_stringstream ( Targeted_stringstream &&  other)
noexcept

◆ ~Targeted_stringstream()

raii::Targeted_stringstream::~Targeted_stringstream ( )

Member Function Documentation

◆ operator=() [1/2]

Targeted_stringstream & raii::Targeted_stringstream::operator= ( const Targeted_stringstream )
delete

◆ operator=() [2/2]

Targeted_stringstream & raii::Targeted_stringstream::operator= ( Targeted_stringstream &&  other)
noexcept

Friends And Related Function Documentation

◆ operator<< [1/2]

template<class T >
Targeted_stringstream & operator<< ( Targeted_stringstream &&  stream,
const T &  value 
)
friend

◆ operator<< [2/2]

template<class T >
Targeted_stringstream & operator<< ( Targeted_stringstream stream,
const T &  value 
)
friend

Member Data Documentation

◆ m_active

bool raii::Targeted_stringstream::m_active
private

◆ m_callback

std::function<void(std::string &)> raii::Targeted_stringstream::m_callback
private

◆ m_stream

std::ostringstream raii::Targeted_stringstream::m_stream
private

◆ m_suffix

std::string raii::Targeted_stringstream::m_suffix
private

◆ m_target

std::string& raii::Targeted_stringstream::m_target
private

The documentation for this class was generated from the following files: