All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
streamOut.h
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"
13#include "pxr/base/tf/functionRef.h"
14
15#include <iosfwd>
16#include <typeinfo>
17#include <type_traits>
18
19PXR_NAMESPACE_OPEN_SCOPE
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>.
24VT_API std::ostream &
25Vt_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.
30template <class T>
31inline auto
32Vt_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.
39template <class T>
40inline std::ostream &
41Vt_StreamOutImpl(T const &obj, std::ostream &stream, long)
42{
43 return Vt_StreamOutGeneric(
44 typeid(T), static_cast<void const *>(&obj), stream);
45}
46
50template <class T>
51typename std::enable_if<!std::is_enum<T>::value, std::ostream &>::type
52VtStreamOut(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}
58template <class EnumT>
59typename std::enable_if<std::is_enum<EnumT>::value, std::ostream &>::type
60VtStreamOut(EnumT const &e, std::ostream &stream)
61{
62 return VtStreamOut(TfEnum::GetName(e), stream);
63}
64VT_API std::ostream &VtStreamOut(bool const &, std::ostream &);
65VT_API std::ostream &VtStreamOut(char const &, std::ostream &);
66VT_API std::ostream &VtStreamOut(unsigned char const &, std::ostream &);
67VT_API std::ostream &VtStreamOut(signed char const &, std::ostream &);
68VT_API std::ostream &VtStreamOut(float const &, std::ostream &);
69VT_API std::ostream &VtStreamOut(double const &, std::ostream &);
70
71struct Vt_ShapeData;
72
73VT_API void VtStreamOutArray(std::ostream&, const Vt_ShapeData*,
74 TfFunctionRef<void(std::ostream&)>);
75
76#ifdef PXR_PYTHON_SUPPORT_ENABLED
77VT_API std::ostream &VtStreamOut(class TfPyObjWrapper const &, std::ostream &);
78#endif // PXR_PYTHON_SUPPORT_ENABLED
79
80PXR_NAMESPACE_CLOSE_SCOPE
81
82#endif // PXR_BASE_VT_STREAM_OUT_H
static TF_API std::string GetName(TfEnum val)
Returns the name associated with an enumerated value.
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
Definition: functionRef.h:19
Boost Python object wrapper.
Definition: pyObjWrapper.h:79