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_OObject_h_ 00038 #define _Alembic_Abc_OObject_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 OArchive; 00049 class OCompoundProperty; 00050 00051 //-***************************************************************************** 00052 class OObject : public Base 00053 { 00054 public: 00055 //! By convention, we always define "this_type" in every Abc 00056 //! class. This convention is relied upon by the unspecified-bool-type 00057 //! conversion. 00058 typedef OObject this_type; 00059 typedef OObject operator_bool_base_type; 00060 00061 //-************************************************************************* 00062 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT 00063 //-************************************************************************* 00064 00065 //! The default constructor creates an empty OObject function set. 00066 //! ... 00067 OObject() {} 00068 00069 //! This templated, explicit function creates a new object writer. 00070 //! The first argument is any Abc (or AbcCoreAbstract) object 00071 //! which can intrusively be converted to an ObjectWriterPtr 00072 //! to use as a parent, from which the error handler policy for 00073 //! inheritance is also derived. The remaining optional arguments 00074 //! can be used to override the ErrorHandlerPolicy, to specify 00075 //! MetaData, and that's it. 00076 template <class OBJECT_PTR> 00077 OObject( OBJECT_PTR iParentObject, 00078 const std::string &iName, 00079 00080 const Argument &iArg0 = Argument(), 00081 const Argument &iArg1 = Argument(), 00082 const Argument &iArg2 = Argument() ); 00083 00084 //! This attaches an OObject wrapper around an existing 00085 //! ObjectWriterPtr, with an optional error handling policy. 00086 //! Arguments can be used to set error handling policy. 00087 template <class OBJECT_PTR> 00088 OObject( OBJECT_PTR iPtr, 00089 00090 WrapExistingFlag iFlag, 00091 00092 const Argument &iArg0 = Argument(), 00093 const Argument &iArg1 = Argument(), 00094 const Argument &iArg2 = Argument() ) 00095 : m_object( GetObjectWriterPtr( iPtr ) ) 00096 { 00097 // Set the error handling policy 00098 getErrorHandler().setPolicy( 00099 GetErrorHandlerPolicy( iPtr, iArg0, iArg1, iArg2 ) ); 00100 } 00101 00102 //! This attaches an OObject wrapper around the top 00103 //! object in an archive. 00104 //! Arguments can be used to set error handling policy. 00105 template <class ARCHIVE_PTR> 00106 OObject( ARCHIVE_PTR iPtr, 00107 00108 TopFlag iTop, 00109 00110 const Argument &iArg0 = Argument(), 00111 const Argument &iArg1 = Argument(), 00112 const Argument &iArg2 = Argument() ) 00113 { 00114 // Set the error handling policy 00115 getErrorHandler().setPolicy( 00116 GetErrorHandlerPolicy( iPtr, iArg0, iArg1, iArg2 ) ); 00117 00118 ALEMBIC_ABC_SAFE_CALL_BEGIN( "OObject::OObject( top )" ); 00119 00120 m_object = GetArchiveWriterPtr( iPtr )->getTop(); 00121 00122 ALEMBIC_ABC_SAFE_CALL_END_RESET(); 00123 } 00124 00125 //! Default copy constructor used 00126 //! Default assignment operator used. 00127 00128 //! Destructor 00129 //! ... 00130 ~OObject(); 00131 00132 //-************************************************************************* 00133 // OBJECT WRITER FUNCTIONALITY 00134 //-************************************************************************* 00135 00136 //! Return the object's header. 00137 //! ... 00138 const AbcA::ObjectHeader & getHeader() const; 00139 00140 //! This function returns the object's local name 00141 //! ... 00142 const std::string &getName() const 00143 { return getHeader().getName(); } 00144 00145 //! This function returns the object's full (unique with the archive) 00146 //! name 00147 const std::string &getFullName() const 00148 { return getHeader().getFullName(); } 00149 00150 //! This function returns the object's metadata. 00151 //! ... 00152 const AbcA::MetaData &getMetaData() const 00153 { return getHeader().getMetaData(); } 00154 00155 //! This function returns the object's archive, handily 00156 //! wrapped in an OArchive wrapper. 00157 OArchive getArchive(); 00158 00159 //! This function returns the object's parent, handily 00160 //! wrapped in an OObject wrapper. If the object is the top 00161 //! level object, the OObject returned will be NULL. 00162 OObject getParent(); 00163 00164 //! This function returns the number of child objects that 00165 //! this object has. This may change as new children 00166 //! are created for writing. 00167 size_t getNumChildren(); 00168 00169 //! This function returns the headers of each of the child 00170 //! objects created so far. 00171 const AbcA::ObjectHeader & getChildHeader( size_t i ); 00172 00173 //! This function returns the header of a named object if it has 00174 //! been created - even if the object no longer exists. 00175 const AbcA::ObjectHeader * getChildHeader( const std::string &iName ); 00176 00177 //! This returns the single top-level OCompoundProperty that exists 00178 //! automatically as part of the object. 00179 OCompoundProperty getProperties(); 00180 00181 //-************************************************************************* 00182 // ADVANCED TOOLS 00183 // Unless you really know why you need to be using these next few 00184 // functions, they're probably best left alone. These functions attempt 00185 // to find a pointer to an existing writer, instead of creating a new one. 00186 //-************************************************************************* 00187 00188 //! This function returns an OObject wrapped around a pointer 00189 //! to an already created child. This is distinct from creating a new 00190 //! OObject as a child. If the writer associated with this child no longer 00191 //! exists, this function will return an empty OObject. 00192 OObject getChild( size_t iChildIndex ); 00193 00194 //! This function returns an OObject wrapped around a pointer 00195 //! to an already created child. This is distinct from creating a new 00196 //! OObject as a child. If the writer associated with this child no longer 00197 //! exists, this function will return an empty OObject. 00198 OObject getChild( const std::string &iChildName ); 00199 00200 //-************************************************************************* 00201 // ABC BASE MECHANISMS 00202 // These functions are used by Abc to deal with errors, rewrapping, 00203 // and so on. 00204 //-************************************************************************* 00205 00206 //! getPtr, as usual, returns a shared ptr to the 00207 //! underlying AbcCoreAbstract object, in this case the 00208 //! ObjectWriterPtr. 00209 AbcA::ObjectWriterPtr getPtr() { return m_object; } 00210 00211 //! Reset returns this function set to an empty, default 00212 //! state. 00213 void reset() { m_object.reset(); Base::reset(); } 00214 00215 //! Valid returns whether this function set is 00216 //! valid. 00217 bool valid() const 00218 { 00219 return ( Base::valid() && m_object ); 00220 } 00221 00222 //! The unspecified-bool-type operator casts the object to "true" 00223 //! if it is valid, and "false" otherwise. 00224 ALEMBIC_OPERATOR_BOOL( valid() ); 00225 00226 private: 00227 void init( AbcA::ObjectWriterPtr iParentObject, 00228 const std::string &iName, 00229 ErrorHandler::Policy iParentPolicy, 00230 00231 const Argument &iArg0, 00232 const Argument &iArg1, 00233 const Argument &iARg2 ); 00234 00235 protected: 00236 AbcA::ObjectWriterPtr m_object; 00237 }; 00238 00239 //-***************************************************************************** 00240 //-***************************************************************************** 00241 // TEMPLATE AND INLINE FUNCTIONS 00242 //-***************************************************************************** 00243 //-***************************************************************************** 00244 00245 //-***************************************************************************** 00246 inline AbcA::ObjectWriterPtr 00247 GetObjectWriterPtr( OObject& iPrp ) 00248 { return iPrp.getPtr(); } 00249 00250 //-***************************************************************************** 00251 template <class OBJECT_PTR> 00252 inline OObject::OObject( OBJECT_PTR iParentObject, 00253 const std::string &iName, 00254 const Argument &iArg0, 00255 const Argument &iArg1, 00256 const Argument &iArg2 ) 00257 { 00258 init( GetObjectWriterPtr( iParentObject ), 00259 iName, 00260 00261 GetErrorHandlerPolicy( iParentObject ), 00262 iArg0, iArg1, iArg2 ); 00263 } 00264 00265 } // End namespace ALEMBIC_VERSION_NS 00266 00267 using namespace ALEMBIC_VERSION_NS; 00268 00269 } // End namespace Abc 00270 } // End namespace Alembic 00271 00272 #endif
1.5.9