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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_VT_STREAM_OUT_H
8 #define PXR_BASE_VT_STREAM_OUT_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/vt/api.h"
12 #include "pxr/base/tf/enum.h"
14 
15 #include <iosfwd>
16 #include <typeinfo>
17 #include <type_traits>
18 
20 
21 // Helper that's used to stream a generic string for a type that isn't
22 // streamable and doesn't provide VtStreamOut. Inserts a message like
23 // <'typeName' @ 0xXXXXXXXX>.
24 VT_API std::ostream &
25 Vt_StreamOutGeneric(std::type_info const &type,
26  void const *addr,
27  std::ostream &stream);
28 
29 // Function used in the case that T has a stream insertion operator.
30 template <class T>
31 inline auto
32 Vt_StreamOutImpl(T const &obj, std::ostream &stream, int)
33  -> decltype(stream << obj)
34 {
35  return stream << obj;
36 }
37 
38 // Function used in the case that T does not have a stream insertion operator.
39 template <class T>
40 inline std::ostream &
41 Vt_StreamOutImpl(T const &obj, std::ostream &stream, long)
42 {
43  return Vt_StreamOutGeneric(
44  typeid(T), static_cast<void const *>(&obj), stream);
45 }
46 
47 /// VtValue and VtArray make unqualified calls to VtStreamOut when writing
48 /// values to streams. Clients may overload VtStreamOut for their own types
49 /// if desired.
50 template <class T>
51 typename std::enable_if<!std::is_enum<T>::value, std::ostream &>::type
52 VtStreamOut(T const &obj, std::ostream &stream)
53 {
54  // For types that have an operator<< suitable for ostream, we use the
55  // traditional int/long 0-argument technique to disambiguate overloads.
56  return Vt_StreamOutImpl(obj, stream, 0);
57 }
58 template <class EnumT>
60 VtStreamOut(EnumT const &e, std::ostream &stream)
61 {
62  return VtStreamOut(TfEnum::GetName(e), stream);
63 }
64 VT_API std::ostream &VtStreamOut(bool const &, std::ostream &);
65 VT_API std::ostream &VtStreamOut(char const &, std::ostream &);
66 VT_API std::ostream &VtStreamOut(unsigned char const &, std::ostream &);
67 VT_API std::ostream &VtStreamOut(signed char const &, std::ostream &);
68 VT_API std::ostream &VtStreamOut(float const &, std::ostream &);
69 VT_API std::ostream &VtStreamOut(double const &, std::ostream &);
70 
71 struct Vt_ShapeData;
72 
73 VT_API void VtStreamOutArray(std::ostream&, const Vt_ShapeData*,
74  TfFunctionRef<void(std::ostream&)>);
75 
76 #ifdef PXR_PYTHON_SUPPORT_ENABLED
77 VT_API std::ostream &VtStreamOut(class TfPyObjWrapper const &, std::ostream &);
78 #endif // PXR_PYTHON_SUPPORT_ENABLED
79 
81 
82 #endif // PXR_BASE_VT_STREAM_OUT_H
GLuint GLuint stream
Definition: glcorearb.h:1832
GLsizei const GLfloat * value
Definition: glcorearb.h:824
#define VT_API
Definition: api.h:23
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
std::enable_if<!std::is_enum< T >::value, std::ostream & >::type VtStreamOut(T const &obj, std::ostream &stream)
Definition: streamOut.h:52
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:74
VT_API void VtStreamOutArray(std::ostream &, const Vt_ShapeData *, TfFunctionRef< void(std::ostream &)>)
static TF_API std::string GetName(TfEnum val)
auto Vt_StreamOutImpl(T const &obj, std::ostream &stream, int) -> decltype(stream<< obj)
Definition: streamOut.h:32