PSCF v1.1
List of all members
Util::Str Class Reference

Wrapper for a std::string, for formatted ostream output. More...

#include <Str.h>

Public Member Functions

Constructors
 Str ()
 Default constructor. More...
 
 Str (std::string value)
 Constructor, set value only. More...
 
 Str (std::string value, int width)
 Constructor, set value and width. More...
 
Mutators
void setValue (std::string value)
 Set the string value. More...
 
void setWidth (int width)
 Set the default width. More...
 

Accessors

std::string value () const
 Return string value. More...
 
int width () const
 Return default string width. More...
 
std::istream & operator>> (std::istream &in, Str &object)
 Input stream extractor for an Str object. More...
 
std::ostream & operator<< (std::ostream &out, const Str &object)
 Output stream inserter for an Str object. More...
 

Detailed Description

Wrapper for a std::string, for formatted ostream output.

An Str object has std::string value, and an integer output field width. The << operator for an Str object uses the specified width. The value and width may both be specified as parameters to a constructor. If the width is not specified as a constructor parameter, it is set within the constructor to a default value given by Format::defaultWidth().

An Str object may be passed to an ostream as a temporary object. For example, the expression:

std::cout << Str("Hello") << Str("World", 20) << std::endl;
Str()
Default constructor.
Definition: Str.cpp:17

outputs "Hello" using the default width, followed by "World" in a field of width 20.

Definition at line 36 of file Str.h.

Constructor & Destructor Documentation

◆ Str() [1/3]

Util::Str::Str ( )

Default constructor.

Definition at line 17 of file Str.cpp.

◆ Str() [2/3]

Util::Str::Str ( std::string  value)
explicit

Constructor, set value only.

Constructor, value only (explicit).

Parameters
valuevalue of the string

Definition at line 23 of file Str.cpp.

◆ Str() [3/3]

Util::Str::Str ( std::string  value,
int  width 
)

Constructor, set value and width.

Constructor, value and width.

Parameters
valuevalue of the string
widthdefault width (minimum number of characters)

Definition at line 29 of file Str.cpp.

Member Function Documentation

◆ setValue()

void Util::Str::setValue ( std::string  value)

Set the string value.

Parameters
valuevalue of the string

Definition at line 34 of file Str.cpp.

References value().

◆ setWidth()

void Util::Str::setWidth ( int  width)

Set the default width.

Parameters
widthdefault width (minimum number of characters)

Definition at line 37 of file Str.cpp.

References width().

◆ value()

std::string Util::Str::value ( ) const

Return string value.

Definition at line 40 of file Str.cpp.

Referenced by setValue().

◆ width()

int Util::Str::width ( ) const

Return default string width.

Definition at line 43 of file Str.cpp.

Referenced by setWidth().

Friends And Related Function Documentation

◆ operator>>

std::istream & operator>> ( std::istream &  in,
Str object 
)
friend

Input stream extractor for an Str object.

Parameters
ininput stream
objectStr object to be read from stream
Returns
modified input stream

Definition at line 49 of file Str.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Str object 
)
friend

Output stream inserter for an Str object.

Parameters
outoutput stream
objectStr to be written to stream
Returns
modified output stream

Definition at line 58 of file Str.cpp.


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