w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RosPrintfS.cpp
Go to the documentation of this file.
1// $Id: RosPrintfS.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2000-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-18 1089 1.1.1 use c++ style casts
8// 2018-12-17 1088 1.1 add bool specialization (use c++11 std::boolalpha)
9// 2011-02-25 364 1.0.1 allow NULL ptr for const char*, output <NULL>
10// 2011-01-30 357 1.0 Adopted from CTBprintfS
11// 2000-10-29 - - Last change on CTBprintfS
12// ---------------------------------------------------------------------------
13
18#include <iomanip>
19
20#include "RiosState.hpp"
21#include "RosPrintfS.hpp"
22
23using namespace std;
24
30// all method definitions in namespace Retro
31namespace Retro {
32
33//------------------------------------------+-----------------------------------
43template <class T>
44RosPrintfS<T>::RosPrintfS(T value, const char* form, int width, int prec)
45 : RosPrintfBase(form, width, prec),
46 fValue(value)
47{}
48
49//------------------------------------------+-----------------------------------
50template <class T>
51void RosPrintfS<T>::ToStream(std::ostream& os) const
52{
53 RiosState iostate(os, fForm, fPrec);
54 os << setw(fWidth) << fValue;
55}
56
57//------------------------------------------+-----------------------------------
58template <>
59void RosPrintfS<bool>::ToStream(std::ostream& os) const
60{
61 RiosState iostate(os, fForm, fPrec);
62 os << std::boolalpha << fValue;
63}
64
65//------------------------------------------+-----------------------------------
66template <>
67void RosPrintfS<char>::ToStream(std::ostream& os) const
68{
69 RiosState iostate(os, fForm, fPrec);
70 char ctype = iostate.Ctype();
71
72 os.width(fWidth);
73 if (ctype == 0 || ctype == 'c') {
74 os << fValue;
75 } else {
76 os << int(fValue);
77 }
78}
79
80//------------------------------------------+-----------------------------------
81template <>
82void RosPrintfS<int>::ToStream(std::ostream& os) const
83{
84 RiosState iostate(os, fForm, fPrec);
85 char ctype = iostate.Ctype();
86
87 os.width(fWidth);
88 if (ctype == 'c') {
89 os << char(fValue);
90 } else {
91 os << fValue;
92 }
93}
94
95//------------------------------------------+-----------------------------------
96template <>
97void RosPrintfS<const char *>::ToStream(std::ostream& os) const
98{
99 RiosState iostate(os, fForm, fPrec);
100 char ctype = iostate.Ctype();
101
102 os.width(fWidth);
103 if (ctype == 'p') {
104 os << reinterpret_cast<const void*>(fValue);
105 } else {
106 os << (fValue?fValue:"<NULL>");
107 }
108}
109
110//------------------------------------------+-----------------------------------
111template <>
112void RosPrintfS<const void *>::ToStream(std::ostream& os) const
113{
114 RiosState iostate(os, fForm, fPrec);
115 char ctype = iostate.Ctype();
116
117 os.width(fWidth);
118 if (ctype == 0 || ctype == 'p') {
119 os << fValue;
120 } else {
121 os << reinterpret_cast<unsigned long>(fValue);
122 }
123}
124
128
129// finally do an explicit instantiation of the required RosPrintfS
130
131template class RosPrintfS<bool>;
132template class RosPrintfS<char>;
133template class RosPrintfS<int>;
134template class RosPrintfS<unsigned int>;
135template class RosPrintfS<long>;
136template class RosPrintfS<unsigned long>;
137template class RosPrintfS<double>;
138
139template class RosPrintfS<const char *>;
140template class RosPrintfS<const void *>;
141
142} // end namespace Retro
Stack object for ostream state. **.
Definition: RiosState.hpp:23
Base class for print objects. **.
RosPrintfS(T value, const char *form, int width, int prec)
Constructor.
Definition: RosPrintfS.cpp:44
virtual void ToStream(std::ostream &os) const
Concrete implementation of the ostream insertion.
Definition: RosPrintfS.cpp:51
Print object for scalar values . **.
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47