-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathstreamOut.cpp
More file actions
133 lines (113 loc) · 3.17 KB
/
streamOut.cpp
File metadata and controls
133 lines (113 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Copyright 2016 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#include "pxr/pxr.h"
#include "pxr/base/arch/demangle.h"
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/tf/stringUtils.h"
#include "pxr/base/vt/streamOut.h"
#include "pxr/base/vt/types.h"
#ifdef PXR_PYTHON_SUPPORT_ENABLED
#include "pxr/base/tf/pyObjWrapper.h"
#include "pxr/base/tf/pyUtils.h"
#endif // PXR_PYTHON_SUPPORT_ENABLED
#include <ostream>
#include <numeric>
PXR_NAMESPACE_OPEN_SCOPE
std::ostream &
Vt_StreamOutGeneric(std::type_info const &type,
void const *addr,
std::ostream &stream)
{
return stream <<
TfStringPrintf("<'%s' @ %p>", ArchGetDemangled(type).c_str(), addr);
}
std::ostream &
VtStreamOut(bool const &val, std::ostream &stream)
{
return stream << static_cast<int>(val);
}
std::ostream &
VtStreamOut(char const &val, std::ostream &stream)
{
return stream << static_cast<int>(val);
}
std::ostream &
VtStreamOut(unsigned char const &val, std::ostream &stream)
{
return stream << static_cast<unsigned int>(val);
}
std::ostream &
VtStreamOut(signed char const &val, std::ostream &stream)
{
return stream << static_cast<int>(val);
}
std::ostream &
VtStreamOut(float const &val, std::ostream &stream)
{
return stream << TfStreamFloat(val);
}
std::ostream &
VtStreamOut(double const &val, std::ostream &stream)
{
return stream << TfStreamDouble(val);
}
namespace {
void
_StreamArrayRecursive(
std::ostream& out,
const Vt_ShapeData &shape,
TfFunctionRef<void(std::ostream&)> streamNextElem,
size_t lastDimSize,
size_t dimension)
{
out << '[';
if (dimension == shape.GetRank() - 1) {
for (size_t j = 0; j < lastDimSize; ++j) {
if (j) { out << ", "; }
streamNextElem(out);
}
}
else {
TF_AXIOM(dimension < Vt_ShapeData::NumOtherDims);
for (size_t j = 0; j < shape.otherDims[dimension]; ++j) {
if (j) { out << ", "; }
_StreamArrayRecursive(
out, shape, streamNextElem, lastDimSize, dimension + 1);
}
}
out << ']';
}
}
void
VtStreamOutArray(
std::ostream& out,
const Vt_ShapeData* shapeData,
TfFunctionRef<void(std::ostream&)> streamNextElem)
{
// Compute last dim size, and if size is not evenly divisible, output as
// rank-1.
size_t divisor = std::accumulate(
shapeData->otherDims, shapeData->otherDims + shapeData->GetRank()-1,
1, [](size_t x, size_t y) { return x * y; });
size_t lastDimSize = divisor ? shapeData->totalSize / divisor : 0;
size_t remainder = divisor ? shapeData->totalSize % divisor : 0;
// If there's a remainder, make a rank-1 shapeData.
Vt_ShapeData rank1;
if (remainder) {
rank1.totalSize = shapeData->totalSize;
shapeData = &rank1;
}
_StreamArrayRecursive(out, *shapeData, streamNextElem, lastDimSize, 0);
}
#ifdef PXR_PYTHON_SUPPORT_ENABLED
std::ostream &
VtStreamOut(TfPyObjWrapper const &obj, std::ostream &stream)
{
return stream << TfPyObjectRepr(obj.Get());
}
#endif // PXR_PYTHON_SUPPORT_ENABLED
PXR_NAMESPACE_CLOSE_SCOPE