HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IBaseProperty.h
Go to the documentation of this file.
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  //-*************************************************************************
65 
66  //-*************************************************************************
67  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
68  //-*************************************************************************
69 
70  //! The default constructor creates an empty IBasePropertyT function set.
71  //! ...
73 
74  //! This attaches an IBasePropertyT wrapper around an existing
75  //! PROP_PTR, with an optional error handling policy.
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  { return getHeader().getName(); }
102 
103  //! This function returns the property's type
104  //! ...
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.
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.
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.
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  PROP_PTR getPtr() const { return m_property; }
157 
158  //! Reset returns this function set to an empty, default
159  //! state.
160  void reset() { m_property.reset(); Base::reset(); }
161 
162  //! Valid returns whether this function set is
163  //! valid.
164  bool valid() const
165  {
166  return ( Base::valid() && m_property );
167  }
168 
169  //! The unspecified-bool-type operator casts the object to "true"
170  //! if it is valid, and "false" otherwise.
172 
173 protected:
174  PROP_PTR m_property;
175 };
176 
177 //-*****************************************************************************
178 // TEMPLATE AND INLINE FUNCTIONS
179 //-*****************************************************************************
180 template <class PROP_PTR>
182 (
183  PROP_PTR iPtr,
184  ErrorHandler::Policy iPolicy )
185  : m_property( iPtr )
186 {
187  getErrorHandler().setPolicy( iPolicy );
188 }
189 
190 //-*****************************************************************************
191 template <class PROP_PTR>
193 {
194  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IBasePropertyT::getHeader()" );
195 
196  return m_property->getHeader();
197 
199 
200  // Not all error handlers throw, so have a default behavior.
201  static const AbcA::PropertyHeader phd;
202  return phd;
203 };
204 
205 //-*****************************************************************************
206 template <class PROP_PTR>
208 {
209  ALEMBIC_ABC_SAFE_CALL_BEGIN( "IBasePropertyT::getObject()" );
210 
211  return IObject( m_property->getObject(),
213  getErrorHandlerPolicy() );
214 
216 
217  // Not all error handlers throw. Have a default.
218  return IObject();
219 }
220 
221 } // End namespace ALEMBIC_VERSION_NS
222 
223 using namespace ALEMBIC_VERSION_NS;
224 
225 } // End namespace Abc
226 } // End namespace Alembic
227 
228 #endif
const AbcA::MetaData & getMetaData() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
const AbcA::PropertyHeader & getHeader() const
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
AbcA::TimeSamplingPtr getTimeSampling() const
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
IBasePropertyT< PROP_PTR > operator_bool_base_type
Definition: IBaseProperty.h:64
const AbcA::DataType & getDataType() const
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105