summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/kwsys_ios_sstream.h.in
blob: 42e247e998d41223d9677ce05e3683286e22ef16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*=========================================================================

  Program:   KWSys - Kitware System Library
  Module:    $RCSfile$

  Copyright (c) Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_ios_sstream
#define @KWSYS_NAMESPACE@_ios_sstream

#include <@KWSYS_NAMESPACE@/Configure.hxx>

/* Define this macro temporarily to keep the code readable.  */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl
#endif

#if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
# ifdef _MSC_VER
#  pragma warning (push, 1)
#  pragma warning (disable: 4702)
# endif
# include <sstream>
# ifdef _MSC_VER
#  pragma warning(pop)
# endif
#else
# ifdef _MSC_VER
#  pragma warning (push, 1)
#  pragma warning (disable: 4702)
#  pragma warning (disable: 4995) /* Old streams are deprecated.  */
# endif
# if @KWSYS_NAMESPACE@_IOS_USE_ANSI
#  include <strstream>
# elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
#  include <strstream.h>
# elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
#  include <strstrea.h>
# endif
# if @KWSYS_NAMESPACE@_IOS_USE_ANSI
#  include <new> // Need placement operator new.
# else
#  include <new.h> // Need placement operator new.
# endif
# ifdef _MSC_VER
#  pragma warning(pop)
# endif

// Only have old std::strstream classes.  Wrap them to look like new
// ostringstream and istringstream classes.

# include <@KWSYS_NAMESPACE@/stl/string>

namespace @KWSYS_NAMESPACE@_ios
{
using @KWSYS_NAMESPACE@_ios_namespace::streambuf;
using @KWSYS_NAMESPACE@_ios_namespace::ostream;
using @KWSYS_NAMESPACE@_ios_namespace::istream;
using @KWSYS_NAMESPACE@_ios_namespace::strstream;
using @KWSYS_NAMESPACE@_ios_namespace::istrstream;
using @KWSYS_NAMESPACE@_ios_namespace::ostrstream;
using @KWSYS_NAMESPACE@_ios_namespace::ios;
using @KWSYS_NAMESPACE@_ios_namespace::endl;
using @KWSYS_NAMESPACE@_ios_namespace::ends;
using @KWSYS_NAMESPACE@_ios_namespace::flush;

class stringstream_cleanup
{
public:
  stringstream_cleanup(strstream& str): m_StrStream(str) {}
  ~stringstream_cleanup() { m_StrStream.rdbuf()->freeze(0); }
  static void IgnoreUnusedVariable(const stringstream_cleanup&) {}
protected:
  strstream& m_StrStream;
private:
  void operator=(stringstream_cleanup const&);
};

class stringstream: public strstream
{
public:
  typedef strstream Superclass;
  stringstream() {}
  stringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
  kwsys_stl::string str()
    {
    stringstream_cleanup cleanup(*this);
    stringstream_cleanup::IgnoreUnusedVariable(cleanup);
// Visual Studio 6 has a strstream::pcount, but this is not rdbuf()->pcount()
#if (@KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H) && defined(_MSC_VER) && (_MSC_VER == 1200)
    int count = this->pcount();
#elif defined(__WATCOMC__)
    int count = this->rdbuf()->out_waiting();
#else
    int count = this->rdbuf()->pcount();
#endif
    const char* ptr = this->Superclass::str();
    return kwsys_stl::string(ptr?ptr:"", count);
    }
  void str(const kwsys_stl::string& s)
    {
    this->~stringstream();
    new (this) stringstream(s);
    }
private:
  stringstream(const stringstream&);
  void operator=(const stringstream&);
};

class ostringstream_cleanup
{
public:
  ostringstream_cleanup(ostrstream& ostr): m_OStrStream(ostr) {}
  ~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
  static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
protected:
  ostrstream& m_OStrStream;
private:
  void operator=(ostringstream_cleanup const&);
};

class ostringstream: public ostrstream
{
public:
  typedef ostrstream Superclass;
  ostringstream() {}
  ostringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
  kwsys_stl::string str()
    {
    ostringstream_cleanup cleanup(*this);
    ostringstream_cleanup::IgnoreUnusedVariable(cleanup);
    int count = this->pcount();
    const char* ptr = this->Superclass::str();
    return kwsys_stl::string(ptr?ptr:"", count);
    }
  void str(const kwsys_stl::string& s)
    {
    this->~ostringstream();
    new (this) ostringstream(s);
    }
private:
  ostringstream(const ostringstream&);
  void operator=(const ostringstream&);
};

#if defined(_MSC_VER)
# pragma warning (push)
# pragma warning (disable: 4097) /* typedef-name used as synonym for class */
#endif
#if defined(__WATCOMC__)
// W728: class modifiers for 'A' conflict with class modifiers for 'B'
# pragma warning 728 10
#endif

class istringstream: private kwsys_stl::string, public istrstream
{
public:
  typedef kwsys_stl::string StdString;
  typedef istrstream IStrStream;
  istringstream(): StdString(),
                   IStrStream(const_cast<char*>(StdString::c_str())) {}
  istringstream(const kwsys_stl::string& s):
    StdString(s), IStrStream(const_cast<char*>(StdString::c_str())) {}
  kwsys_stl::string str() const { return *this; }
  void str(const kwsys_stl::string& s)
    {
    this->~istringstream();
    new (this) istringstream(s);
    }
  void clear(int flags)
    {
    this->IStrStream::clear(flags);
    }
private:
  istringstream(const istringstream&);
  void operator=(const istringstream&);
};

#if defined(__WATCOMC__)
# pragma warning 728 9
#endif
#if defined(_MSC_VER)
# pragma warning (pop)
#endif

} // namespace @KWSYS_NAMESPACE@_ios

#endif

/* Undefine temporary macro.  */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
#endif

#endif