/src/alembic/lib/Alembic/Abc/IBaseProperty.h
Line | Count | Source |
1 | | //-***************************************************************************** |
2 | | // |
3 | | // Copyright (c) 2009-2011, |
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_IBaseProperty_h |
38 | | #define Alembic_Abc_IBaseProperty_h |
39 | | |
40 | | #include <Alembic/Abc/Foundation.h> |
41 | | #include <Alembic/Abc/Base.h> |
42 | | #include <Alembic/Abc/Argument.h> |
43 | | #include <Alembic/Abc/IObject.h> |
44 | | #include <Alembic/Abc/IArchive.h> |
45 | | |
46 | | namespace Alembic { |
47 | | namespace Abc { |
48 | | namespace ALEMBIC_VERSION_NS { |
49 | | |
50 | | //-***************************************************************************** |
51 | | //! Most of the functionality of properties (getting information about the |
52 | | //! properties and so on) is common to all property types, so we create |
53 | | //! a base class to contain all that functionality. |
54 | | //! This is purely a base class for other properties to derive from, |
55 | | //! it will never be created directly. |
56 | | template <class PROP_PTR> |
57 | | class IBasePropertyT : public Base |
58 | | { |
59 | | protected: |
60 | | //-************************************************************************* |
61 | | // TYPEDEFS AND IDENTIFIERS |
62 | | //-************************************************************************* |
63 | | typedef IBasePropertyT<PROP_PTR> this_type; |
64 | | typedef IBasePropertyT<PROP_PTR> operator_bool_base_type; |
65 | | |
66 | | //-************************************************************************* |
67 | | // CONSTRUCTION, DESTRUCTION, ASSIGNMENT |
68 | | //-************************************************************************* |
69 | | |
70 | | //! The default constructor creates an empty IBasePropertyT function set. |
71 | | //! ... |
72 | 36 | IBasePropertyT() {}Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::CompoundPropertyReader> >::IBasePropertyT() Line | Count | Source | 72 | 18 | IBasePropertyT() {} |
Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::ScalarPropertyReader> >::IBasePropertyT() Line | Count | Source | 72 | 14 | IBasePropertyT() {} |
Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::ArrayPropertyReader> >::IBasePropertyT() Line | Count | Source | 72 | 4 | IBasePropertyT() {} |
|
73 | | |
74 | | //! This attaches an IBasePropertyT wrapper around an existing |
75 | | //! PROP_PTR, with an optional error handling policy. |
76 | | IBasePropertyT( |
77 | | |
78 | | //! The pointer |
79 | | //! ... |
80 | | PROP_PTR iPtr, |
81 | | |
82 | | //! Optional error handling policy |
83 | | //! ... |
84 | | ErrorHandler::Policy iPolicy ); |
85 | | |
86 | | //! Default copy constructor used |
87 | | //! Default assignment operator used. |
88 | | |
89 | | public: |
90 | | //-************************************************************************* |
91 | | // PROPERTY WRITER FUNCTIONALITY |
92 | | //-************************************************************************* |
93 | | |
94 | | //! Return the property's header. |
95 | | //! ... |
96 | | const AbcA::PropertyHeader & getHeader() const; |
97 | | |
98 | | //! This function returns the property's local name |
99 | | //! ... |
100 | | const std::string &getName() const |
101 | 0 | { return getHeader().getName(); } |
102 | | |
103 | | //! This function returns the property's type |
104 | | //! ... |
105 | | AbcA::PropertyType getPropertyType() const |
106 | | { return getHeader().getPropertyType(); } |
107 | | |
108 | | //! Convenience to return whether the property is scalar. |
109 | | //! Same as getPropertyType() == kScalarProperty |
110 | | bool isScalar() const { return getPropertyType() == AbcA::kScalarProperty; } |
111 | | |
112 | | //! Convenience to return whether the property is array. |
113 | | //! Same as getPropertyType() == kArrayProperty |
114 | | bool isArray() const { return getPropertyType() == AbcA::kArrayProperty; } |
115 | | |
116 | | //! Convenience to return whether the property is compound. |
117 | | //! Same as getPropertyType() == kCompoundProperty |
118 | | bool isCompound() const { return getPropertyType() == AbcA::kCompoundProperty; } |
119 | | |
120 | | //! Convenience to return whether the property is simple (non-compound) |
121 | | //! Same as getPropertyType() != kCompoundProperty |
122 | | bool isSimple() const { return !isCompound(); } |
123 | | |
124 | | //! All properties have MetaData. This just returns the |
125 | | //! MetaData portion of the header that was used in creation. |
126 | | const AbcA::MetaData &getMetaData() const |
127 | | { return getHeader().getMetaData(); } |
128 | | |
129 | | //! Non-compound properties have a DataType. It is an error |
130 | | //! to call this function for CompoundProperties, and an exception will |
131 | | //! be thrown. This is a convenience function which just returns the |
132 | | //! DataType from the header that was used in creation. |
133 | | const AbcA::DataType &getDataType() const |
134 | | { return getHeader().getDataType(); } |
135 | | |
136 | | //! Non-compound properties have a TimeSamplingPtr. It is an error |
137 | | //! to call this function for CompoundProperties, and an exception will |
138 | | //! be thrown. This is a convenience function which just returns the |
139 | | //! TimeSamplingPtr from the header that was used in creation. |
140 | | AbcA::TimeSamplingPtr getTimeSampling() const |
141 | | { return getHeader().getTimeSampling(); } |
142 | | |
143 | | //! This function returns the property's object, handily |
144 | | //! wrapped in an IObject wrapper. |
145 | | IObject getObject() const; |
146 | | |
147 | | //-************************************************************************* |
148 | | // ABC BASE MECHANISMS |
149 | | // These functions are used by Abc to deal with errors, rewrapping, |
150 | | // and so on. |
151 | | //-************************************************************************* |
152 | | |
153 | | //! getPtr, as usual, returns a shared ptr to the |
154 | | //! underlying AbcCoreAbstract object, in this case the |
155 | | //! PROP_PTR. |
156 | 13 | PROP_PTR getPtr() const { return m_property; } |
157 | | |
158 | | //! Reset returns this function set to an empty, default |
159 | | //! state. |
160 | 0 | void reset() { m_property.reset(); Base::reset(); }Unexecuted instantiation: Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::ScalarPropertyReader> >::reset() Unexecuted instantiation: Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::CompoundPropertyReader> >::reset() Unexecuted instantiation: Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::ArrayPropertyReader> >::reset() |
161 | | |
162 | | //! Valid returns whether this function set is |
163 | | //! valid. |
164 | | bool valid() const |
165 | 7 | { |
166 | 7 | return ( Base::valid() && m_property ); |
167 | 7 | } Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::CompoundPropertyReader> >::valid() const Line | Count | Source | 165 | 3 | { | 166 | 3 | return ( Base::valid() && m_property ); | 167 | 3 | } |
Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::ScalarPropertyReader> >::valid() const Line | Count | Source | 165 | 4 | { | 166 | 4 | return ( Base::valid() && m_property ); | 167 | 4 | } |
Unexecuted instantiation: Alembic::Abc::v12::IBasePropertyT<std::__1::shared_ptr<Alembic::AbcCoreAbstract::v12::ArrayPropertyReader> >::valid() const |
168 | | |
169 | | //! The unspecified-bool-type operator casts the object to "true" |
170 | | //! if it is valid, and "false" otherwise. |
171 | | ALEMBIC_OPERATOR_BOOL( valid() ); |
172 | | |
173 | | protected: |
174 | | PROP_PTR m_property; |
175 | | }; |
176 | | |
177 | | //-***************************************************************************** |
178 | | // TEMPLATE AND INLINE FUNCTIONS |
179 | | //-***************************************************************************** |
180 | | template <class PROP_PTR> |
181 | | inline IBasePropertyT<PROP_PTR>::IBasePropertyT |
182 | | ( |
183 | | PROP_PTR iPtr, |
184 | | ErrorHandler::Policy iPolicy ) |
185 | 7 | : m_property( iPtr ) |
186 | 7 | { |
187 | 7 | getErrorHandler().setPolicy( iPolicy ); |
188 | 7 | } |
189 | | |
190 | | //-***************************************************************************** |
191 | | template <class PROP_PTR> |
192 | | const AbcA::PropertyHeader &IBasePropertyT<PROP_PTR>::getHeader() const |
193 | 0 | { |
194 | 0 | ALEMBIC_ABC_SAFE_CALL_BEGIN( "IBasePropertyT::getHeader()" ); |
195 | |
|
196 | 0 | return m_property->getHeader(); |
197 | |
|
198 | 0 | ALEMBIC_ABC_SAFE_CALL_END(); |
199 | | |
200 | | // Not all error handlers throw, so have a default behavior. |
201 | 0 | static const AbcA::PropertyHeader phd; |
202 | 0 | return phd; |
203 | 0 | }; |
204 | | |
205 | | //-***************************************************************************** |
206 | | template <class PROP_PTR> |
207 | | IObject IBasePropertyT<PROP_PTR>::getObject() const |
208 | 0 | { |
209 | 0 | ALEMBIC_ABC_SAFE_CALL_BEGIN( "IBasePropertyT::getObject()" ); |
210 | |
|
211 | 0 | return IObject( m_property->getObject(), |
212 | 0 | getErrorHandlerPolicy() ); |
213 | |
|
214 | 0 | ALEMBIC_ABC_SAFE_CALL_END(); |
215 | | |
216 | | // Not all error handlers throw. Have a default. |
217 | 0 | return IObject(); |
218 | 0 | } |
219 | | |
220 | | } // End namespace ALEMBIC_VERSION_NS |
221 | | |
222 | | using namespace ALEMBIC_VERSION_NS; |
223 | | |
224 | | } // End namespace Abc |
225 | | } // End namespace Alembic |
226 | | |
227 | | #endif |