HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  //! Wrap existing
94  //! ...
95  WrapExistingFlag /* iWrap */,
96 
97  //! Optional error handling policy
98  //! ...
100  : m_archive( iPtr )
101  {
102  // Set the error handling policy.
103  getErrorHandler().setPolicy( iPolicy );
104  }
105 
106  //! Destructor
107  //! ...
108  ~IArchive();
109 
110  //! Default copy constructor
111  //! Default assignment operator
112 
113  //-*************************************************************************
114  // ARCHIVE WRITER FUNCTIONALITY
115  //-*************************************************************************
116 
117  //! Returns the file name.
118  //! It is an error to do so with an invalid object.
119  std::string getName() const;
120 
121  //! This returns the single top-level IObject that exists
122  //! automatically as part of the archive.
123  IObject getTop();
124 
125  //! Get the read array sample cache. It may be a NULL pointer.
126  //! Caches can be shared amongst separate archives, and caching
127  //! will is disabled if a NULL cache is returned here.
128  AbcA::ReadArraySampleCachePtr getReadArraySampleCachePtr();
129 
130  //! Set the read array sample cache. It may also be a NULL pointer.
131  //! Caches can be shared amongst separate archives, and caching
132  //! will be disabled if a NULL cache is passed here.
133  void setReadArraySampleCachePtr( AbcA::ReadArraySampleCachePtr iPtr );
134 
135  //-*************************************************************************
136  // ABC BASE MECHANISMS
137  // These functions are used by Abc to deal with errors, rewrapping,
138  // and so on.
139  //-*************************************************************************
140 
141  //! getPtr, as usual, returns a shared ptr to the
142  //! underlying AbcCoreAbstract object, in this case the
143  //! ArchiveReaderPtr.
144  AbcA::ArchiveReaderPtr getPtr() { return m_archive; }
145 
146  //! Reset returns this function et to an empty, default
147  //! state.
148  void reset() { m_archive.reset(); Base::reset(); }
149 
150  //! Returns the TimeSampling at a given index.
151  AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex );
152 
153  //! Returns the total number of TimeSamplingPtrs in the Archive
154  //! TimeSampling pool.
155  uint32_t getNumTimeSamplings();
156 
157  //! Returns the maximum number of samples written for the TimeSampling at
158  //! the given index. If an illegal iIndex is specified, or a max
159  //! number of samplings couldn't be found for that iIndex
160  //! (for older archives pre 1.1.3) INDEX_UNKNOWN will be returned.
161  index_t getMaxNumSamplesForTimeSamplingIndex( uint32_t iIndex );
162 
163  //! Valid returns whether this function set is
164  //! valid.
165  bool valid() const
166  {
167  return ( Base::valid() && m_archive );
168  }
169 
170  //! Returns the Alembic library numeric version (see Foundation.h)
171  //! of this archive file.
172  int32_t getArchiveVersion();
173 
174  //! The unspecified-bool-type operator casts the object to "true"
175  //! if it is valid, and "false" otherwise.
176  ALEMBIC_OPERATOR_BOOL( valid() );
177 
178 private:
179  AbcA::ArchiveReaderPtr m_archive;
180 };
181 
182 //-*****************************************************************************
183 //! This function is used by the intrusive templated constructors
184 //! for IObjects.
186 GetArchiveReaderPtr( IArchive& iPrp ) { return iPrp.getPtr(); }
187 
188 //-*****************************************************************************
189 //-*****************************************************************************
190 template <class ARCHIVE_CTOR>
191 IArchive::IArchive( ARCHIVE_CTOR iCtor,
192  const std::string &iFileName,
193  ErrorHandler::Policy iPolicy,
195 {
196  // Set the error handling policy.
197  getErrorHandler().setPolicy( iPolicy );
198 
199  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IArchive::IArchive( iFileName )" );
200 
201  m_archive = iCtor( iFileName, iCachePtr );
202 
204 
205 }
206 
207 } // End namespace ALEMBIC_VERSION_NS
208 
209 using namespace ALEMBIC_VERSION_NS;
210 
211 } // End namespace Abc
212 } // End namespace Alembic
213 
214 
215 
216 #endif
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
IArchive(AbcA::ArchiveReaderPtr iPtr, WrapExistingFlag, ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy)
Definition: IArchive.h:87
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
AbcA::ArchiveReaderPtr GetArchiveReaderPtr(AbcA::ArchiveReaderPtr iPtr)
Definition: Foundation.h:209
AbcA::ArchiveReaderPtr getPtr()
Definition: IArchive.h:144
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.
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104