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_AbcCoreAbstract_PropertyHeader_h
38 #define Alembic_AbcCoreAbstract_PropertyHeader_h
39 
40 #include <Alembic/AbcCoreAbstract/Foundation.h>
41 #include <Alembic/AbcCoreAbstract/MetaData.h>
42 #include <Alembic/AbcCoreAbstract/DataType.h>
43 #include <Alembic/AbcCoreAbstract/TimeSampling.h>
44 
45 namespace Alembic {
46 namespace AbcCoreAbstract {
47 namespace ALEMBIC_VERSION_NS {
48 
49 //-*****************************************************************************
50 //! In Alembic, Objects may have three distinct types of abstract properties.
51 //! Any fancy type-specific properties are ultimately and instance of one
52 //! of these three types of properties, identified here by an enum.
53 //! "Simple" properties are simply "non-compound" properties -
54 //! the SimpleProperty classes are simply common base classes for
55 //! Scalar and Array Properties.
56 enum PropertyType
57 {
58 
59     //! Compound Properties are groups of other properties, with their own
60     //! unique name and set of MetaData. All objects have a single root
61     //! compound property as the base of their property description.
62     kCompoundProperty = 0,
63 
64     //! Scalar Properties represent Rank-0 properties, which contain a
65     //! single element value for any given time sample.
66     kScalarProperty = 1,
67 
68     //! Array Properties represent Rank-N properties, which contain an
69     //! array of values for any given time sample. Array properties may have
70     //! any rank of 1 or higher, but will most often be ranks 1, 2, 3.
71     kArrayProperty = 2
72 };
73 
74 //-*****************************************************************************
75 //! The PropertyHeader is a collection of MetaData which helps define a
76 //! Property. It also acts as a key for getting an instance of a property
77 //! from a CompoundProperty.
78 class PropertyHeader
79 {
80 public:
81     //! Default constructor creates an invalid property.
82     //! The propertyType is set to Scalar, but the dataType will be set
83     //! to its default value of kUnknownPOD[1]
PropertyHeader()84     PropertyHeader()
85       : m_name(),
86         m_propertyType( kScalarProperty ),
87         m_metaData(),
88         m_dataType(),
89         m_timeSampling() {}
90 
91     //! Construct a compound property header.
92     //! Just give a name and metadata, the rest is redundant or unused.
PropertyHeader(const std::string & iName,const MetaData & iMetaData)93     explicit PropertyHeader( const std::string &iName,
94                              const MetaData &iMetaData )
95       : m_name( iName ),
96         m_propertyType( kCompoundProperty ),
97         m_metaData( iMetaData ),
98         m_dataType(),
99         m_timeSampling() {}
100 
101     //! Construct a simple property header.
102     //! Use this for array or scalar properties.
PropertyHeader(const std::string & iName,PropertyType iPropType,const MetaData & iMetaData,const DataType & iDataType,const TimeSamplingPtr & iTsamp)103     PropertyHeader( const std::string &iName,
104                     PropertyType iPropType,
105                     const MetaData &iMetaData,
106                     const DataType &iDataType,
107                     const TimeSamplingPtr & iTsamp )
108       : m_name( iName ),
109         m_propertyType( iPropType ),
110         m_metaData( iMetaData ),
111         m_dataType( iDataType ),
112         m_timeSampling( iTsamp ) {}
113 
114     //! Copy constructor
115     //! ...
PropertyHeader(const PropertyHeader & iCopy)116     PropertyHeader( const PropertyHeader &iCopy )
117       : m_name( iCopy.m_name ),
118         m_propertyType( iCopy.m_propertyType ),
119         m_metaData( iCopy.m_metaData ),
120         m_dataType( iCopy.m_dataType ),
121         m_timeSampling( iCopy.m_timeSampling ) {}
122 
123     //! Assignment operator
124     //! ...
125     PropertyHeader& operator=( const PropertyHeader &iCopy )
126     {
127         m_name = iCopy.m_name;
128         m_propertyType = iCopy.m_propertyType;
129         m_metaData = iCopy.m_metaData;
130         m_dataType = iCopy.m_dataType;
131         m_timeSampling = iCopy.m_timeSampling;
132         return *this;
133     }
134 
135     //! All properties have a name, which is unique amongst its siblings.
136     //! ...
getName()137     const std::string &getName() const { return m_name; }
138 
setName(const std::string & iName)139     void setName( const std::string &iName ) { m_name = iName; }
140 
141     //! All properties have a type, which is the enum defined above.
142     //! ...
getPropertyType()143     PropertyType getPropertyType() const { return m_propertyType; }
144 
setPropertyType(PropertyType iPtyp)145     void setPropertyType( PropertyType iPtyp ) { m_propertyType = iPtyp; }
146 
147     //! Convenience to return whether the property is scalar.
148     //! Same as getPropertyType() == kScalarProperty
isScalar()149     bool isScalar() const { return m_propertyType == kScalarProperty; }
150 
151     //! Convenience to return whether the property is array.
152     //! Same as getPropertyType() == kArrayProperty
isArray()153     bool isArray() const { return m_propertyType == kArrayProperty; }
154 
155     //! Convenience to return whether the property is compound.
156     //! Same as getPropertyType() == kCompoundProperty
isCompound()157     bool isCompound() const { return m_propertyType == kCompoundProperty; }
158 
159     //! Convenience to return whether the property is simple (non-compound)
160     //! Same as getPropertyType() != kCompoundProperty
isSimple()161     bool isSimple() const { return !isCompound(); }
162 
163     //! All properties have metadata.
164     //! ...
getMetaData()165     const MetaData &getMetaData() const { return m_metaData; }
166 
setMetaData(const MetaData & iMetaData)167     void setMetaData( const MetaData &iMetaData ) { m_metaData = iMetaData; }
168 
169     //! Non-compound properties have a data type.
170     //! If this is called for a Compound Property (basically, one which
171     //! returns kCompoundProperty from getType() above)
172     //! it will throw an exception.
getDataType()173     const DataType &getDataType() const { return m_dataType; }
174 
setDataType(const DataType & iDataType)175     void setDataType( const DataType &iDataType ) { m_dataType = iDataType; }
176 
177     //! Non-compound properties have time sampling
178     //! If this is called for a Compound Property (basically, one which
179     //! returns kCompoundProperty from getType() above)
180     //! it will throw an exception.
getTimeSampling()181     TimeSamplingPtr getTimeSampling() const
182     { return m_timeSampling; }
183 
setTimeSampling(const TimeSamplingPtr & iTsamp)184     void setTimeSampling( const TimeSamplingPtr &iTsamp )
185     { m_timeSampling = iTsamp; }
186 
187 private:
188     std::string m_name;
189     PropertyType m_propertyType;
190     MetaData m_metaData;
191     DataType m_dataType;
192     TimeSamplingPtr m_timeSampling;
193 };
194 
195 } // End namespace ALEMBIC_VERSION_NS
196 
197 using namespace ALEMBIC_VERSION_NS;
198 
199 } // End namespace AbcCoreAbstract
200 } // End namespace Alembic
201 
202 #endif
203