/src/alembic/lib/Alembic/Abc/IArchive.h
Line | Count | Source |
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_IArchive_h |
38 | | #define Alembic_Abc_IArchive_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 IObject; |
50 | | |
51 | | //-***************************************************************************** |
52 | | class ALEMBIC_EXPORT IArchive : 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 | | //! cast |
58 | | typedef IArchive this_type; |
59 | | |
60 | | //-************************************************************************* |
61 | | // CONSTRUCTION, DESTRUCTION, ASSIGNMENT |
62 | | //-************************************************************************* |
63 | | |
64 | | //! The default constructor creates an empty IArchive function set. |
65 | | //! ... |
66 | 161 | IArchive() {} |
67 | | |
68 | | //! The explicit constructor opens an existing archive with the |
69 | | //! given file name. Additional arguments that may be passed are the |
70 | | //! error handler policy and a pointer to a cache instance. By |
71 | | //! default, an archive-local cache will be created. |
72 | | template <class ARCHIVE_CTOR> |
73 | | IArchive( |
74 | | //! We need to pass in a constructor which provides |
75 | | //! an explicit link to the concrete implementation of |
76 | | //! AbcCoreAbstract that we're using. |
77 | | ARCHIVE_CTOR iCtor, |
78 | | |
79 | | //! The file name. |
80 | | const std::string &iFileName, |
81 | | |
82 | | ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy, |
83 | | AbcA::ReadArraySampleCachePtr iCachePtr = AbcA::ReadArraySampleCachePtr()); |
84 | | |
85 | | //! This attaches an IArchive wrapper around an existing |
86 | | //! ArchiveReaderPtr, with an optional error handling policy. |
87 | | IArchive( |
88 | | |
89 | | //! The pointer |
90 | | //! ... |
91 | | AbcA::ArchiveReaderPtr iPtr, |
92 | | |
93 | | //! Optional error handling policy |
94 | | //! ... |
95 | | ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy ) |
96 | 0 | : m_archive( iPtr ) |
97 | 0 | { |
98 | | // Set the error handling policy. |
99 | 0 | getErrorHandler().setPolicy( iPolicy ); |
100 | 0 | } |
101 | | |
102 | | // Deprecated in favor of the constructor above |
103 | | IArchive( |
104 | | AbcA::ArchiveReaderPtr iPtr, |
105 | | WrapExistingFlag /* iWrap */, |
106 | | ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy ) |
107 | | : m_archive( iPtr ) |
108 | 0 | { |
109 | 0 | // Set the error handling policy. |
110 | 0 | getErrorHandler().setPolicy( iPolicy ); |
111 | 0 | } |
112 | | |
113 | | //! Destructor |
114 | | //! ... |
115 | | ~IArchive(); |
116 | | |
117 | | //! Default copy constructor |
118 | | //! Default assignment operator |
119 | | |
120 | | //-************************************************************************* |
121 | | // ARCHIVE WRITER FUNCTIONALITY |
122 | | //-************************************************************************* |
123 | | |
124 | | //! Returns the file name. |
125 | | //! It is an error to do so with an invalid object. |
126 | | std::string getName() const; |
127 | | |
128 | | //! This returns the single top-level IObject that exists |
129 | | //! automatically as part of the archive. |
130 | | IObject getTop() const; |
131 | | |
132 | | //! Get the read array sample cache. It may be a NULL pointer. |
133 | | //! Caches can be shared amongst separate archives, and caching |
134 | | //! will be disabled if a NULL cache is returned here. |
135 | | AbcA::ReadArraySampleCachePtr getReadArraySampleCachePtr(); |
136 | | |
137 | | //! Set the read array sample cache. It may also be a NULL pointer. |
138 | | //! Caches can be shared amongst separate archives, and caching |
139 | | //! will be disabled if a NULL cache is passed here. |
140 | | void setReadArraySampleCachePtr( AbcA::ReadArraySampleCachePtr iPtr ); |
141 | | |
142 | | //-************************************************************************* |
143 | | // ABC BASE MECHANISMS |
144 | | // These functions are used by Abc to deal with errors, rewrapping, |
145 | | // and so on. |
146 | | //-************************************************************************* |
147 | | |
148 | | //! getPtr, as usual, returns a shared ptr to the |
149 | | //! underlying AbcCoreAbstract object, in this case the |
150 | | //! ArchiveReaderPtr. |
151 | 0 | AbcA::ArchiveReaderPtr getPtr() { return m_archive; } |
152 | | |
153 | | //! Reset returns this function et to an empty, default |
154 | | //! state. |
155 | 161 | void reset() { m_archive.reset(); Base::reset(); } |
156 | | |
157 | | //! Returns the TimeSampling at a given index. |
158 | | AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex ); |
159 | | |
160 | | //! Returns the total number of TimeSamplingPtrs in the Archive |
161 | | //! TimeSampling pool. |
162 | | uint32_t getNumTimeSamplings(); |
163 | | |
164 | | //! Returns the maximum number of samples written for the TimeSampling at |
165 | | //! the given index. If an illegal iIndex is specified, or a max |
166 | | //! number of samplings couldn't be found for that iIndex |
167 | | //! (for older archives pre 1.1.3) INDEX_UNKNOWN will be returned. |
168 | | index_t getMaxNumSamplesForTimeSamplingIndex( uint32_t iIndex ); |
169 | | |
170 | | //! Valid returns whether this function set is |
171 | | //! valid. |
172 | | bool valid() const |
173 | 438 | { |
174 | 438 | return ( Base::valid() && m_archive ); |
175 | 438 | } |
176 | | |
177 | | //! Returns the Alembic library numeric version (see Foundation.h) |
178 | | //! of this archive file. |
179 | | int32_t getArchiveVersion(); |
180 | | |
181 | | //! The unspecified-bool-type operator casts the object to "true" |
182 | | //! if it is valid, and "false" otherwise. |
183 | | ALEMBIC_OPERATOR_BOOL( valid() ); |
184 | | |
185 | | private: |
186 | | AbcA::ArchiveReaderPtr m_archive; |
187 | | }; |
188 | | |
189 | | //-***************************************************************************** |
190 | | //! This function is used by the intrusive templated constructors |
191 | | //! for IObjects. |
192 | | inline AbcA::ArchiveReaderPtr |
193 | 0 | GetArchiveReaderPtr( IArchive& iPrp ) { return iPrp.getPtr(); } |
194 | | |
195 | | //-***************************************************************************** |
196 | | //-***************************************************************************** |
197 | | template <class ARCHIVE_CTOR> |
198 | | IArchive::IArchive( ARCHIVE_CTOR iCtor, |
199 | | const std::string &iFileName, |
200 | | ErrorHandler::Policy iPolicy, |
201 | | AbcA::ReadArraySampleCachePtr iCachePtr ) |
202 | 219 | { |
203 | | // Set the error handling policy. |
204 | 219 | getErrorHandler().setPolicy( iPolicy ); |
205 | | |
206 | 438 | ALEMBIC_ABC_SAFE_CALL_BEGIN( "IArchive::IArchive( iFileName )" ); |
207 | | |
208 | 438 | m_archive = iCtor( iFileName, iCachePtr ); |
209 | | |
210 | 438 | ALEMBIC_ABC_SAFE_CALL_END_RESET(); |
211 | | |
212 | 219 | } |
213 | | |
214 | | } // End namespace ALEMBIC_VERSION_NS |
215 | | |
216 | | using namespace ALEMBIC_VERSION_NS; |
217 | | |
218 | | } // End namespace Abc |
219 | | } // End namespace Alembic |
220 | | |
221 | | |
222 | | |
223 | | #endif |