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"
31 
32 #include <iosfwd>
33 #include <typeinfo>
34 #include <type_traits>
35 
37 
38 // Helper that's used to stream a generic string for a type that isn't
39 // streamable and doesn't provide VtStreamOut. Inserts a message like
40 // <'typeName' @ 0xXXXXXXXX>.
41 VT_API std::ostream &
42 Vt_StreamOutGeneric(std::type_info const &type,
43  void const *addr,
44  std::ostream &stream);
45 
46 // Function used in the case that T has a stream insertion operator.
47 template <class T>
48 inline auto
49 Vt_StreamOutImpl(T const &obj, std::ostream &stream, int)
50  -> decltype(stream << obj)
51 {
52  return stream << obj;
53 }
54 
55 // Function used in the case that T does not have a stream insertion operator.
56 template <class T>
57 inline std::ostream &
58 Vt_StreamOutImpl(T const &obj, std::ostream &stream, long)
59 {
60  return Vt_StreamOutGeneric(
61  typeid(T), static_cast<void const *>(&obj), stream);
62 }
63 
64 /// VtValue and VtArray make unqualified calls to VtStreamOut when writing
65 /// values to streams. Clients may overload VtStreamOut for their own types
66 /// if desired.
67 template <class T>
68 typename std::enable_if<!std::is_enum<T>::value, std::ostream &>::type
69 VtStreamOut(T const &obj, std::ostream &stream)
70 {
71  // For types that have an operator<< suitable for ostream, we use the
72  // traditional int/long 0-argument technique to disambiguate overloads.
73  return Vt_StreamOutImpl(obj, stream, 0);
74 }
75 template <class EnumT>
77 VtStreamOut(EnumT const &e, std::ostream &stream)
78 {
79  return VtStreamOut(TfEnum::GetName(e), stream);
80 }
81 VT_API std::ostream &VtStreamOut(bool const &, std::ostream &);
82 VT_API std::ostream &VtStreamOut(char const &, std::ostream &);
83 VT_API std::ostream &VtStreamOut(unsigned char const &, std::ostream &);
84 VT_API std::ostream &VtStreamOut(signed char const &, std::ostream &);
85 VT_API std::ostream &VtStreamOut(float const &, std::ostream &);
86 VT_API std::ostream &VtStreamOut(double const &, std::ostream &);
87 
88 struct Vt_ShapeData;
89 
90 VT_API void VtStreamOutArray(std::ostream&, const Vt_ShapeData*,
91  TfFunctionRef<void(std::ostream&)>);
92 
93 #ifdef PXR_PYTHON_SUPPORT_ENABLED
94 VT_API std::ostream &VtStreamOut(class TfPyObjWrapper const &, std::ostream &);
95 #endif // PXR_PYTHON_SUPPORT_ENABLED
96 
98 
99 #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:40
std::enable_if<!std::is_enum< T >::value, std::ostream & >::type VtStreamOut(T const &obj, std::ostream &stream)
Definition: streamOut.h:69
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
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
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:49
type
Definition: core.h:1059