OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [src/] [librtools/] [RosPrintfS.cpp] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 wfjm
// $Id: RosPrintfS.cpp 488 2013-02-16 18:49:47Z mueller $
2 10 wfjm
//
3
// Copyright 2000-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16
// 2011-02-25   364   1.0.1  allow NULL ptr for const char*, output <NULL>
17
// 2011-01-30   357   1.0    Adopted from CTBprintfS
18
// 2000-10-29     -   -      Last change on CTBprintfS
19
// ---------------------------------------------------------------------------
20
 
21
/*!
22
  \file
23 19 wfjm
  \version $Id: RosPrintfS.cpp 488 2013-02-16 18:49:47Z mueller $
24 10 wfjm
  \brief   Implemenation of RosPrintfS .
25
*/
26
 
27
#include <iomanip>
28
 
29
#include "RiosState.hpp"
30
#include "RosPrintfS.hpp"
31
 
32
using namespace std;
33
 
34
/*!
35
  \class RosPrintfS
36
  \brief Print object for scalar values . **
37
*/
38
 
39 19 wfjm
// all method definitions in namespace Retro
40
namespace Retro {
41
 
42 10 wfjm
//------------------------------------------+-----------------------------------
43
/*!
44
  \brief Constructor.
45
 
46
  \param value  value to be printed
47
  \param form   format descriptor string
48
  \param width  field width
49
  \param prec   precision
50
*/
51
 
52
template <class T>
53
RosPrintfS<T>::RosPrintfS(T value, const char* form, int width, int prec)
54
  : RosPrintfBase(form, width, prec),
55
    fValue(value)
56
{}
57
 
58
//------------------------------------------+-----------------------------------
59
template <class T>
60
void RosPrintfS<T>::ToStream(std::ostream& os) const
61
{
62
  RiosState iostate(os, fForm, fPrec);
63
  os << setw(fWidth) << fValue;
64
}
65
 
66
//------------------------------------------+-----------------------------------
67
template <>
68
void RosPrintfS<char>::ToStream(std::ostream& os) const
69
{
70
  RiosState  iostate(os, fForm, fPrec);
71
  char       ctype = iostate.Ctype();
72
 
73
  os.width(fWidth);
74
  if (ctype == 0 || ctype == 'c') {
75
    os << fValue;
76
  } else {
77
    os << (int) fValue;
78
  }
79
}
80
 
81
//------------------------------------------+-----------------------------------
82
template <>
83
void RosPrintfS<int>::ToStream(std::ostream& os) const
84
{
85
  RiosState  iostate(os, fForm, fPrec);
86
  char       ctype = iostate.Ctype();
87
 
88
  os.width(fWidth);
89
  if (ctype == 'c') {
90
    os << (char) fValue;
91
  } else {
92
    os << fValue;
93
  }
94
}
95
 
96
//------------------------------------------+-----------------------------------
97
template <>
98
void RosPrintfS<const char *>::ToStream(std::ostream& os) const
99
{
100
  RiosState  iostate(os, fForm, fPrec);
101
  char       ctype = iostate.Ctype();
102
 
103
  os.width(fWidth);
104
  if (ctype == 'p') {
105
    os << (const void*) fValue;
106
  } else {
107
    os << (fValue?fValue:"<NULL>");
108
  }
109
}
110
 
111
//------------------------------------------+-----------------------------------
112
template <>
113
void RosPrintfS<const void *>::ToStream(std::ostream& os) const
114
{
115
  RiosState  iostate(os, fForm, fPrec);
116
  char       ctype = iostate.Ctype();
117
 
118
  os.width(fWidth);
119
  if (ctype == 0 || ctype == 'p') {
120
    os << fValue;
121
  } else {
122
    os << (unsigned long) fValue;
123
  }
124
}
125
 
126
//!! Note:
127
//!!  1.  This specialization is printing signed and unsigned char types and
128
//!!      implements the `c' conversion format,
129
 
130
// finally do an explicit instantiation of the required CTBioState
131
 
132
template class RosPrintfS<char>;
133
template class RosPrintfS<int>;
134
template class RosPrintfS<unsigned int>;
135
template class RosPrintfS<long>;
136
template class RosPrintfS<unsigned long>;
137
template class RosPrintfS<double>;
138
 
139
template class RosPrintfS<const char *>;
140
template class RosPrintfS<const void *>;
141 19 wfjm
 
142
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.