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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [tools/] [src/] [librtools/] [RiosState.cpp] - Blame information for rev 40

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

Line No. Rev Author Line
1 19 wfjm
// $Id: RiosState.cpp 488 2013-02-16 18:49:47Z mueller $
2 10 wfjm
//
3
// Copyright 2006-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-01-30   357   1.0    Adopted from CTBioState
17
// 2006-04-16     -   -      Last change on CTBioState
18
// ---------------------------------------------------------------------------
19
 
20
/*!
21
  \file
22 19 wfjm
  \version $Id: RiosState.cpp 488 2013-02-16 18:49:47Z mueller $
23 10 wfjm
  \brief   Implemenation of RiosState.
24
*/
25
 
26
#include "RiosState.hpp"
27
 
28
using namespace std;
29
 
30
/*!
31
  \class Retro::RiosState
32
  \brief Stack object for ostream state. **
33
*/
34
 
35
//------------------------------------------+-----------------------------------
36 19 wfjm
// all method definitions in namespace Retro
37
namespace Retro {
38
 
39 10 wfjm
//! Construct with stream.
40
 
41
RiosState::RiosState(ios& stream)
42
  : fStream(stream)
43
{
44
  fOldFlags     = fStream.flags();
45
  fOldPrecision = -1;
46
  fOldFill      =  0;
47
  fCtype        =  0;
48
}
49
 
50
//------------------------------------------+-----------------------------------
51
//! Construct from stream and format.
52
 
53
RiosState::RiosState(ios& stream, const char* form, int prec)
54
  : fStream(stream)
55
{
56
  fOldFlags     = fStream.flags();
57
  fOldPrecision = -1;
58
  fOldFill      =  0;
59
  SetFormat(form, prec);
60
}
61
 
62
//------------------------------------------+-----------------------------------
63
//! Destructor.
64
 
65
RiosState::~RiosState()
66
{
67
  fStream.flags(fOldFlags);
68
  if (fOldPrecision >= 0) fStream.precision(fOldPrecision);
69
  if (fOldFill      != 0) fStream.fill(fOldFill);
70
}
71
 
72
//------------------------------------------+-----------------------------------
73
//! Setup format.
74
 
75
void RiosState::SetFormat(const char* form, int prec)
76
{
77
  bool    b_plus      = false;
78
  bool    b_minus     = false;
79
  bool    b_point     = false;
80
  bool    b_dollar    = false;
81
  bool    b_internal  = false;
82
  char    c_ctype     = 0;
83
  char    c_fill      = 0;
84
  char    c;
85
 
86
  if (form == 0) form = "";          // allow null as format
87
 
88
  for (c = *form++; ; c = *form++) {
89
    if (c == '+') { b_plus   = true; continue;}
90
    if (c == '-') { b_minus  = true; continue;}
91
    if (c == '.') { b_point  = true; continue;}
92
    if (c == '$') { b_dollar = true; continue;}
93
    break;
94
  }
95
 
96
  if (c != 0 && isalpha(c)) { c_ctype = c; c = *form++; }
97
  if (c != 0) c_fill = c;
98
 
99
  if (prec >= 0) {
100
    int i_old_precision = fStream.precision(prec);
101
    if (fOldPrecision < 0) fOldPrecision = i_old_precision;
102
  }
103
  if (c_fill != 0) {
104
    char c_old_fill = fStream.fill(c_fill);
105
    if (fOldFill == 0) fOldFill = c_old_fill;
106
  }
107
 
108
  fCtype = c_ctype;
109
 
110
  switch(c_ctype) {
111
    case 'd':
112
        b_internal = !b_minus & (c_fill == '0');
113
        fStream.setf(ios::dec,ios::basefield);
114
        break;
115
    case 'o':
116
        b_internal = !b_minus & (c_fill == '0');
117
        fStream.setf(ios::oct,ios::basefield);
118
        break;
119
    case 'x':
120
    case 'X':
121
        b_internal = !b_minus & (c_fill == '0');
122
        fStream.setf(ios::hex,ios::basefield);
123
        if (isupper(c_ctype)) fStream.setf(ios::uppercase);
124
        break;
125
    case 'g':
126
    case 'G':
127
        b_internal = !b_minus & (c_fill == '0');
128
        fStream.setf(ios_base::fmtflags(0),ios::floatfield);
129
        if (isupper(c_ctype)) fStream.setf(ios::uppercase);
130
        break;
131
    case 'f':
132
        b_internal = !b_minus & (c_fill == '0');
133
        fStream.setf(ios::fixed,ios::floatfield);
134
        break;
135
    case 'e':
136
    case 'E':
137
        b_internal = !b_minus & (c_fill == '0');
138
        fStream.setf(ios::scientific,ios::floatfield);
139
        if (isupper(c_ctype)) fStream.setf(ios::uppercase);
140
        break;
141
    case 's':
142
    case 'p':
143
    case 'c':
144
        break;
145
  }
146
 
147
  {
148
    ios_base::fmtflags l_flags = ios_base::fmtflags(0);
149
    if (b_plus)   l_flags |= ios::showpos;
150
    if (b_point)  l_flags |= ios::showpoint;
151
    if (b_dollar) l_flags |= ios::showbase;
152
    fStream.setf(l_flags);
153
    fStream.setf(b_internal ? ios::internal :
154
                   (b_minus ? ios::left : ios::right), ios::adjustfield);
155
  }
156
}
157
 
158 19 wfjm
} // end namespace Retro

powered by: WebSVN 2.1.0

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