00001 //-***************************************************************************** 00002 // 00003 // Copyright (c) 2009-2011, 00004 // Sony Pictures Imageworks, Inc. and 00005 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd. 00006 // 00007 // All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // * Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // * Redistributions in binary form must reproduce the above 00015 // copyright notice, this list of conditions and the following disclaimer 00016 // in the documentation and/or other materials provided with the 00017 // distribution. 00018 // * Neither the name of Sony Pictures Imageworks, nor 00019 // Industrial Light & Magic nor the names of their contributors may be used 00020 // to endorse or promote products derived from this software without specific 00021 // prior written permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 // 00035 //-***************************************************************************** 00036 00037 #ifndef _Alembic_Abc_IArchive_h_ 00038 #define _Alembic_Abc_IArchive_h_ 00039 00040 #include <Alembic/Abc/Foundation.h> 00041 #include <Alembic/Abc/Base.h> 00042 #include <Alembic/Abc/Argument.h> 00043 00044 namespace Alembic { 00045 namespace Abc { 00046 namespace ALEMBIC_VERSION_NS { 00047 00048 class IObject; 00049 00050 //-***************************************************************************** 00051 class IArchive : public Base 00052 { 00053 public: 00054 //! By convention, we always define "this_type" in every Abc 00055 //! class. This convention is relied upon by the unspecified-bool-type 00056 //! cast 00057 typedef IArchive this_type; 00058 00059 //-************************************************************************* 00060 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT 00061 //-************************************************************************* 00062 00063 //! The default constructor creates an empty IArchive function set. 00064 //! ... 00065 IArchive() {} 00066 00067 //! The explicit constructor opens an existing archive with the 00068 //! given file name. Additional arguments that may be passed are the 00069 //! error handler policy and a pointer to a cache instance. By 00070 //! default, an archive-local cache will be created. 00071 template <class ARCHIVE_CTOR> 00072 IArchive( 00073 //! We need to pass in a constructor which provides 00074 //! an explicit link to the concrete implementation of 00075 //! AbcCoreAbstract that we're using. 00076 ARCHIVE_CTOR iCtor, 00077 00078 //! The file name. 00079 const std::string &iFileName, 00080 00081 ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy, 00082 AbcA::ReadArraySampleCachePtr iCachePtr = AbcA::ReadArraySampleCachePtr()); 00083 00084 //! This attaches an IArchive wrapper around an existing 00085 //! ArchiveReaderPtr, with an optional error handling policy. 00086 IArchive( 00087 00088 //! The pointer 00089 //! ... 00090 AbcA::ArchiveReaderPtr iPtr, 00091 00092 //! Wrap existing 00093 //! ... 00094 WrapExistingFlag iWrap, 00095 00096 //! Optional error handling policy 00097 //! ... 00098 ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy ) 00099 : m_archive( iPtr ) 00100 { 00101 // Set the error handling policy. 00102 getErrorHandler().setPolicy( iPolicy ); 00103 } 00104 00105 //! Destructor 00106 //! ... 00107 ~IArchive(); 00108 00109 //! Default copy constructor 00110 //! Default assignment operator 00111 00112 //-************************************************************************* 00113 // ARCHIVE WRITER FUNCTIONALITY 00114 //-************************************************************************* 00115 00116 //! Returns the file name. 00117 //! It is an error to do so with an invalid object. 00118 std::string getName() const; 00119 00120 //! This returns the single top-level IObject that exists 00121 //! automatically as part of the archive. 00122 IObject getTop(); 00123 00124 //! Get the read array sample cache. It may be a NULL pointer. 00125 //! Caches can be shared amongst separate archives, and caching 00126 //! will is disabled if a NULL cache is returned here. 00127 AbcA::ReadArraySampleCachePtr getReadArraySampleCachePtr(); 00128 00129 //! Set the read array sample cache. It may also be a NULL pointer. 00130 //! Caches can be shared amongst separate archives, and caching 00131 //! will be disabled if a NULL cache is passed here. 00132 void setReadArraySampleCachePtr( AbcA::ReadArraySampleCachePtr iPtr ); 00133 00134 //-************************************************************************* 00135 // ABC BASE MECHANISMS 00136 // These functions are used by Abc to deal with errors, rewrapping, 00137 // and so on. 00138 //-************************************************************************* 00139 00140 //! getPtr, as usual, returns a shared ptr to the 00141 //! underlying AbcCoreAbstract object, in this case the 00142 //! ArchiveReaderPtr. 00143 AbcA::ArchiveReaderPtr getPtr() { return m_archive; } 00144 00145 //! Reset returns this function et to an empty, default 00146 //! state. 00147 void reset() { m_archive.reset(); Base::reset(); } 00148 00149 //! Returns the TimeSampling at a given index. 00150 AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex ); 00151 00152 //! Returns the total number of TimeSamplingPtrs in the Archive 00153 //! TimeSampling pool. 00154 uint32_t getNumTimeSamplings(); 00155 00156 //! Valid returns whether this function set is 00157 //! valid. 00158 bool valid() const 00159 { 00160 return ( Base::valid() && m_archive ); 00161 } 00162 00163 //! Returns the Alembic library numeric version (see Foundation.h) 00164 //! of this archive file. 00165 int32_t getArchiveVersion(); 00166 00167 //! The unspecified-bool-type operator casts the object to "true" 00168 //! if it is valid, and "false" otherwise. 00169 ALEMBIC_OPERATOR_BOOL( valid() ); 00170 00171 private: 00172 AbcA::ArchiveReaderPtr m_archive; 00173 }; 00174 00175 //-***************************************************************************** 00176 //! This function is used by the intrusive templated constructors 00177 //! for IObjects. 00178 inline AbcA::ArchiveReaderPtr 00179 GetArchiveReaderPtr( IArchive& iPrp ) { return iPrp.getPtr(); } 00180 00181 //-***************************************************************************** 00182 //-***************************************************************************** 00183 template <class ARCHIVE_CTOR> 00184 IArchive::IArchive( ARCHIVE_CTOR iCtor, 00185 const std::string &iFileName, 00186 ErrorHandler::Policy iPolicy, 00187 AbcA::ReadArraySampleCachePtr iCachePtr ) 00188 { 00189 // Set the error handling policy. 00190 getErrorHandler().setPolicy( iPolicy ); 00191 00192 ALEMBIC_ABC_SAFE_CALL_BEGIN( "IArchive::IArchive( iFileName )" ); 00193 00194 m_archive = iCtor( iFileName, iCachePtr ); 00195 00196 ALEMBIC_ABC_SAFE_CALL_END_RESET(); 00197 00198 } 00199 00200 } // End namespace ALEMBIC_VERSION_NS 00201 00202 using namespace ALEMBIC_VERSION_NS; 00203 00204 } // End namespace Abc 00205 } // End namespace Alembic 00206 00207 00208 00209 #endif
1.5.9