Format.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief Format inline non-template implementation */
16 
17 #include "Format.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::format::eng
26 
27 prefix_ senf::format::eng::eng(float v, float d)
28  : v_ (v), d_ (d), haveWidth_ (false), width_ (0), havePrecision_ (false), precision_ (0),
29  haveFill_ (false), fill_ (' '), mask_ (), flags_ ()
30 {}
31 
32 prefix_ senf::format::eng const & senf::format::eng::setw(unsigned w)
33  const
34 {
35  haveWidth_ = true;
36  width_ = w;
37  return *this;
38 }
39 
40 prefix_ senf::format::eng const & senf::format::eng::setprecision(unsigned p)
41  const
42 {
43  havePrecision_ = true;
44  precision_ = p;
45  return *this;
46 }
47 
48 prefix_ senf::format::eng const & senf::format::eng::setfill(char c)
49  const
50 {
51  haveFill_ = true;
52  fill_ = c;
53  return *this;
54 }
55 
56 prefix_ senf::format::eng const & senf::format::eng::showbase()
57  const
58 {
59  mask_ |= std::ios_base::showbase;
60  flags_ |= std::ios_base::showbase;
61  return *this;
62 }
63 
64 prefix_ senf::format::eng const & senf::format::eng::noshowbase()
65  const
66 {
67  mask_ |= std::ios_base::showbase;
68  flags_ &= ~std::ios_base::showbase;
69  return *this;
70 }
71 
72 prefix_ senf::format::eng const & senf::format::eng::showpos()
73  const
74 {
75  mask_ |= std::ios_base::showpos;
76  flags_ |= std::ios_base::showpos;
77  return *this;
78 }
79 
80 prefix_ senf::format::eng const & senf::format::eng::noshowpos()
81  const
82 {
83  mask_ |= std::ios_base::showpos;
84  flags_ &= ~std::ios_base::showpos;
85  return *this;
86 }
87 
88 prefix_ senf::format::eng const & senf::format::eng::showpoint()
89  const
90 {
91  mask_ |= std::ios_base::showpoint;
92  flags_ |= std::ios_base::showpoint;
93  return *this;
94 }
95 
96 prefix_ senf::format::eng const & senf::format::eng::noshowpoint()
97  const
98 {
99  mask_ |= std::ios_base::showpoint;
100  flags_ &= ~std::ios_base::showpoint;
101  return *this;
102 }
103 
104 prefix_ senf::format::eng const & senf::format::eng::uppercase()
105  const
106 {
107  mask_ |= std::ios_base::uppercase;
108  flags_ |= std::ios_base::uppercase;
109  return *this;
110 }
111 
112 prefix_ senf::format::eng const & senf::format::eng::nouppercase()
113  const
114 {
115  mask_ |= std::ios_base::uppercase;
116  flags_ &= ~std::ios_base::uppercase;
117  return *this;
118 }
119 
120 prefix_ senf::format::eng const & senf::format::eng::left()
121  const
122 {
123  mask_ |= std::ios_base::adjustfield;
124  flags_ &= ~std::ios_base::adjustfield;
125  flags_ |= std::ios_base::left;
126  return *this;
127 }
128 
129 prefix_ senf::format::eng const & senf::format::eng::internal()
130  const
131 {
132  mask_ |= std::ios_base::adjustfield;
133  flags_ &= ~std::ios_base::adjustfield;
134  flags_ |= std::ios_base::internal;
135  return *this;
136 }
137 
138 prefix_ senf::format::eng const & senf::format::eng::right()
139  const
140 {
141  mask_ |= std::ios_base::adjustfield;
142  flags_ &= ~std::ios_base::adjustfield;
143  flags_ |= std::ios_base::right;
144  return *this;
145 }
146 
147 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 // senf::format::IndentHelper
149 
150 prefix_ senf::format::IndentHelper::IndentHelper()
151  : instance_level(1)
152 {
153  ++static_level;
154 }
155 
156 prefix_ senf::format::IndentHelper::~IndentHelper()
157 {
158  static_level -= instance_level;
159 }
160 
161 prefix_ void senf::format::IndentHelper::increase()
162 {
163  ++static_level;
164  ++instance_level;
165 }
166 
167 prefix_ unsigned int senf::format::IndentHelper::level()
168  const
169 {
170  return static_level;
171 }
172 
173 prefix_ std::ostream & senf::format::operator<<(std::ostream & os, senf::format::IndentHelper const & indent)
174 {
175  for (unsigned int i=0, j=indent.level(); i<j; ++i)
176  os << " ";
177  return os;
178 }
179 
180 //-/////////////////////////////////////////////////////////////////////////////////////////////////
181 #undef prefix_
182 
183 
184 // Local Variables:
185 // mode: c++
186 // fill-column: 100
187 // comment-column: 40
188 // c-file-style: "senf"
189 // indent-tabs-mode: nil
190 // ispell-local-dictionary: "american"
191 // compile-command: "scons -u test"
192 // End: