switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Format.cci
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief Format inline non-template implementation */
30
31 #include "Format.ih"
32
33 // Custom includes
34
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::format::eng
40
41 prefix_ senf::format::eng::eng(float v, float d)
42     : v_ (v), d_ (d), haveWidth_ (false), width_ (0), havePrecision_ (false), precision_ (0),
43       haveFill_ (false), fill_ (' '), mask_ (), flags_ ()
44 {}
45
46 prefix_ senf::format::eng const & senf::format::eng::setw(unsigned w)
47     const
48 {
49     haveWidth_ = true;
50     width_ = w;
51     return *this;
52 }
53
54 prefix_ senf::format::eng const & senf::format::eng::setprecision(unsigned p)
55     const
56 {
57     havePrecision_ = true;
58     precision_ = p;
59     return *this;
60 }
61
62 prefix_ senf::format::eng const & senf::format::eng::setfill(char c)
63     const
64 {
65     haveFill_ = true;
66     fill_ = c;
67     return *this;
68 }
69
70 prefix_ senf::format::eng const & senf::format::eng::showbase()
71     const
72 {
73     mask_ |= std::ios_base::showbase;
74     flags_ |= std::ios_base::showbase;
75     return *this;
76 }
77
78 prefix_ senf::format::eng const & senf::format::eng::noshowbase()
79     const
80 {
81     mask_ |= std::ios_base::showbase;
82     flags_ &= ~std::ios_base::showbase;
83     return *this;
84 }
85
86 prefix_ senf::format::eng const & senf::format::eng::showpos()
87     const
88 {
89     mask_ |= std::ios_base::showpos;
90     flags_ |= std::ios_base::showpos;
91     return *this;
92 }
93
94 prefix_ senf::format::eng const & senf::format::eng::noshowpos()
95     const
96 {
97     mask_ |= std::ios_base::showpos;
98     flags_ &= ~std::ios_base::showpos;
99     return *this;
100 }
101
102 prefix_ senf::format::eng const & senf::format::eng::showpoint()
103     const
104 {
105     mask_ |= std::ios_base::showpoint;
106     flags_ |= std::ios_base::showpoint;
107     return *this;
108 }
109
110 prefix_ senf::format::eng const & senf::format::eng::noshowpoint()
111     const
112 {
113     mask_ |= std::ios_base::showpoint;
114     flags_ &= ~std::ios_base::showpoint;
115     return *this;
116 }
117
118 prefix_ senf::format::eng const & senf::format::eng::uppercase()
119     const
120 {
121     mask_ |= std::ios_base::uppercase;
122     flags_ |= std::ios_base::uppercase;
123     return *this;
124 }
125
126 prefix_ senf::format::eng const & senf::format::eng::nouppercase()
127     const
128 {
129     mask_ |= std::ios_base::uppercase;
130     flags_ &= ~std::ios_base::uppercase;
131     return *this;
132 }
133
134 prefix_ senf::format::eng const & senf::format::eng::left()
135     const
136 {
137     mask_ |= std::ios_base::adjustfield;
138     flags_ &= ~std::ios_base::adjustfield;
139     flags_ |= std::ios_base::left;
140     return *this;
141 }
142
143 prefix_ senf::format::eng const & senf::format::eng::internal()
144     const
145 {
146     mask_ |= std::ios_base::adjustfield;
147     flags_ &= ~std::ios_base::adjustfield;
148     flags_ |= std::ios_base::internal;
149     return *this;
150 }
151
152 prefix_ senf::format::eng const & senf::format::eng::right()
153     const
154 {
155     mask_ |= std::ios_base::adjustfield;
156     flags_ &= ~std::ios_base::adjustfield;
157     flags_ |= std::ios_base::right;
158     return *this;
159 }
160
161 //-/////////////////////////////////////////////////////////////////////////////////////////////////
162 // senf::format::IndentHelper
163
164 prefix_ senf::format::IndentHelper::IndentHelper()
165     : instance_level(1)
166 {
167     ++static_level;
168 }
169
170 prefix_ senf::format::IndentHelper::~IndentHelper()
171 {
172     static_level -= instance_level;
173 }
174
175 prefix_ void senf::format::IndentHelper::increase()
176 {
177     ++static_level;
178     ++instance_level;
179 }
180
181 prefix_ unsigned int senf::format::IndentHelper::level()
182     const
183 {
184     return static_level;
185 }
186
187 prefix_ std::ostream & senf::format::operator<<(std::ostream & os, senf::format::IndentHelper const & indent)
188 {
189     for (unsigned int i=0, j=indent.level(); i<j; ++i)
190         os << "  ";
191     return os;
192 }
193
194
195
196
197
198
199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
200 #undef prefix_
201
202 \f
203 // Local Variables:
204 // mode: c++
205 // fill-column: 100
206 // comment-column: 40
207 // c-file-style: "senf"
208 // indent-tabs-mode: nil
209 // ispell-local-dictionary: "american"
210 // compile-command: "scons -u test"
211 // End: