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 #include <Alembic/AbcCoreHDF5/OwImpl.h>
38 #include <Alembic/AbcCoreHDF5/AwImpl.h>
39 #include <Alembic/AbcCoreHDF5/CpwImpl.h>
40 #include <Alembic/AbcCoreHDF5/WriteUtil.h>
41 #include <Alembic/AbcCoreHDF5/HDF5Util.h>
42 
43 namespace Alembic {
44 namespace AbcCoreHDF5 {
45 namespace ALEMBIC_VERSION_NS {
46 
OwImpl(AbcA::ArchiveWriterPtr iArchive,OwDataPtr iData,const AbcA::MetaData & iMetaData)47 OwImpl::OwImpl( AbcA::ArchiveWriterPtr iArchive,
48                 OwDataPtr iData,
49                 const AbcA::MetaData & iMetaData )
50     : m_archive( iArchive )
51     , m_header( new AbcA::ObjectHeader( "ABC", "/", iMetaData ) )
52     , m_data( iData )
53 {
54     ABCA_ASSERT( m_archive, "Invalid archive" );
55     ABCA_ASSERT( m_data, "Invalid data" );
56 }
57 
58 //-*****************************************************************************
OwImpl(AbcA::ObjectWriterPtr iParent,hid_t iParentGroup,ObjectHeaderPtr iHeader)59 OwImpl::OwImpl( AbcA::ObjectWriterPtr iParent,
60                 hid_t iParentGroup,
61                 ObjectHeaderPtr iHeader )
62   : m_parent( iParent )
63   , m_header( iHeader )
64 {
65     // Check validity of all inputs.
66     ABCA_ASSERT( m_parent, "Invalid parent" );
67     ABCA_ASSERT( m_header, "Invalid header" );
68 
69     m_archive = m_parent->getArchive();
70     ABCA_ASSERT( m_archive, "Invalid archive" );
71 
72     m_data.reset( new OwData( iParentGroup, m_header->getName(),
73                               m_header->getMetaData() ) );
74 }
75 
76 //-*****************************************************************************
~OwImpl()77 OwImpl::~OwImpl()
78 {
79     // Nothing!!
80 }
81 
82 //-*****************************************************************************
getHeader() const83 const AbcA::ObjectHeader & OwImpl::getHeader() const
84 {
85     ABCA_ASSERT( m_header, "Invalid header" );
86     return *m_header;
87 }
88 
89 //-*****************************************************************************
getArchive()90 AbcA::ArchiveWriterPtr OwImpl::getArchive()
91 {
92     return m_archive;
93 }
94 
95 //-*****************************************************************************
getParent()96 AbcA::ObjectWriterPtr OwImpl::getParent()
97 {
98     return m_parent;
99 }
100 
101 //-*****************************************************************************
getProperties()102 AbcA::CompoundPropertyWriterPtr OwImpl::getProperties()
103 {
104     return m_data->getProperties( asObjectPtr() );
105 }
106 
107 //-*****************************************************************************
getNumChildren()108 size_t OwImpl::getNumChildren()
109 {
110     return m_data->getNumChildren();
111 }
112 
113 //-*****************************************************************************
getChildHeader(size_t i)114 const AbcA::ObjectHeader & OwImpl::getChildHeader( size_t i )
115 {
116     return m_data->getChildHeader( i );
117 }
118 
getChildHeader(const std::string & iName)119 const AbcA::ObjectHeader * OwImpl::getChildHeader( const std::string &iName )
120 {
121     return m_data->getChildHeader( iName );
122 }
123 
124 //-*****************************************************************************
getChild(const std::string & iName)125 AbcA::ObjectWriterPtr OwImpl::getChild( const std::string &iName )
126 {
127     return m_data->getChild( iName );
128 }
129 
130 //-*****************************************************************************
createChild(const AbcA::ObjectHeader & iHeader)131 AbcA::ObjectWriterPtr OwImpl::createChild( const AbcA::ObjectHeader &iHeader )
132 {
133     return m_data->createChild( asObjectPtr(), m_header->getFullName(),
134                                 iHeader );
135 }
136 
137 //-*****************************************************************************
asObjectPtr()138 AbcA::ObjectWriterPtr OwImpl::asObjectPtr()
139 {
140     return shared_from_this();
141 }
142 
143 } // End namespace ALEMBIC_VERSION_NS
144 } // End namespace AbcCoreHDF5
145 } // End namespace Alembic
146