HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataType.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
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_DataType_h
38 #define Alembic_AbcCoreAbstract_DataType_h
39 
41 
42 namespace Alembic {
43 namespace AbcCoreAbstract {
44 namespace ALEMBIC_VERSION_NS {
45 
46 //-*****************************************************************************
47 //! The DataType class is a description of how an element of a sample in a
48 //! Scalar or an Array property is stored. It does not contain an interpretation
49 //! this is left to the metadata of the properties themselves.
52 {
53 public:
54  //! Default constructor
55  //! Sets the DataType to an unknown DataType with extent 0.
56  //! This is obviously an invalid storage description, and is used in
57  //! cases where we need to indicated that a DataType could not be
58  //! determined.
60  : m_pod( kUnknownPOD ), m_extent( 0 ) {}
61 
62  //! Explicit constructor.
63  //! Takes a pod and an extent.
64  //! By default the extent is 1.
65  //! For String and Wstring types, the extent _must_ be 1.
66  explicit DataType( PlainOldDataType iPod, uint8_t iExtent = 1 )
67  : m_pod( iPod ), m_extent( iExtent ) {}
68 
69  //! Default copy constructor used.
70  //! Default assignment operator used.
71 
72  //! Return the PlainOldDataType enum
73  //! ...
74  PlainOldDataType getPod() const { return m_pod; }
75 
76  //! Set the PlainOldDataType
77  //! ...
78  void setPod( PlainOldDataType iPod ) { m_pod = iPod; }
79 
80  //! Return the 8-bit extent
81  //! ...
82  uint8_t getExtent() const { return m_extent; }
83 
84  //! Set the 8-bit extent
85  //! ...
86  void setExtent( uint8_t iExtent ) { m_extent = iExtent; }
87 
88  //! Returns the number of bytes occupied by a single datum. (element)
89  //! The assumption that each element has a fixed size in memory is a
90  //! core assumption in Alembic.
91  //!
92  //! String DataTypes are a troublesome problem. A single string datum
93  //! does not have a fixed number of bytes associated with it. So we
94  //! are returning, here, the size of the std::string and std::wstring
95  //! datatypes, respectively.
96  size_t getNumBytes() const
97  {
98  return PODNumBytes( m_pod ) * ( size_t )m_extent;
99  }
100 
101  //! Equality operator
102  //! ...
103  bool operator==( const DataType &b ) const
104  {
105  return ( ( m_pod == b.m_pod ) &&
106  ( m_extent == b.m_extent ) );
107  }
108 
109  //-*************************************************************************
110  //! Returns whether one datatype is lexigraphically "less" than
111  //! another - this has meaning only so that DataType instances can
112  //! be meaningfully sorted.
113  bool operator<( const DataType &b ) const
114  {
115  if ( m_pod < b.m_pod ) { return true; }
116  else if ( m_pod > b.m_pod ) { return false; }
117  else { return ( m_extent < b.m_extent ); }
118  }
119 
120 private:
121  //! An Enum indicating which PlainOldDataType is our
122  //! super-storage-class.
123  PlainOldDataType m_pod;
124 
125  //! An 8-bit extent indicating the cardinality of
126  //! a single element of data.
127  uint8_t m_extent;
128 };
129 
130 //-*****************************************************************************
131 //! Outputs DataType to a std::ostream
132 //! Makes use of PlainOldDataType's string conversion functions
133 inline std::ostream &operator<<( std::ostream &ostr, const DataType &a )
134 {
135  ostr << PODName( a.getPod() );
136  if ( a.getExtent() > 1 )
137  {
138  ostr << "[" << ( size_t )a.getExtent() << "]";
139  }
140  return ostr;
141 }
142 
143 } // End namespace ALEMBIC_VERSION_NS
144 
145 using namespace ALEMBIC_VERSION_NS;
146 
147 } // End namespace AbcCoreAbstract
148 } // End namespace Alembic
149 
150 #endif
size_t PODNumBytes(PlainOldDataType pod)
DataType(PlainOldDataType iPod, uint8_t iExtent=1)
Definition: DataType.h:66
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define ALEMBIC_EXPORT
Definition: Export.h:51
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
Definition: DataType.h:133
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
const char * PODName(PlainOldDataType pod)
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88