vtkOStreamWrapper.h 4.71 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkOStreamWrapper.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
9
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

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

=========================================================================*/
15
16
17
18
19
20
21
22
23
24
25
/**
 * @class   vtkOStreamWrapper
 * @brief   Wrapper for C++ ostream.  Internal VTK use only.
 *
 * Provides a wrapper around the C++ ostream so that VTK source files
 * need not include the full C++ streams library.  This is intended to
 * prevent cluttering of the translation unit and speed up
 * compilation.  Experimentation has revealed between 10% and 60% less
 * time for compilation depending on the platform.  This wrapper is
 * used by the macros in vtkSetGet.h.
*/
26

27
28
#ifndef vtkOStreamWrapper_h
#define vtkOStreamWrapper_h
29
#ifndef __VTK_WRAP__
30

VTK Developers's avatar
VTK Developers committed
31
32
#include "vtkCommonCoreModule.h"

33
34
#ifndef VTK_SYSTEM_INCLUDES_INSIDE
Do_not_include_vtkOStreamWrapper_directly_vtkSystemIncludes_includes_it;
35
36
37
38
39
#endif

class vtkIndent;
class vtkObjectBase;
class vtkLargeInteger;
40
class vtkSmartPointerBase;
41
class vtkStdString;
42

VTK Developers's avatar
VTK Developers committed
43
class VTKCOMMONCORE_EXPORT vtkOStreamWrapper
44
{
45
  class std_string;
46
public:
47
48
49
50
51
  //@{
  /**
   * Construct class to reference a real ostream.  All methods and
   * operators will be forwarded.
   */
52
53
  vtkOStreamWrapper(ostream& os);
  vtkOStreamWrapper(vtkOStreamWrapper& r);
54
  //@}
55
56
57

  virtual ~vtkOStreamWrapper();

58
59
60
  /**
   * Type for a fake endl.
   */
61
  struct EndlType {};
62

63
64
65
66
  //@{
  /**
   * Forward this output operator to the real ostream.
   */
67
  vtkOStreamWrapper& operator << (const EndlType&);
68
69
70
  vtkOStreamWrapper& operator << (const vtkIndent&);
  vtkOStreamWrapper& operator << (vtkObjectBase&);
  vtkOStreamWrapper& operator << (const vtkLargeInteger&);
71
  vtkOStreamWrapper& operator << (const vtkSmartPointerBase&);
72
  vtkOStreamWrapper& operator << (const vtkStdString&);
73
  vtkOStreamWrapper& operator << (const char*);
74
  vtkOStreamWrapper& operator << (void*);
75
76
77
78
  vtkOStreamWrapper& operator << (char);
  vtkOStreamWrapper& operator << (short);
  vtkOStreamWrapper& operator << (int);
  vtkOStreamWrapper& operator << (long);
79
  vtkOStreamWrapper& operator << (long long);
80
81
82
83
  vtkOStreamWrapper& operator << (unsigned char);
  vtkOStreamWrapper& operator << (unsigned short);
  vtkOStreamWrapper& operator << (unsigned int);
  vtkOStreamWrapper& operator << (unsigned long);
84
  vtkOStreamWrapper& operator << (unsigned long long);
85
86
  vtkOStreamWrapper& operator << (float);
  vtkOStreamWrapper& operator << (double);
87
  vtkOStreamWrapper& operator << (bool);
88
  //@}
89

90
91
  // Work-around for IBM Visual Age bug in overload resolution.
#if defined(__IBMCPP__)
92
93
  vtkOStreamWrapper& WriteInternal(const char*);
  vtkOStreamWrapper& WriteInternal(void*);
94
95
  template <typename T>
  vtkOStreamWrapper& operator << (T* p)
96
  {
97
    return this->WriteInternal(p);
98
  }
99
100
#endif

101
102
103
104
105
106
107
  vtkOStreamWrapper& operator << (void (*)(void*));
  vtkOStreamWrapper& operator << (void* (*)(void*));
  vtkOStreamWrapper& operator << (int (*)(void*));
  vtkOStreamWrapper& operator << (int* (*)(void*));
  vtkOStreamWrapper& operator << (float* (*)(void*));
  vtkOStreamWrapper& operator << (const char* (*)(void*));
  vtkOStreamWrapper& operator << (void (*)(void*, int*));
108

109
110
111
112
  // Accept std::string without a declaration.
  template <template <typename, typename, typename> class S>
  vtkOStreamWrapper& operator << (const
    S< char, std::char_traits<char>, std::allocator<char> >& s)
113
  {
114
    return *this << reinterpret_cast<std_string const&>(s);
115
  }
116

117
118
119
  /**
   * Forward the write method to the real stream.
   */
120
  vtkOStreamWrapper& write(const char*, unsigned long);
121

122
123
124
  /**
   * Get a reference to the real ostream.
   */
125
126
  ostream& GetOStream();

127
128
129
130
131
  /**
   * Allow conversion to the real ostream type.  This allows an
   * instance of vtkOStreamWrapper to look like ostream when passing to a
   * function argument.
   */
132
133
  operator ostream&();

134
135
136
  /**
   * Forward conversion to bool to the real ostream.
   */
137
  operator int();
138

139
140
141
  /**
   * Forward the flush method to the real ostream.
   */
142
  void flush();
143

144
145
146
147
148
  //@{
  /**
   * Implementation detail to allow macros to provide an endl that may
   * or may not be used.
   */
149
  static void UseEndl(const EndlType&) {}
150
151
152
153
protected:
  // Reference to the real ostream.
  ostream& ostr;
private:
154
  vtkOStreamWrapper& operator=(const vtkOStreamWrapper& r) = delete;
155
  vtkOStreamWrapper& operator << (std_string const&);
156
};
157
  //@}
158

159
#endif
160
#endif
161
// VTK-HeaderTest-Exclude: vtkOStreamWrapper.h