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_OArchive_h_ 00038 #define _Alembic_Abc_OArchive_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 OObject; 00049 00050 //-***************************************************************************** 00051 class OArchive : 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 //! conversion. 00057 typedef OArchive this_type; 00058 00059 //-************************************************************************* 00060 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT 00061 //-************************************************************************* 00062 00063 //! The default constructor creates an empty OArchive function set. 00064 //! ... 00065 OArchive() {} 00066 00067 //! The explicit constructor creates an archive with the given 00068 //! file name. Additional arguments that may be passed are the 00069 //! error handling policy and meta data. 00070 template <class ARCHIVE_CTOR> 00071 OArchive( 00072 //! We need to pass in a constructor which provides 00073 //! an explicit link to the concrete implementation of 00074 //! AbcCoreAbstract that we're using. 00075 ARCHIVE_CTOR iCtor, 00076 00077 //! File name 00078 const std::string &iFileName, 00079 00080 //! Optionally could be the error handling policy, or the meta data. 00081 const Argument &iArg0 = Argument(), 00082 00083 //! Optionally could be the error handling policy, or the meta data. 00084 const Argument &iArg1 = Argument() ); 00085 00086 //! This attaches an OArchive wrapper around an existing 00087 //! ArchiveWriterPtr, with an optional error handling policy. 00088 OArchive( 00089 00090 //! The pointer 00091 //! ... 00092 AbcA::ArchiveWriterPtr iPtr, 00093 00094 //! Wrap existing. Here cosmetically, for consistency. 00095 //! ... 00096 WrapExistingFlag iWrap, 00097 00098 //! Optional error handling policy 00099 //! ... 00100 ErrorHandler::Policy iPolicy = ErrorHandler::kThrowPolicy ) 00101 : m_archive( iPtr ) 00102 { 00103 // Set the error handling policy. 00104 getErrorHandler().setPolicy( iPolicy ); 00105 } 00106 00107 //! Destructor 00108 //! ... 00109 ~OArchive(); 00110 00111 //! Default copy constructor 00112 //! Default assignment operator 00113 00114 //-************************************************************************* 00115 // ARCHIVE WRITER FUNCTIONALITY 00116 //-************************************************************************* 00117 00118 //! Returns the file name. 00119 //! It is an error to do so with an invalid object. 00120 std::string getName() const; 00121 00122 //! This returns the single top-level OObject that exists 00123 //! automatically as part of the archive. 00124 OObject getTop(); 00125 00126 //! Get the compression applied to array properties. 00127 //! The value will be -1 for uncompressed, and 0-9 for weak through 00128 //! strong gzip compression. 00129 int8_t getCompressionHint() const; 00130 00131 //! Set the compression applied to array properties. 00132 //! Value of -1 means uncompressed, and values of 0-9 indicate increasingly 00133 //! compressed data, at the expense of time. 00134 void setCompressionHint( int8_t iCh ); 00135 00136 //! Adds the TimeSampling to the Archive TimeSampling pool. 00137 //! If the TimeSampling already exists in the pool, the index for the match 00138 //! should be returned. 00139 //! index 0 is automatically reserved for uniform time sampling with a start 00140 //! time of 0 and time per cycle of 1 (aka identity sampling) 00141 uint32_t addTimeSampling( const AbcA::TimeSampling & iTs ); 00142 00143 //! Returns the TimeSampling at a given index. 00144 //! index 0 is automatically reserved for uniform time sampling with a start 00145 //! time of 0 and time per cycle of 1 (aka identity sampling) 00146 AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex ); 00147 00148 //! Returns the total number of TimeSamplingPtrs in the Archive 00149 //! TimeSampling pool. 00150 uint32_t getNumTimeSamplings(); 00151 00152 //-************************************************************************* 00153 // ABC BASE MECHANISMS 00154 // These functions are used by Abc to deal with errors, rewrapping, 00155 // and so on. 00156 //-************************************************************************* 00157 00158 //! getPtr, as usual, returns a shared ptr to the 00159 //! underlying AbcCoreAbstract object, in this case the 00160 //! ArchiveWriterPtr. 00161 AbcA::ArchiveWriterPtr getPtr() { return m_archive; } 00162 00163 //! Reset returns this function set to an empty, default 00164 //! state. 00165 void reset() { m_archive.reset(); Base::reset(); } 00166 00167 //! Valid returns whether this function set is 00168 //! valid. 00169 bool valid() const 00170 { 00171 return ( Base::valid() && m_archive ); 00172 } 00173 00174 //! The unspecified-bool-type operator casts the object to "true" 00175 //! if it is valid, and "false" otherwise. 00176 ALEMBIC_OPERATOR_BOOL( valid() ); 00177 00178 private: 00179 AbcA::ArchiveWriterPtr m_archive; 00180 }; 00181 00182 //-***************************************************************************** 00183 inline AbcA::ArchiveWriterPtr GetArchiveWriterPtr( OArchive &iArch ) 00184 { 00185 return iArch.getPtr(); 00186 } 00187 00188 //-***************************************************************************** 00189 //-***************************************************************************** 00190 template <class ARCHIVE_CTOR> 00191 OArchive::OArchive( ARCHIVE_CTOR iCtor, 00192 const std::string &iFileName, 00193 const Argument &iArg0, 00194 const Argument &iArg1 ) 00195 { 00196 // Create arguments 00197 Arguments args( ErrorHandler::kThrowPolicy ); 00198 iArg0.setInto( args ); 00199 iArg1.setInto( args ); 00200 00201 // Set the error handling policy. 00202 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() ); 00203 00204 ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArchive::OArchive( iFileName )" ); 00205 00206 m_archive = iCtor( iFileName, args.getMetaData() ); 00207 00208 ALEMBIC_ABC_SAFE_CALL_END_RESET(); 00209 } 00210 00211 } // End namespace ALEMBIC_VERSION_NS 00212 00213 using namespace ALEMBIC_VERSION_NS; 00214 00215 } // End namespace Abc 00216 } // End namespace Alembic 00217 00218 #endif
1.5.9