PSCF v1.1
Str.cpp
1/*
2* Util Package - C++ Utilities for Scientific Computation
3*
4* Copyright 2010 - 2017, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Str.h"
9#include "Format.h"
10
11#include <iostream>
12
13namespace Util
14{
15
18 : value_(),
19 width_(Format::defaultWidth())
20 {}
21
23 Str::Str(std::string value)
24 : value_(value),
25 width_(Format::defaultWidth())
26 {}
27
29 Str::Str(std::string value, int width)
30 : value_(value),
31 width_(width)
32 {}
33
34 void Str::setValue(std::string value)
35 { value_ = value; }
36
37 void Str::setWidth(int width)
38 { width_ = width; }
39
40 std::string Str::value() const
41 { return value_; }
42
43 int Str::width() const
44 { return width_; }
45
46 /*
47 * Input stream extractor for an Str object.
48 */
49 std::istream& operator>>(std::istream& in, Str &object)
50 {
51 in >> object.value_;
52 return in;
53 }
54
55 /*
56 * Output stream inserter for an Str object.
57 */
58 std::ostream& operator<<(std::ostream& out, const Str &object)
59 {
60 out.width(object.width_);
61 out << object.value_;
62 return out;
63 }
64
65}
Base class for output wrappers for formatted C++ ostream output.
Definition: Format.h:25
Wrapper for a std::string, for formatted ostream output.
Definition: Str.h:37
int width() const
Return default string width.
Definition: Str.cpp:43
Str()
Default constructor.
Definition: Str.cpp:17
void setValue(std::string value)
Set the string value.
Definition: Str.cpp:34
std::string value() const
Return string value.
Definition: Str.cpp:40
void setWidth(int width)
Set the default width.
Definition: Str.cpp:37
Utility classes for scientific computation.
Definition: accumulators.mod:1
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition: Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition: Pair.h:57