HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OArchive.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_OArchive_h_
38 #define _Alembic_Abc_OArchive_h_
39 
40 #include <Alembic/Util/Export.h>
41 #include <Alembic/Abc/Foundation.h>
42 #include <Alembic/Abc/Base.h>
43 #include <Alembic/Abc/Argument.h>
44 
45 namespace Alembic {
46 namespace Abc {
47 namespace ALEMBIC_VERSION_NS {
48 
49 class OObject;
50 
51 //-*****************************************************************************
53 {
54 public:
55  //! By convention, we always define "this_type" in every Abc
56  //! class. This convention is relied upon by the unspecified-bool-type
57  //! conversion.
59 
60  //-*************************************************************************
61  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
62  //-*************************************************************************
63 
64  //! The default constructor creates an empty OArchive function set.
65  //! ...
66  OArchive() {}
67 
68  //! The explicit constructor creates an archive with the given
69  //! file name. Additional arguments that may be passed are the
70  //! error handling policy and meta data.
71  template <class ARCHIVE_CTOR>
72  OArchive(
73  //! We need to pass in a constructor which provides
74  //! an explicit link to the concrete implementation of
75  //! AbcCoreAbstract that we're using.
76  ARCHIVE_CTOR iCtor,
77 
78  //! File name
79  const std::string &iFileName,
80 
81  //! Optionally could be the error handling policy, or the meta data.
82  const Argument &iArg0 = Argument(),
83 
84  //! Optionally could be the error handling policy, or the meta data.
85  const Argument &iArg1 = Argument() );
86 
87  //! This attaches an OArchive wrapper around an existing
88  //! ArchiveWriterPtr, with an optional error handling policy.
90 
91  //! The pointer
92  //! ...
94 
95  //! Wrap existing. Here cosmetically, for consistency.
96  //! ...
97  WrapExistingFlag /* iWrap */,
98 
99  //! Optional error handling policy
100  //! ...
102  : m_archive( iPtr )
103  {
104  // Set the error handling policy.
105  getErrorHandler().setPolicy( iPolicy );
106  }
107 
108  //! Destructor
109  //! ...
110  ~OArchive();
111 
112  //! Default copy constructor
113  //! Default assignment operator
114 
115  //-*************************************************************************
116  // ARCHIVE WRITER FUNCTIONALITY
117  //-*************************************************************************
118 
119  //! Returns the file name.
120  //! It is an error to do so with an invalid object.
121  std::string getName() const;
122 
123  //! This returns the single top-level OObject that exists
124  //! automatically as part of the archive.
125  OObject getTop();
126 
127  //! Get the compression applied to array properties.
128  //! The value will be -1 for uncompressed, and 0-9 for weak through
129  //! strong gzip compression.
130  int8_t getCompressionHint() const;
131 
132  //! Set the compression applied to array properties.
133  //! Value of -1 means uncompressed, and values of 0-9 indicate increasingly
134  //! compressed data, at the expense of time.
135  void setCompressionHint( int8_t iCh );
136 
137  //! Adds the TimeSampling to the Archive TimeSampling pool.
138  //! If the TimeSampling already exists in the pool, the index for the match
139  //! should be returned.
140  //! index 0 is automatically reserved for uniform time sampling with a start
141  //! time of 0 and time per cycle of 1 (aka identity sampling)
142  uint32_t addTimeSampling( const AbcA::TimeSampling & iTs );
143 
144  //! Returns the TimeSampling at a given index.
145  //! index 0 is automatically reserved for uniform time sampling with a start
146  //! time of 0 and time per cycle of 1 (aka identity sampling)
147  AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex );
148 
149  //! Returns the total number of TimeSamplingPtrs in the Archive
150  //! TimeSampling pool.
151  uint32_t getNumTimeSamplings();
152 
153  //-*************************************************************************
154  // ABC BASE MECHANISMS
155  // These functions are used by Abc to deal with errors, rewrapping,
156  // and so on.
157  //-*************************************************************************
158 
159  //! getPtr, as usual, returns a shared ptr to the
160  //! underlying AbcCoreAbstract object, in this case the
161  //! ArchiveWriterPtr.
162  AbcA::ArchiveWriterPtr getPtr() { return m_archive; }
163 
164  //! Reset returns this function set to an empty, default
165  //! state.
166  void reset() { m_archive.reset(); Base::reset(); }
167 
168  //! Valid returns whether this function set is
169  //! valid.
170  bool valid() const
171  {
172  return ( Base::valid() && m_archive );
173  }
174 
175  //! The unspecified-bool-type operator casts the object to "true"
176  //! if it is valid, and "false" otherwise.
177  ALEMBIC_OPERATOR_BOOL( valid() );
178 
179 private:
180  AbcA::ArchiveWriterPtr m_archive;
181 };
182 
183 //-*****************************************************************************
185 {
186  return iArch.getPtr();
187 }
188 
189 //-*****************************************************************************
190 //-*****************************************************************************
191 template <class ARCHIVE_CTOR>
192 OArchive::OArchive( ARCHIVE_CTOR iCtor,
193  const std::string &iFileName,
194  const Argument &iArg0,
195  const Argument &iArg1 )
196 {
197  // Create arguments
199  iArg0.setInto( args );
200  iArg1.setInto( args );
201 
202  // Set the error handling policy.
204 
205  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArchive::OArchive( iFileName )" );
206 
207  m_archive = iCtor( iFileName, args.getMetaData() );
208 
210 }
211 
212 } // End namespace ALEMBIC_VERSION_NS
213 
214 using namespace ALEMBIC_VERSION_NS;
215 
216 } // End namespace Abc
217 } // End namespace Alembic
218 
219 #endif
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
AbcA::ArchiveWriterPtr getPtr()
Definition: OArchive.h:162
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
AbcA::ArchiveWriterPtr GetArchiveWriterPtr(AbcA::ArchiveWriterPtr iPtr)
Definition: Foundation.h:203
OArchive(AbcA::ArchiveWriterPtr iPtr, WrapExistingFlag, ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy)
Definition: OArchive.h:89
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:81
Alembic::Util::shared_ptr< ArchiveWriter > ArchiveWriterPtr
Smart Ptrs to Writers.
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104