Coverage Report

Created: 2026-06-30 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/alembic/lib/Alembic/Ogawa/IGroup.cpp
Line
Count
Source
1
//-*****************************************************************************
2
//
3
// Copyright (c) 2013,
4
//  Sony Pictures Imageworks Inc. and
5
//  Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6
//
7
// All rights reserved.
8
//
9
// Redistribution and use in source and binary forms, with or without
10
// modification, are permitted provided that the following conditions are
11
// met:
12
// *       Redistributions of source code must retain the above copyright
13
// notice, this list of conditions and the following disclaimer.
14
// *       Redistributions in binary form must reproduce the above
15
// copyright notice, this list of conditions and the following disclaimer
16
// in the documentation and/or other materials provided with the
17
// distribution.
18
// *       Neither the name of Industrial Light & Magic nor the names of
19
// its contributors may be used to endorse or promote products derived
20
// from this software without specific prior written permission.
21
//
22
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
//
34
//-*****************************************************************************
35
36
#include <Alembic/Ogawa/IGroup.h>
37
#include <Alembic/Ogawa/IArchive.h>
38
#include <Alembic/Ogawa/IStreams.h>
39
40
namespace Alembic {
41
namespace Ogawa {
42
namespace ALEMBIC_VERSION_NS {
43
44
class IGroup::PrivateData
45
{
46
public:
47
    PrivateData(IStreamsPtr iStreams)
48
403
    {
49
403
        numChildren = 0;
50
403
        pos = 0;
51
403
        streams = iStreams;
52
403
    }
53
54
403
    ~PrivateData() {}
55
56
    IStreamsPtr streams;
57
58
    std::vector<Alembic::Util::uint64_t> childVec;
59
60
    Alembic::Util::uint64_t numChildren;
61
    Alembic::Util::uint64_t pos;
62
};
63
64
IGroup::IGroup(IStreamsPtr iStreams,
65
               Alembic::Util::uint64_t iPos,
66
               bool iLight,
67
               std::size_t iThreadIndex) :
68
403
    mData(new IGroup::PrivateData(iStreams))
69
403
{
70
    // all done, we have no children, or our streams aren't good
71
403
    if (iPos == EMPTY_GROUP || !mData->streams || !mData->streams->isValid())
72
1
    {
73
1
        return;
74
1
    }
75
76
402
    mData->pos = iPos;
77
402
    mData->streams->read(iThreadIndex, iPos, 8, &mData->numChildren);
78
79
    // make sure we don't have a maliciously bad number of children
80
402
    if ( mData->numChildren > (mData->streams->getSize() / 8) ||
81
346
         mData->numChildren == 0 )
82
49
    {
83
49
        mData->numChildren = 0;
84
49
        return;
85
49
    }
86
87
    // 0 should NOT have been written, this groups should have been the
88
    // special EMPTY_GROUP instead
89
90
    // read all our child indices, unless we are light and have more than 8
91
    // children
92
353
    if (!iLight || mData->numChildren < 9)
93
338
    {
94
338
        mData->childVec.resize(mData->numChildren);
95
338
        mData->streams->read(iThreadIndex, iPos + 8, mData->numChildren * 8,
96
338
                             &(mData->childVec.front()));
97
338
    }
98
353
}
99
100
IGroup::~IGroup()
101
382
{
102
103
382
}
104
105
IGroupPtr IGroup::getGroup(Alembic::Util::uint64_t iIndex, bool iLight,
106
                           std::size_t iThreadIndex)
107
220
{
108
220
    IGroupPtr child;
109
110
220
    Alembic::Util::uint64_t childPos = EMPTY_DATA;
111
112
220
    if (isLight())
113
0
    {
114
0
        if (iIndex < mData->numChildren)
115
0
        {
116
0
            mData->streams->read(iThreadIndex, mData->pos + 8 * iIndex + 8, 8,
117
0
                                 &childPos);
118
0
        }
119
0
    }
120
220
    else if (isChildGroup(iIndex))
121
220
    {
122
220
        childPos = mData->childVec[iIndex];
123
220
    }
124
125
    // sanity check that we have a valid group, either an empty one
126
    // or a non data that has a decent value
127
220
    if (childPos == EMPTY_GROUP || ((childPos & EMPTY_DATA) == 0 &&
128
219
        childPos > 8 && childPos != mData->pos))
129
220
    {
130
220
        child.reset(new IGroup(mData->streams, childPos, iLight, iThreadIndex));
131
220
    }
132
133
220
    return child;
134
220
}
135
136
IDataPtr IGroup::getData(Alembic::Util::uint64_t iIndex,
137
                         std::size_t iThreadIndex)
138
884
{
139
884
    IDataPtr child;
140
884
    if (isLight())
141
0
    {
142
0
        if (iIndex < mData->numChildren)
143
0
        {
144
0
            Alembic::Util::uint64_t childPos = 0;
145
0
            mData->streams->read(iThreadIndex, mData->pos + 8 * iIndex + 8, 8,
146
0
                                 &childPos);
147
148
            // top bit should be set for data
149
0
            if ((childPos & EMPTY_DATA) != 0)
150
0
            {
151
0
                child.reset(new IData(mData->streams, childPos, iThreadIndex));
152
0
            }
153
0
        }
154
0
    }
155
884
    else if (isChildData(iIndex))
156
884
    {
157
884
        child.reset(new IData(mData->streams, mData->childVec[iIndex],
158
884
                              iThreadIndex));
159
884
    }
160
884
    return child;
161
884
}
162
163
Alembic::Util::uint64_t IGroup::getNumChildren() const
164
382
{
165
382
    return mData->numChildren;
166
382
}
167
168
bool IGroup::isChildGroup(Alembic::Util::uint64_t iIndex) const
169
460
{
170
460
    return (iIndex < mData->childVec.size() &&
171
460
            (mData->childVec[iIndex] & EMPTY_DATA) == 0);
172
460
}
173
174
bool IGroup::isChildData(Alembic::Util::uint64_t iIndex) const
175
1.94k
{
176
1.94k
    return (iIndex < mData->childVec.size() &&
177
1.94k
            (mData->childVec[iIndex] & EMPTY_DATA) != 0);
178
1.94k
}
179
180
bool IGroup::isEmptyChildGroup(Alembic::Util::uint64_t iIndex) const
181
0
{
182
0
    return (iIndex < mData->childVec.size() &&
183
0
            mData->childVec[iIndex] == EMPTY_GROUP);
184
0
}
185
186
bool IGroup::isEmptyChildData(Alembic::Util::uint64_t iIndex) const
187
0
{
188
0
    return (iIndex < mData->childVec.size() &&
189
0
        mData->childVec[iIndex] == EMPTY_DATA);
190
0
}
191
192
bool IGroup::isLight() const
193
1.10k
{
194
1.10k
    return mData->numChildren != 0 && mData->childVec.empty();
195
1.10k
}
196
197
} // End namespace ALEMBIC_VERSION_NS
198
} // End namespace Ogawa
199
} // End namespace Alembic