HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IObject.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_IObject_h
38 #define Alembic_Abc_IObject_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 #include <Alembic/Abc/IArchive.h>
45 
46 namespace Alembic {
47 namespace Abc {
48 namespace ALEMBIC_VERSION_NS {
49 
50 class ICompoundProperty;
51 
52 //-*****************************************************************************
53 class ALEMBIC_EXPORT IObject : public Base
54 {
55 public:
56  //! By convention, we always define "this_type" in every Abc
57  //! class. This convention is relied upon by the unspecified-bool-type
58  //! conversion.
59  typedef IObject this_type;
61 
62  //-*************************************************************************
63  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
64  //-*************************************************************************
65 
66  //! The default constructor creates an empty IObject function set.
67  //! ...
68  IObject() {}
69 
70  //! This function creates a new object reader.
71  //! The first argument is the Abc IObject parent from which the error
72  //! handler policy for inheritance is also derived. The remaining optional
73  //! arguments can be used to override the ErrorHandlerPolicy.
74  IObject( const IObject & iParent,
75  const std::string &iName,
76  const Argument &iArg0 = Argument() )
77  {
78  init( iParent.getPtr(),
79  iName,
80  GetErrorHandlerPolicy( iParent, iArg0 ) );
81 
82  initInstance();
83  }
84 
85  //! This attaches an IObject wrapper around an existing
86  //! ObjectReaderPtr, with an optional error handling policy.
88  const Argument &iArg0 = Argument() )
89  : m_object( GetObjectReaderPtr( iPtr ) )
90  {
91  // Set the error handling policy
92  getErrorHandler().setPolicy(
93  GetErrorHandlerPolicy( iPtr, iArg0 ) );
94 
95  initInstance();
96  }
97 
98  // Deprecated in favor of the constructor above
100  WrapExistingFlag /* iFlag */,
101  const Argument &iArg0 = Argument() )
102  : m_object( GetObjectReaderPtr( iPtr ) )
103  {
104  // Set the error handling policy
105  getErrorHandler().setPolicy(
106  GetErrorHandlerPolicy( iPtr, iArg0 ) );
107 
108  initInstance();
109  }
110 
111  //! This attaches an IObject wrapper around the top
112  //! object of an archive.
113  IObject( IArchive & iArchive,
114  const Argument &iArg0 = Argument() )
115  {
116  init( iArchive, iArg0 );
117  }
118 
119  // Deprecated in favor of the constructor above
120  IObject( IArchive & iArchive,
121  TopFlag iFlag,
122  const Argument &iArg0 = Argument() )
123  {
124  init( iArchive, iArg0 );
125  }
126 
127  //! Default copy constructor used
128  //! Default assignment operator used.
129 
130  //! Destructor
131  //! ...
132  virtual ~IObject();
133 
134  //-*************************************************************************
135  // OBJECT READER FUNCTIONALITY
136  //-*************************************************************************
137 
138  //! All objects have a header, which contains all the MetaData that was
139  //! specified upon their creation.
140  //! This function returns a constant reference to that Header.
141  const AbcA::ObjectHeader &getHeader() const;
142 
143  //! All objects have a name. This name is unique amongst their siblings
144  //! Returned by reference, since it is guaranteed to exist and be
145  //! unchanging.
146  //! This is a convenience function which returns the header's name.
147  const std::string &getName() const;
148 
149  //! The full name of an object is the complete path name all the way
150  //! to the root object of the archive. It is guaranteed to be fully
151  //! unique within the entire archive.
152  //! This is a convenience function which returns the header's full name.
153  const std::string &getFullName() const;
154 
155  //! All objects have metadata. This metadata is identical to the
156  //! Metadata of the top level compoundProperty "properties".
157  //! Because the metadata must exist and be initialized in order to
158  //! bootstrap the object, it is guaranteed to exist and is returned
159  //! by reference.
160  //! This is a convenience function which returns the header's MetaData.
162  { return getHeader().getMetaData(); }
163 
164  //! This function returns the object's archive, handily
165  //! wrapped in an IArchive wrapper.
166  IArchive getArchive() const;
167 
168  //! This function returns the object's parent, handily
169  //! wrapped in an IObject wrapper. If the object is the top
170  //! level object, the IObject returned will be NULL.
171  IObject getParent() const;
172 
173  //! This function returns the number of child objects that
174  //! this object has.
175  size_t getNumChildren() const;
176 
177  //! This function returns the headers of each of the child
178  //! objects that were written as children of this object.
179  const AbcA::ObjectHeader & getChildHeader( size_t i ) const;
180 
181  //! Return the header of an object by name.
182  //! This will return a NULL pointer if no header by that name is found.
183  const AbcA::ObjectHeader *
184  getChildHeader( const std::string &iName ) const;
185 
186  //! This returns the single top-level CompoundPropertyReader that exists
187  //! automatically as part of the object.
188  ICompoundProperty getProperties() const;
189 
190  //-*************************************************************************
191  // ADVANCED TOOLS
192  // Unless you really know why you need to be using these next few
193  // functions, they're probably best left alone. The right way to create
194  // an IObject is to actually call its constructor.
195  //-*************************************************************************
196 
197  //! This function returns an IObject constructed from the indexed
198  //! object.
199  IObject getChild( size_t iChildIndex ) const;
200 
201  //! This function returns an IObject wrapped constructed from the
202  //! header referenced by the name. If the child of the given name
203  //! does not exist, this will fail in the same way as if the
204  //! equivalent constructor was called.
205  IObject getChild( const std::string &iChildName ) const;
206 
207  //!-************************************************************************
208  // INSTANCE METHODS
209  // An IObject can refer to another IObject in the same cache and stand in
210  // as an instance for that target hierarchy. On disk only the instance
211  // object is required. When read in however, a normal hierarchy is
212  // returned. Optionally, client code could use the isInstanceRoot() and
213  // instanceSourcePath() methods to discover that the hierarchies are
214  // duplicate and instance them appropriately in memory.
215  //!-************************************************************************
216 
217  //! Returns whether this object directly instances another object.
218  bool isInstanceRoot() const;
219 
220  //! Returns whether this object has been arrived at via an instance, or if
221  //! this object is an instance itself.
222  bool isInstanceDescendant() const;
223 
224  //! If this object is an instance (isInstanceRoot), returns the source path
225  //! that the instance points at. Otherwise and empty string is returned.
226  std::string instanceSourcePath() const;
227 
228  bool isChildInstance(size_t iChildIndex) const;
229  bool isChildInstance(const std::string &iChildName) const;
230 
231  //! Returns the original ObjectReaderPtr, if this object is an instance
232  AbcA::ObjectReaderPtr getInstancePtr() const { return m_instanceObject; }
233 
234  //-*************************************************************************
235  // ABC BASE MECHANISMS
236  // These functions are used by Abc to deal with errors, rewrapping,
237  // and so on.
238  //-*************************************************************************
239 
240  //! getPtr, as usual, returns a shared ptr to the
241  //! underlying AbcCoreAbstract object, in this case the
242  //! ObjectReaderPtr. If this object happens to be an instance, it points
243  //! to the instance source ObjectReaderPtr
244  AbcA::ObjectReaderPtr getPtr() const { return m_object; }
245 
246  //! Reset returns this function set to an empty, default state.
247  void reset();
248 
249  //! Valid returns whether this function set is
250  //! valid.
251  bool valid() const
252  {
253  return ( Base::valid() && m_object );
254  }
255 
256  //! If an aggregated properties hash exists fill oDigest with it and
257  //! return true, if it doesn't exist return false
258  bool getPropertiesHash( Util::Digest & oDigest );
259 
260  //! If an aggregated child objects hash exists fill oDigest with it and
261  //! return true, if it doesn't exist return false
262  bool getChildrenHash( Util::Digest & oDigest );
263 
264  //! The unspecified-bool-type operator casts the object to "true"
265  //! if it is valid, and "false" otherwise.
266  ALEMBIC_OPERATOR_BOOL( valid() );
267 
268 public:
270 
271 private:
272 
273  void init( IArchive & iArchive, const Argument &iArg0 );
274 
275  void init( AbcA::ObjectReaderPtr iParentObject,
276  const std::string &iName,
277  ErrorHandler::Policy iPolicy );
278 
279  void initInstance();
280 
281  void setInstancedFullName(const std::string& parentPath) const;
282 
283  // This is the "original" object when it is an instance (not the source)
284  AbcA::ObjectReaderPtr m_instanceObject;
285 
286  // All IObject ancestors of an instance object have these set.
287  mutable std::string m_instancedFullName;
288 };
289 
290 typedef Alembic::Util::shared_ptr< IObject > IObjectPtr;
291 
292 //-*****************************************************************************
294 GetObjectReaderPtr( IObject& iPrp ) { return iPrp.getPtr(); }
295 
296 //-*****************************************************************************
297 // TEMPLATE AND INLINE FUNCTIONS
298 //-*****************************************************************************
299 
300 template <class OBJ>
302  ErrorHandler::Policy iPcy )
303 {
304  Argument arg( iPcy );
305  return GetErrorHandlerPolicy( iObj, arg );
306 }
307 
308 } // End namespace ALEMBIC_VERSION_NS
309 
310 using namespace ALEMBIC_VERSION_NS;
311 
312 } // End namespace Abc
313 } // End namespace Alembic
314 
315 #endif
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
const AbcA::MetaData & getMetaData() const
Definition: IObject.h:161
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
Alembic::Util::shared_ptr< ObjectReader > ObjectReaderPtr
#define ALEMBIC_EXPORT
Definition: Export.h:51
AbcA::ObjectReaderPtr getInstancePtr() const
Returns the original ObjectReaderPtr, if this object is an instance.
Definition: IObject.h:232
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1736
GU_API GA_Offset getParent(const GU_Detail *gdp, const GA_Offset &node)
IObject(AbcA::ObjectReaderPtr iPtr, const Argument &iArg0=Argument())
Definition: IObject.h:87
GLboolean reset
Definition: glad.h:5138
AbcA::ObjectReaderPtr getPtr() const
Definition: IObject.h:244
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
IObject(IArchive &iArchive, const Argument &iArg0=Argument())
Definition: IObject.h:113
Alembic::Util::shared_ptr< IObject > IObjectPtr
Definition: IObject.h:290
AbcA::ObjectReaderPtr GetObjectReaderPtr(AbcA::ObjectReaderPtr iPtr)
Definition: Foundation.h:200
IObject(AbcA::ObjectReaderPtr iPtr, WrapExistingFlag, const Argument &iArg0=Argument())
Definition: IObject.h:99
IObject(IArchive &iArchive, TopFlag iFlag, const Argument &iArg0=Argument())
Definition: IObject.h:120
IObject(const IObject &iParent, const std::string &iName, const Argument &iArg0=Argument())
Definition: IObject.h:74
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88