VTK  9.7.20260824
vtkOStreamWrapper.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
14
15#ifndef vtkOStreamWrapper_h
16#define vtkOStreamWrapper_h
17
18#include "vtkCommonCoreModule.h"
19
20#include <type_traits>
21
22#ifndef VTK_SYSTEM_INCLUDES_INSIDE
24#endif
25
26VTK_ABI_NAMESPACE_BEGIN
27class vtkIndent;
28class vtkObjectBase;
29class vtkLargeInteger;
30template <typename T>
31class vtkSmartPointer;
33class vtkStdString;
34
35class VTKCOMMONCORE_EXPORT VTK_WRAPEXCLUDE vtkOStreamWrapper
36{
37 class std_string;
38 class std_string_view;
39
40public:
42
46 vtkOStreamWrapper(ostream& os);
49
51
55 struct EndlType
56 {
57 };
58
60
77 vtkOStreamWrapper& operator<<(unsigned short);
80 vtkOStreamWrapper& operator<<(unsigned long long);
85
86 // Work-around for IBM Visual Age bug in overload resolution.
87#if defined(__IBMCPP__)
88 vtkOStreamWrapper& WriteInternal(const char*);
89 vtkOStreamWrapper& WriteInternal(void*);
90 template <typename T>
92 {
93 return this->WriteInternal(p);
94 }
95#endif
96
97 vtkOStreamWrapper& operator<<(void (*)(void*));
98 vtkOStreamWrapper& operator<<(void* (*)(void*));
99 vtkOStreamWrapper& operator<<(int (*)(void*));
100 vtkOStreamWrapper& operator<<(int* (*)(void*));
101 vtkOStreamWrapper& operator<<(float* (*)(void*));
102 vtkOStreamWrapper& operator<<(const char* (*)(void*));
103 vtkOStreamWrapper& operator<<(void (*)(void*, int*));
104
105 // Accept std::string without a declaration.
106 template <template <typename, typename, typename> class S>
107 vtkOStreamWrapper& operator<<(const S<char, std::char_traits<char>, std::allocator<char>>& s)
108 {
109 return *this << reinterpret_cast<std_string const&>(s);
110 }
111
112 // Accept std::string_view without a declaration. The trivially-copyable
113 // constraint keeps this from also matching std::basic_string (whose
114 // allocator parameter is defaulted and would otherwise be deduced too).
115 template <template <typename, typename> class S,
116 typename = std::enable_if_t<std::is_trivially_copyable<S<char, std::char_traits<char>>>::value>>
117 vtkOStreamWrapper& operator<<(const S<char, std::char_traits<char>>& s)
118 {
119 return *this << reinterpret_cast<std_string_view const&>(s);
120 }
121
122 // Accept vtkSmartPointer for output.
123 template <typename T>
125 {
126 this->ostr << (static_cast<T*>(ptr));
127 return *this;
128 }
129
133 vtkOStreamWrapper& write(const char*, unsigned long);
134
138 ostream& GetOStream();
139
145 operator ostream&();
146
150 operator int();
151
155 void flush();
156
158
162 static void UseEndl(const EndlType&) {}
164protected:
165 // Reference to the real ostream.
166 ostream& ostr;
167
168private:
169 vtkOStreamWrapper& operator=(const vtkOStreamWrapper& r) = delete;
170 vtkOStreamWrapper& operator<<(std_string const&);
171 vtkOStreamWrapper& operator<<(std_string_view const&);
172};
173
174VTK_ABI_NAMESPACE_END
175#endif
176// VTK-HeaderTest-Exclude: vtkOStreamWrapper.h
a simple class to control print indentation
Definition vtkIndent.h:108
class for arbitrarily large ints
vtkOStreamWrapper & operator<<(const vtkIndent &)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(vtkObjectBase &)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(int *(*)(void *))
vtkOStreamWrapper & operator<<(char)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(short)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(float *(*)(void *))
vtkOStreamWrapper & operator<<(void *)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(const vtkLargeInteger &)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(const vtkSmartPointerBase &)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(const char *(*)(void *))
vtkOStreamWrapper & write(const char *, unsigned long)
Forward the write method to the real stream.
vtkOStreamWrapper & operator<<(const vtkSmartPointer< T > &ptr)
vtkOStreamWrapper & operator<<(const char *)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(const vtkStdString &)
Forward this output operator to the real ostream.
virtual ~vtkOStreamWrapper()
static void UseEndl(const EndlType &)
Implementation detail to allow macros to provide an endl that may or may not be used.
vtkOStreamWrapper & operator<<(double)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(unsigned long long)
Forward this output operator to the real ostream.
vtkOStreamWrapper(ostream &os)
Construct class to reference a real ostream.
ostream & GetOStream()
Get a reference to the real ostream.
vtkOStreamWrapper & operator<<(void(*)(void *))
void flush()
Forward the flush method to the real ostream.
vtkOStreamWrapper & operator<<(unsigned long)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(int(*)(void *))
vtkOStreamWrapper & operator<<(const EndlType &)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(unsigned char)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(long long)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(bool)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(float)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(unsigned short)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(long)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(int)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(const S< char, std::char_traits< char >, std::allocator< char > > &s)
vtkOStreamWrapper & operator<<(void *(*)(void *))
vtkOStreamWrapper(vtkOStreamWrapper &r)
Construct class to reference a real ostream.
vtkOStreamWrapper & operator<<(const S< char, std::char_traits< char > > &s)
vtkOStreamWrapper & operator<<(unsigned int)
Forward this output operator to the real ostream.
vtkOStreamWrapper & operator<<(void(*)(void *, int *))
abstract base class for most VTK objects
Non-templated superclass for vtkSmartPointer.
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkIndent &o)
Do_not_include_vtkOStreamWrapper_directly_vtkSystemIncludes_includes_it
#define VTK_WRAPEXCLUDE