HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OObject.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_OObject_h_
38 #define _Alembic_Abc_OObject_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 OArchive;
50 class OCompoundProperty;
51 
52 //-*****************************************************************************
53 class ALEMBIC_EXPORT OObject : 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 OObject this_type;
61 
62  //-*************************************************************************
63  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
64  //-*************************************************************************
65 
66  //! The default constructor creates an empty OObject function set.
67  //! ...
68  OObject() {}
69 
70  //! This templated, explicit function creates a new object writer.
71  //! The first argument is any Abc (or AbcCoreAbstract) object
72  //! which can intrusively be converted to an ObjectWriterPtr
73  //! to use as a parent, from which the error handler policy for
74  //! inheritance is also derived. The remaining optional arguments
75  //! can be used to override the ErrorHandlerPolicy, to specify
76  //! MetaData, and that's it.
77  template <class OBJECT_PTR>
78  OObject( OBJECT_PTR iParentObject,
79  const std::string &iName,
80 
81  const Argument &iArg0 = Argument(),
82  const Argument &iArg1 = Argument(),
83  const Argument &iArg2 = Argument() );
84 
85  //! This attaches an OObject wrapper around an existing
86  //! ObjectWriterPtr, with an optional error handling policy.
87  //! Arguments can be used to set error handling policy.
88  template <class OBJECT_PTR>
89  OObject( OBJECT_PTR iPtr,
90 
91  WrapExistingFlag /* iFlag */,
92 
93  const Argument &iArg0 = Argument(),
94  const Argument &iArg1 = Argument(),
95  const Argument &iArg2 = Argument() )
96  : m_object( GetObjectWriterPtr( iPtr ) )
97  {
98  // Set the error handling policy
99  getErrorHandler().setPolicy(
100  GetErrorHandlerPolicy( iPtr, iArg0, iArg1, iArg2 ) );
101  }
102 
103  //! This attaches an OObject wrapper around the top
104  //! object in an archive.
105  //! Arguments can be used to set error handling policy.
106  template <class ARCHIVE_PTR>
107  OObject( ARCHIVE_PTR iPtr,
108 
109  TopFlag /* iTop */,
110 
111  const Argument &iArg0 = Argument(),
112  const Argument &iArg1 = Argument(),
113  const Argument &iArg2 = Argument() )
114  {
115  // Set the error handling policy
116  getErrorHandler().setPolicy(
117  GetErrorHandlerPolicy( iPtr, iArg0, iArg1, iArg2 ) );
118 
119  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OObject::OObject( top )" );
120 
121  m_object = GetArchiveWriterPtr( iPtr )->getTop();
122 
124  }
125 
126  //! Default copy constructor used
127  //! Default assignment operator used.
128 
129  //! Destructor
130  //! ...
131  virtual ~OObject();
132 
133  //-*************************************************************************
134  // OBJECT WRITER FUNCTIONALITY
135  //-*************************************************************************
136 
137  //! Return the object's header.
138  //! ...
139  const AbcA::ObjectHeader & getHeader() const;
140 
141  //! This function returns the object's local name
142  //! ...
143  const std::string &getName() const
144  { return getHeader().getName(); }
145 
146  //! This function returns the object's full (unique with the archive)
147  //! name
148  const std::string &getFullName() const
149  { return getHeader().getFullName(); }
150 
151  //! This function returns the object's metadata.
152  //! ...
154  { return getHeader().getMetaData(); }
155 
156  //! This function returns the object's archive, handily
157  //! wrapped in an OArchive wrapper.
158  OArchive getArchive();
159 
160  //! This function returns the object's parent, handily
161  //! wrapped in an OObject wrapper. If the object is the top
162  //! level object, the OObject returned will be NULL.
163  OObject getParent();
164 
165  //! This function returns the number of child objects that
166  //! this object has. This may change as new children
167  //! are created for writing.
168  size_t getNumChildren();
169 
170  //! This function returns the headers of each of the child
171  //! objects created so far.
172  const AbcA::ObjectHeader & getChildHeader( size_t i );
173 
174  //! This function returns the header of a named object if it has
175  //! been created - even if the object no longer exists.
176  const AbcA::ObjectHeader * getChildHeader( const std::string &iName );
177 
178  //! This returns the single top-level OCompoundProperty that exists
179  //! automatically as part of the object.
180  OCompoundProperty getProperties();
181 
182  //-*************************************************************************
183  // ADVANCED TOOLS
184  // Unless you really know why you need to be using these next few
185  // functions, they're probably best left alone. These functions attempt
186  // to find a pointer to an existing writer, instead of creating a new one.
187  //-*************************************************************************
188 
189  //! This function returns an OObject wrapped around a pointer
190  //! to an already created child. This is distinct from creating a new
191  //! OObject as a child. If the writer associated with this child no longer
192  //! exists, this function will return an empty OObject.
193  OObject getChild( size_t iChildIndex );
194 
195  //! This function returns an OObject wrapped around a pointer
196  //! to an already created child. This is distinct from creating a new
197  //! OObject as a child. If the writer associated with this child no longer
198  //! exists, this function will return an empty OObject.
199  OObject getChild( const std::string &iChildName );
200 
201  //!-************************************************************************
202  // PROXY METHODS
203  // An OObject can refer to another OObject. When read in, this instance
204  // will be represented by the target source hierarchy and its children.
205  //!-************************************************************************
206  bool addChildInstance( OObject iTarget, const std::string& iName );
207 
208  //-*************************************************************************
209  // ABC BASE MECHANISMS
210  // These functions are used by Abc to deal with errors, rewrapping,
211  // and so on.
212  //-*************************************************************************
213 
214  //! getPtr, as usual, returns a shared ptr to the
215  //! underlying AbcCoreAbstract object, in this case the
216  //! ObjectWriterPtr.
217  AbcA::ObjectWriterPtr getPtr() { return m_object; }
218 
219  //! Reset returns this function set to an empty, default
220  //! state.
221  void reset() { m_object.reset(); Base::reset(); }
222 
223  //! Valid returns whether this function set is
224  //! valid.
225  bool valid() const
226  {
227  return ( Base::valid() && m_object );
228  }
229 
230  //! The unspecified-bool-type operator casts the object to "true"
231  //! if it is valid, and "false" otherwise.
232  ALEMBIC_OPERATOR_BOOL( valid() );
233 
234 private:
235  void init( AbcA::ObjectWriterPtr iParentObject,
236  const std::string &iName,
237  ErrorHandler::Policy iParentPolicy,
238 
239  const Argument &iArg0,
240  const Argument &iArg1,
241  const Argument &iARg2 );
242 
243 protected:
245 };
246 
247 //-*****************************************************************************
248 //-*****************************************************************************
249 // TEMPLATE AND INLINE FUNCTIONS
250 //-*****************************************************************************
251 //-*****************************************************************************
252 
253 //-*****************************************************************************
256 { return iPrp.getPtr(); }
257 
258 //-*****************************************************************************
259 template <class OBJECT_PTR>
260 inline OObject::OObject( OBJECT_PTR iParentObject,
261  const std::string &iName,
262  const Argument &iArg0,
263  const Argument &iArg1,
264  const Argument &iArg2 )
265 {
266  init( GetObjectWriterPtr( iParentObject ),
267  iName,
268 
269  GetErrorHandlerPolicy( iParentObject ),
270  iArg0, iArg1, iArg2 );
271 }
272 
273 } // End namespace ALEMBIC_VERSION_NS
274 
275 using namespace ALEMBIC_VERSION_NS;
276 
277 } // End namespace Abc
278 } // End namespace Alembic
279 
280 #endif
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
Alembic::Util::shared_ptr< ObjectWriter > ObjectWriterPtr
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
const AbcA::MetaData & getMetaData() const
Definition: OObject.h:153
png_uint_32 i
Definition: png.h:2877
OObject(ARCHIVE_PTR iPtr, TopFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: OObject.h:107
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
AbcA::ObjectWriterPtr GetObjectWriterPtr(AbcA::ObjectWriterPtr iPtr)
Definition: Foundation.h:184
const std::string & getFullName() const
Definition: OObject.h:148
AbcA::ObjectWriterPtr getPtr()
Definition: OObject.h:217
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
const std::string & getName() const
Definition: OObject.h:143
AbcA::ArchiveWriterPtr GetArchiveWriterPtr(AbcA::ArchiveWriterPtr iPtr)
Definition: Foundation.h:203
OObject(OBJECT_PTR iPtr, WrapExistingFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: OObject.h:89
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104