SyDEVS  v0.7
Simulation-based analysis of complex systems involving people, devices, physical elements, and dynamic environments.
sydevs::string_builder Class Reference

A class for converting stream objects to string values. More...

#include <string_builder.h>

Public Member Functions

 string_builder ()
 Constructs a string_builder object. More...
 
 string_builder (const string_builder &)=delete
 No copy constructor. More...
 
string_builderoperator= (const string_builder &)=delete
 No copy assignment. More...
 
 string_builder (string_builder &&)=delete
 No move constructor. More...
 
string_builderoperator= (string_builder &&)=delete
 No move assignment. More...
 
 ~string_builder ()=default
 Destructor. More...
 
std::string str () const
 Obtains the data stored in the string_builder object as a std::string. More...
 
template<class T >
string_builderoperator<< (T const &value)
 Inserts data into the stream. More...
 

Detailed Description

A class for converting stream objects to string values.

Several sydevs classes overload the operator<< to append a textual representation of the class instance to a std::ostream object. The string_builder class provides a convenient way to convert these std::ostream objects into std::string values without requiring additional lines of code. Primitives and other classes can also be converted to strings.

std::string s1 = (string_builder() << "n:" << (3 + 5)).str(); // s1 = "n:8"
std::string s2 = (string_builder() << "t:" << (1_min + 7_sec)).str(); // s2 = "t:67_s"
string_builder()
Constructs a string_builder object.
Definition: string_builder.h:67

Constructor & Destructor Documentation

◆ string_builder() [1/3]

sydevs::string_builder::string_builder ( )
inline

Constructs a string_builder object.

◆ string_builder() [2/3]

sydevs::string_builder::string_builder ( const string_builder )
delete

No copy constructor.

◆ string_builder() [3/3]

sydevs::string_builder::string_builder ( string_builder &&  )
delete

No move constructor.

◆ ~string_builder()

sydevs::string_builder::~string_builder ( )
default

Destructor.

Member Function Documentation

◆ operator<<()

template<class T >
string_builder & sydevs::string_builder::operator<< ( T const &  value)
inline

Inserts data into the stream.

If an operation such as operator<<(std::ostream&, const T&) is defined for type T, then a copy of the information in value is inserted into the string_builder object for later retrieval via str().

Parameters
valueThe value to be inserted.
Returns
A reference to the string_builder object, allowing multiple values to be inserted in a single line.

◆ operator=() [1/2]

string_builder& sydevs::string_builder::operator= ( const string_builder )
delete

No copy assignment.

◆ operator=() [2/2]

string_builder& sydevs::string_builder::operator= ( string_builder &&  )
delete

No move assignment.

◆ str()

std::string sydevs::string_builder::str ( ) const
inline

Obtains the data stored in the string_builder object as a std::string.


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