Simpatico  v1.10
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 
13 namespace 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:24
friend std::istream & operator>>(std::istream &in, Str &object)
Input stream extractor for an Str object.
Definition: Str.cpp:49
Str()
Default constructor.
Definition: Str.cpp:17
Utility classes for scientific computation.
Definition: accumulators.mod:1
friend std::ostream & operator<<(std::ostream &out, const Str &object)
Output stream inserter for an Str object.
Definition: Str.cpp:58
Wrapper for a std::string, for formatted ostream output.
Definition: Str.h:36