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