Loading...
Searching...
No Matches
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 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#include "pxr/base/tf/functionRef.h"
31
32#include <iosfwd>
33#include <typeinfo>
34#include <type_traits>
35
36PXR_NAMESPACE_OPEN_SCOPE
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>.
41VT_API std::ostream &
42Vt_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.
47template <class T>
48inline auto
49Vt_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.
56template <class T>
57inline std::ostream &
58Vt_StreamOutImpl(T const &obj, std::ostream &stream, long)
59{
60 return Vt_StreamOutGeneric(
61 typeid(T), static_cast<void const *>(&obj), stream);
62}
63
67template <class T>
68typename std::enable_if<!std::is_enum<T>::value, std::ostream &>::type
69VtStreamOut(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}
75template <class EnumT>
76typename std::enable_if<std::is_enum<EnumT>::value, std::ostream &>::type
77VtStreamOut(EnumT const &e, std::ostream &stream)
78{
79 return VtStreamOut(TfEnum::GetName(e), stream);
80}
81VT_API std::ostream &VtStreamOut(bool const &, std::ostream &);
82VT_API std::ostream &VtStreamOut(char const &, std::ostream &);
83VT_API std::ostream &VtStreamOut(unsigned char const &, std::ostream &);
84VT_API std::ostream &VtStreamOut(signed char const &, std::ostream &);
85VT_API std::ostream &VtStreamOut(float const &, std::ostream &);
86VT_API std::ostream &VtStreamOut(double const &, std::ostream &);
87
88struct Vt_ShapeData;
89
90VT_API void VtStreamOutArray(std::ostream&, const Vt_ShapeData*,
91 TfFunctionRef<void(std::ostream&)>);
92
93#ifdef PXR_PYTHON_SUPPORT_ENABLED
94VT_API std::ostream &VtStreamOut(class TfPyObjWrapper const &, std::ostream &);
95#endif // PXR_PYTHON_SUPPORT_ENABLED
96
97PXR_NAMESPACE_CLOSE_SCOPE
98
99#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:36
Boost Python object wrapper.
Definition: pyObjWrapper.h:97