Coverage Report

Created: 2025-07-23 06:21

/src/alembic/lib/Alembic/Abc/OArchive.h
Line
Count
Source (jump to first uncovered line)
1
//-*****************************************************************************
2
//
3
// Copyright (c) 2009-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 Sony Pictures Imageworks, nor
19
// Industrial Light & Magic nor the names of their contributors may be used
20
// to endorse or promote products derived from this software without specific
21
// prior written permission.
22
//
23
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
//-*****************************************************************************
36
37
#ifndef Alembic_Abc_OArchive_h
38
#define Alembic_Abc_OArchive_h
39
40
#include <Alembic/Util/Export.h>
41
#include <Alembic/Abc/Foundation.h>
42
#include <Alembic/Abc/Base.h>
43
#include <Alembic/Abc/Argument.h>
44
45
namespace Alembic {
46
namespace Abc {
47
namespace ALEMBIC_VERSION_NS {
48
49
class OObject;
50
51
//-*****************************************************************************
52
class ALEMBIC_EXPORT OArchive : public Base
53
{
54
public:
55
    //! By convention, we always define "this_type" in every Abc
56
    //! class. This convention is relied upon by the unspecified-bool-type
57
    //! conversion.
58
    typedef OArchive this_type;
59
60
    //-*************************************************************************
61
    // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
62
    //-*************************************************************************
63
64
    //! The default constructor creates an empty OArchive function set.
65
    //! ...
66
0
    OArchive() {}
67
68
    //! The explicit constructor creates an archive with the given
69
    //! file name. Additional arguments that may be passed are the
70
    //! error handling policy and meta data.
71
    template <class ARCHIVE_CTOR>
72
    OArchive(
73
        //! We need to pass in a constructor which provides
74
        //! an explicit link to the concrete implementation of
75
        //! AbcCoreAbstract that we're using.
76
        ARCHIVE_CTOR iCtor,
77
78
        //! File name
79
        const std::string &iFileName,
80
81
        //! Optionally could be the error handling policy, or the meta data.
82
        const Argument &iArg0 = Argument(),
83
84
        //! Optionally could be the error handling policy, or the meta data.
85
        const Argument &iArg1 = Argument() );
86
87
    //! This attaches an OArchive wrapper around an existing
88
    //! ArchiveWriterPtr, with an optional error handling policy.
89
    OArchive(
90
91
        //! The pointer
92
        //! ...
93
        AbcA::ArchiveWriterPtr iPtr,
94
95
        //! Optional error handling policy
96
        //! ...
97
        ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy )
98
      : m_archive( iPtr )
99
0
    {
100
0
        // Set the error handling policy.
101
0
        getErrorHandler().setPolicy( iPolicy );
102
0
    }
103
104
    // Deprecated in favor of the constructor above
105
    OArchive(
106
        AbcA::ArchiveWriterPtr iPtr,
107
        WrapExistingFlag /* iWrap */,
108
        ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy )
109
      : m_archive( iPtr )
110
0
    {
111
0
        // Set the error handling policy.
112
0
        getErrorHandler().setPolicy( iPolicy );
113
0
    }
114
115
    //! Destructor
116
    //! ...
117
    ~OArchive();
118
119
    //! Default copy constructor
120
    //! Default assignment operator
121
122
    //-*************************************************************************
123
    // ARCHIVE WRITER FUNCTIONALITY
124
    //-*************************************************************************
125
126
    //! Returns the file name.
127
    //! It is an error to do so with an invalid object.
128
    std::string getName() const;
129
130
    //! This returns the single top-level OObject that exists
131
    //! automatically as part of the archive.
132
    OObject getTop();
133
134
    //! Get the compression applied to array properties.
135
    //! The value will be -1 for uncompressed, and 0-9 for weak through
136
    //! strong gzip compression.
137
    int8_t getCompressionHint() const;
138
139
    //! Set the compression applied to array properties.
140
    //! Value of -1 means uncompressed, and values of 0-9 indicate increasingly
141
    //! compressed data, at the expense of time.
142
    void setCompressionHint( int8_t iCh );
143
144
    //! Adds the TimeSampling to the Archive TimeSampling pool.
145
    //! If the TimeSampling already exists in the pool, the index for the match
146
    //! should be returned.
147
    //! index 0 is automatically reserved for uniform time sampling with a start
148
    //! time of 0 and time per cycle of 1 (aka identity sampling)
149
    uint32_t addTimeSampling( const AbcA::TimeSampling & iTs );
150
151
    //! Returns the TimeSampling at a given index.
152
    //! index 0 is automatically reserved for uniform time sampling with a start
153
    //! time of 0 and time per cycle of 1 (aka identity sampling)
154
    AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex );
155
156
    //! Returns the total number of TimeSamplingPtrs in the Archive
157
    //! TimeSampling pool.
158
    uint32_t getNumTimeSamplings();
159
160
    //-*************************************************************************
161
    // ABC BASE MECHANISMS
162
    // These functions are used by Abc to deal with errors, rewrapping,
163
    // and so on.
164
    //-*************************************************************************
165
166
    //! getPtr, as usual, returns a shared ptr to the
167
    //! underlying AbcCoreAbstract object, in this case the
168
    //! ArchiveWriterPtr.
169
0
    AbcA::ArchiveWriterPtr getPtr() { return m_archive; }
170
171
    //! Reset returns this function set to an empty, default
172
    //! state.
173
0
    void reset() { m_archive.reset(); Base::reset(); }
174
175
    //! Valid returns whether this function set is
176
    //! valid.
177
    bool valid() const
178
0
    {
179
0
        return ( Base::valid() && m_archive );
180
0
    }
181
182
    //! The unspecified-bool-type operator casts the object to "true"
183
    //! if it is valid, and "false" otherwise.
184
    ALEMBIC_OPERATOR_BOOL( valid() );
185
186
private:
187
    AbcA::ArchiveWriterPtr m_archive;
188
};
189
190
//-*****************************************************************************
191
inline AbcA::ArchiveWriterPtr GetArchiveWriterPtr( OArchive &iArch )
192
0
{
193
0
    return iArch.getPtr();
194
0
}
195
196
//-*****************************************************************************
197
//-*****************************************************************************
198
template <class ARCHIVE_CTOR>
199
OArchive::OArchive( ARCHIVE_CTOR iCtor,
200
                    const std::string &iFileName,
201
                    const Argument &iArg0,
202
                    const Argument &iArg1 )
203
{
204
    // Create arguments
205
    Arguments args( ErrorHandler::kThrowPolicy );
206
    iArg0.setInto( args );
207
    iArg1.setInto( args );
208
209
    // Set the error handling policy.
210
    getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
211
212
    ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArchive::OArchive( iFileName )" );
213
214
    m_archive = iCtor( iFileName, args.getMetaData() );
215
216
    ALEMBIC_ABC_SAFE_CALL_END_RESET();
217
}
218
219
} // End namespace ALEMBIC_VERSION_NS
220
221
using namespace ALEMBIC_VERSION_NS;
222
223
} // End namespace Abc
224
} // End namespace Alembic
225
226
#endif