HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  //! Optional error handling policy
96  //! ...
98  : m_archive( iPtr )
99  {
100  // Set the error handling policy.
101  getErrorHandler().setPolicy( iPolicy );
102  }
103 
104  // Deprecated in favor of the constructor above
107  WrapExistingFlag /* iWrap */,
109  : m_archive( iPtr )
110  {
111  // Set the error handling policy.
112  getErrorHandler().setPolicy( iPolicy );
113  }
114 
115  //! Destructor
116  //! ...
117  ~OArchive();
118 
119  //! Default copy constructor
120  //! Default assignment operator
121 
122  //-*************************************************************************
123  // ARCHIVE WRITER FUNCTIONALITY
124  //-*************************************************************************
125 
126  //! Returns the file name.
127  //! It is an error to do so with an invalid object.
128  std::string getName() const;
129 
130  //! This returns the single top-level OObject that exists
131  //! automatically as part of the archive.
132  OObject getTop();
133 
134  //! Get the compression applied to array properties.
135  //! The value will be -1 for uncompressed, and 0-9 for weak through
136  //! strong gzip compression.
137  int8_t getCompressionHint() const;
138 
139  //! Set the compression applied to array properties.
140  //! Value of -1 means uncompressed, and values of 0-9 indicate increasingly
141  //! compressed data, at the expense of time.
142  void setCompressionHint( int8_t iCh );
143 
144  //! Adds the TimeSampling to the Archive TimeSampling pool.
145  //! If the TimeSampling already exists in the pool, the index for the match
146  //! should be returned.
147  //! index 0 is automatically reserved for uniform time sampling with a start
148  //! time of 0 and time per cycle of 1 (aka identity sampling)
149  uint32_t addTimeSampling( const AbcA::TimeSampling & iTs );
150 
151  //! Returns the TimeSampling at a given index.
152  //! index 0 is automatically reserved for uniform time sampling with a start
153  //! time of 0 and time per cycle of 1 (aka identity sampling)
154  AbcA::TimeSamplingPtr getTimeSampling( uint32_t iIndex );
155 
156  //! Returns the total number of TimeSamplingPtrs in the Archive
157  //! TimeSampling pool.
158  uint32_t getNumTimeSamplings();
159 
160  //-*************************************************************************
161  // ABC BASE MECHANISMS
162  // These functions are used by Abc to deal with errors, rewrapping,
163  // and so on.
164  //-*************************************************************************
165 
166  //! getPtr, as usual, returns a shared ptr to the
167  //! underlying AbcCoreAbstract object, in this case the
168  //! ArchiveWriterPtr.
169  AbcA::ArchiveWriterPtr getPtr() { return m_archive; }
170 
171  //! Reset returns this function set to an empty, default
172  //! state.
173  void reset() { m_archive.reset(); Base::reset(); }
174 
175  //! Valid returns whether this function set is
176  //! valid.
177  bool valid() const
178  {
179  return ( Base::valid() && m_archive );
180  }
181 
182  //! The unspecified-bool-type operator casts the object to "true"
183  //! if it is valid, and "false" otherwise.
184  ALEMBIC_OPERATOR_BOOL( valid() );
185 
186 private:
187  AbcA::ArchiveWriterPtr m_archive;
188 };
189 
190 //-*****************************************************************************
192 {
193  return iArch.getPtr();
194 }
195 
196 //-*****************************************************************************
197 //-*****************************************************************************
198 template <class ARCHIVE_CTOR>
199 OArchive::OArchive( ARCHIVE_CTOR iCtor,
200  const std::string &iFileName,
201  const Argument &iArg0,
202  const Argument &iArg1 )
203 {
204  // Create arguments
206  iArg0.setInto( args );
207  iArg1.setInto( args );
208 
209  // Set the error handling policy.
211 
212  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OArchive::OArchive( iFileName )" );
213 
214  m_archive = iCtor( iFileName, args.getMetaData() );
215 
217 }
218 
219 } // End namespace ALEMBIC_VERSION_NS
220 
221 using namespace ALEMBIC_VERSION_NS;
222 
223 } // End namespace Abc
224 } // End namespace Alembic
225 
226 #endif
#define ALEMBIC_OPERATOR_BOOL(PASS_COND)
Definition: OperatorBool.h:42
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
#define ALEMBIC_EXPORT
Definition: Export.h:51
AbcA::ArchiveWriterPtr getPtr()
Definition: OArchive.h:169
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
#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:213
**If you just want to fire and args
Definition: thread.h:609
OArchive(AbcA::ArchiveWriterPtr iPtr, ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy)
Definition: OArchive.h:89
OArchive(AbcA::ArchiveWriterPtr iPtr, WrapExistingFlag, ErrorHandler::Policy iPolicy=ErrorHandler::kThrowPolicy)
Definition: OArchive.h:105
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
Alembic::Util::shared_ptr< ArchiveWriter > ArchiveWriterPtr
Smart Ptrs to Writers.
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88