All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
streamOut.h
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 VT_STREAMOUT_H
25 #define VT_STREAMOUT_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 
35 PXR_NAMESPACE_OPEN_SCOPE
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 
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>
75 typename std::enable_if<std::is_enum<EnumT>::value, std::ostream &>::type
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 
87 class VtStreamOutIterator {
88 public:
89  VT_API virtual ~VtStreamOutIterator();
90  virtual void Next(std::ostream&) = 0;
91 };
92 
93 struct Vt_ShapeData;
94 
95 VT_API void VtStreamOutArray(VtStreamOutIterator*, size_t size,
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 
102 PXR_NAMESPACE_CLOSE_SCOPE
103 
104 #endif // VT_STREAMOUT_H
static TF_API std::string GetName(TfEnum val)
Returns the name associated with an enumerated value.
Boost Python object wrapper.
Definition: pyObjWrapper.h:66