HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IArchive.h
Go to the documentation of this file.
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 //-*****************************************************************************
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
59 
60  //-*************************************************************************
61  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
62  //-*************************************************************************
63 
64  //! The default constructor creates an empty IArchive function set.
65  //! ...
66  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 
84 
85  //! This attaches an IArchive wrapper around an existing
86  //! ArchiveReaderPtr, with an optional error handling policy.
88 
89  //! The pointer
90  //! ...
92 
93  //! Optional error handling policy
94  //! ...
96  : m_archive( iPtr )
97  {
98  // Set the error handling policy.
99  getErrorHandler().setPolicy( iPolicy );
100  }
101 
102  // Deprecated in favor of the constructor above
105  WrapExistingFlag /* iWrap */,
107  : m_archive( iPtr )
108  {
109  // Set the error handling policy.
110  getErrorHandler().setPolicy( iPolicy );
111  }
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  AbcA::ArchiveReaderPtr getPtr() { return m_archive; }
152 
153  //! Reset returns this function et to an empty, default
154  //! state.
155  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  {
174  return ( Base::valid() && m_archive );
175  }
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.
193 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,
202 {
203  // Set the error handling policy.
204  getErrorHandler().setPolicy( iPolicy );
205 
206  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IArchive::IArchive( iFileName )" );
207 
208  m_archive = iCtor( iFileName, iCachePtr );
209 
211 
212 }
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
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
IArchive(AbcA::ArchiveReaderPtr iPtr, ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy)
Definition: IArchive.h:87
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
IArchive(AbcA::ArchiveReaderPtr iPtr, WrapExistingFlag, ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy)
Definition: IArchive.h:103
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
AbcA::ArchiveReaderPtr GetArchiveReaderPtr(AbcA::ArchiveReaderPtr iPtr)
Definition: Foundation.h:219
AbcA::ArchiveReaderPtr getPtr()
Definition: IArchive.h:151
Alembic::Util::shared_ptr< ReadArraySampleCache > ReadArraySampleCachePtr
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
Alembic::Util::shared_ptr< ArchiveReader > ArchiveReaderPtr
Smart Ptrs to Readers.
GLsizei const GLchar *const * string
Definition: glew.h:1844
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105