HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OBaseProperty.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_OBaseProperty_h_
38 #define _Alembic_Abc_OBaseProperty_h_
39 
40 #include <Alembic/Abc/Foundation.h>
41 #include <Alembic/Abc/Base.h>
42 #include <Alembic/Abc/Argument.h>
43 #include <Alembic/Abc/OObject.h>
44 #include <Alembic/Abc/OArchive.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 OBasePropertyT : public Base
58 {
59 public:
60  //! By convention we always define this_type in Abc classes
61  //! Used by unspecified-bool-type conversion below
64 
65 protected:
66  friend class OCompoundProperty;
67 
68  //-*************************************************************************
69  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
70  //-*************************************************************************
71 
72  //! The default constructor creates an empty OBaseProperty function set.
73  //! ...
75 
76  //! This attaches an OBaseProperty wrapper around an existing
77  //! PROP_PTR, with the given error handler policy
79 
80  //! The pointer
81  //! ...
82  PROP_PTR iPtr,
83 
84  //! The flag indicating that the intention
85  //! is to wrap the existing pointer.
86  WrapExistingFlag /* iWrapFlag */,
87 
88  //! The error handling.
89  //! ...
90  ErrorHandler::Policy iPolicy );
91 
92  //! Default copy constructor used
93  //! Default assignment operator used.
94 
95 public:
96  //-*************************************************************************
97  // PROPERTY WRITER FUNCTIONALITY
98  //-*************************************************************************
99 
100  //! Return the property's header.
101  //! ...
102  const AbcA::PropertyHeader & getHeader() const;
103 
104  //! This function returns the property's local name
105  //! ...
106  const std::string &getName() const
107  { return getHeader().getName(); }
108 
109  //! This function returns the property's type
110  //! ...
112  { return getHeader().getPropertyType(); }
113 
114  //! Convenience to return whether the property is scalar.
115  //! Same as getPropertyType() == kScalarProperty
116  bool isScalar() const { return getPropertyType() == AbcA::kScalarProperty; }
117 
118  //! Convenience to return whether the property is array.
119  //! Same as getPropertyType() == kArrayProperty
120  bool isArray() const { return getPropertyType() == AbcA::kArrayProperty; }
121 
122  //! Convenience to return whether the property is compound.
123  //! Same as getPropertyType() == kCompoundProperty
124  bool isCompound() const { return getPropertyType() ==
126 
127  //! Convenience to return whether the property is simple (non-compound)
128  //! Same as getPropertyType() != kCompoundProperty
129  bool isSimple() const { return !isCompound(); }
130 
131  //! All properties have MetaData. This just returns the
132  //! MetaData portion of the header that was used in creation.
134  { return getHeader().getMetaData(); }
135 
136  //! Non-compound properties have a DataType. 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  //! DataType from the header that was used in creation.
141  { return getHeader().getDataType(); }
142 
143  //! Non-compound properties have a TimeSamplingPtr. It is an error
144  //! to call this function for CompoundProperties, and an exception will
145  //! be thrown. This is a convenience function which just returns the
146  //! TimeSamplingPtr from the header that was used in creation.
148  { return getHeader().getTimeSampling(); }
149 
150  //! This function returns the property's object, handily
151  //! wrapped in an OObject wrapper.
152  OObject getObject() const;
153 
154  //! Can't wrap
155  //! OCompoundProperty getParent();
156 
157  //-*************************************************************************
158  // ABC BASE MECHANISMS
159  // These functions are used by Abc to deal with errors, rewrapping,
160  // and so on.
161  //-*************************************************************************
162 
163  //! getPtr, as usual, returns a shared ptr to the
164  //! underlying AbcCoreAbstract object, in this case the
165  //! PROP_PTR.
166  PROP_PTR getPtr() const { return m_property; }
167 
168  //! Reset returns this function set to an empty, default
169  //! state.
170  void reset() { m_property.reset(); Base::reset(); }
171 
172  //! Valid returns whether this function set is
173  //! valid.
174  bool valid() const
175  {
176  return ( Base::valid() && m_property );
177  }
178 
179  //! The unspecified-bool-type operator casts the object to "true"
180  //! if it is valid, and "false" otherwise.
182 
183 protected:
184  PROP_PTR m_property;
185 };
186 
187 //-*****************************************************************************
189 
190 //-*****************************************************************************
191 // TEMPLATE AND INLINE FUNCTIONS
192 //-*****************************************************************************
193 
194 //-*****************************************************************************
195 template <class PROP_PTR>
197 (
198  PROP_PTR iPtr,
199  WrapExistingFlag /* iFlag */,
200  ErrorHandler::Policy iPolicy )
201  : m_property( iPtr )
202 {
203  getErrorHandler().setPolicy( iPolicy );
204 }
205 
206 namespace {
207 
208 const AbcA::PropertyHeader g_phd;
209 
210 }
211 
212 //-*****************************************************************************
213 //-*****************************************************************************
214 //-*****************************************************************************
215 template <class PROP_PTR>
217 {
218  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OBaseProperty::getHeader()" );
219 
220  return m_property->getHeader();
221 
223 
224  // Not all error handlers throw, so have a default behavior.
225  return g_phd;
226 };
227 
228 //-*****************************************************************************
229 template <class PROP_PTR>
231 {
232  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OBaseProperty::getObject()" );
233 
234  return OObject( m_property->getObject(),
236  getErrorHandlerPolicy() );
237 
239 
240  // Not all error handlers throw. Have a default.
241  return OObject();
242 }
243 
244 } // End namespace ALEMBIC_VERSION_NS
245 
246 using namespace ALEMBIC_VERSION_NS;
247 
248 } // End namespace Abc
249 } // End namespace Alembic
250 
251 #endif
AbcA::TimeSamplingPtr getTimeSampling() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
const AbcA::MetaData & getMetaData() const
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
OBasePropertyT< AbcA::BasePropertyWriterPtr > OBaseProperty
const AbcA::DataType & getDataType() const
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
const AbcA::PropertyHeader & getHeader() const
#define ALEMBIC_ABC_SAFE_CALL_END()
Definition: ErrorHandler.h:198
OBasePropertyT< PROP_PTR > operator_bool_base_type
Definition: OBaseProperty.h:63
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104