HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
streamOut.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_VT_STREAM_OUT_H
25 #define PXR_BASE_VT_STREAM_OUT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/vt/api.h"
29 #include "pxr/base/tf/enum.h"
30 
31 #include <iosfwd>
32 #include <typeinfo>
33 #include <type_traits>
34 
36 
37 // Helper that's used to stream a generic string for a type that isn't
38 // streamable and doesn't provide VtStreamOut. Inserts a message like
39 // <'typeName' @ 0xXXXXXXXX>.
40 VT_API std::ostream &
41 Vt_StreamOutGeneric(std::type_info const &type,
42  void const *addr,
43  std::ostream &stream);
44 
45 // Function used in the case that T has a stream insertion operator.
46 template <class T>
47 inline auto
48 Vt_StreamOutImpl(T const &obj, std::ostream &stream, int)
49  -> decltype(stream << obj)
50 {
51  return stream << obj;
52 }
53 
54 // Function used in the case that T does not have a stream insertion operator.
55 template <class T>
56 inline std::ostream &
57 Vt_StreamOutImpl(T const &obj, std::ostream &stream, long)
58 {
59  return Vt_StreamOutGeneric(
60  typeid(T), static_cast<void const *>(&obj), stream);
61 }
62 
63 /// VtValue and VtArray make unqualified calls to VtStreamOut when writing
64 /// values to streams. Clients may overload VtStreamOut for their own types
65 /// if desired.
66 template <class T>
67 typename std::enable_if<!std::is_enum<T>::value, std::ostream &>::type
68 VtStreamOut(T const &obj, std::ostream &stream)
69 {
70  // For types that have an operator<< suitable for ostream, we use the
71  // traditional int/long 0-argument technique to disambiguate overloads.
72  return Vt_StreamOutImpl(obj, stream, 0);
73 }
74 template <class EnumT>
76 VtStreamOut(EnumT const &e, std::ostream &stream)
77 {
78  return VtStreamOut(TfEnum::GetName(e), stream);
79 }
80 VT_API std::ostream &VtStreamOut(bool const &, std::ostream &);
81 VT_API std::ostream &VtStreamOut(char const &, std::ostream &);
82 VT_API std::ostream &VtStreamOut(unsigned char const &, std::ostream &);
83 VT_API std::ostream &VtStreamOut(signed char const &, std::ostream &);
84 VT_API std::ostream &VtStreamOut(float const &, std::ostream &);
85 VT_API std::ostream &VtStreamOut(double const &, std::ostream &);
86 
88 public:
89  VT_API virtual ~VtStreamOutIterator();
90  virtual void Next(std::ostream&) = 0;
91 };
92 
93 struct Vt_ShapeData;
94 
96  const Vt_ShapeData*, std::ostream&);
97 
98 #ifdef PXR_PYTHON_SUPPORT_ENABLED
99 VT_API std::ostream &VtStreamOut(class TfPyObjWrapper const &, std::ostream &);
100 #endif // PXR_PYTHON_SUPPORT_ENABLED
101 
103 
104 #endif // PXR_BASE_VT_STREAM_OUT_H
GLsizeiptr size
Definition: glew.h:1681
GLuint GLuint stream
Definition: glew.h:7265
#define VT_API
Definition: api.h:40
GLhandleARB obj
Definition: glew.h:6236
virtual VT_API ~VtStreamOutIterator()
std::enable_if<!std::is_enum< T >::value, std::ostream & >::type VtStreamOut(T const &obj, std::ostream &stream)
Definition: streamOut.h:68
virtual void Next(std::ostream &)=0
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GLenum void * addr
Definition: glew.h:11505
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
PXR_NAMESPACE_OPEN_SCOPE VT_API std::ostream & Vt_StreamOutGeneric(std::type_info const &type, void const *addr, std::ostream &stream)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static TF_API std::string GetName(TfEnum val)
VT_API void VtStreamOutArray(VtStreamOutIterator *, size_t size, const Vt_ShapeData *, std::ostream &)
auto Vt_StreamOutImpl(T const &obj, std::ostream &stream, int) -> decltype(stream<< obj)
Definition: streamOut.h:48
GLsizei const GLfloat * value
Definition: glew.h:1849