Alembic: Abc/ArchiveInfo.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
ArchiveInfo.h
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_ArchiveInfo_h
38#define Alembic_Abc_ArchiveInfo_h
39
40#include <Alembic/Util/Export.h>
41#include <Alembic/Abc/Foundation.h>
42#include <Alembic/Abc/IArchive.h>
43#include <Alembic/Abc/OArchive.h>
44#include <cfloat>
45#include <time.h>
46
47namespace Alembic {
48namespace Abc {
49namespace ALEMBIC_VERSION_NS {
50
51//-*****************************************************************************
52// Alembic archive information:
53// Useful utilities that readers and writers can use to provide
54// useful annotations into the alembic file.
55
56//-*****************************************************************************
57// Some MetaData key constants
58static const char * kApplicationNameKey = "_ai_Application";
59static const char * kDateWrittenKey = "_ai_DateWritten";
60static const char * kUserDescriptionKey = "_ai_Description";
61static const char * kDCCFPSKey = "_ai_DCC_FPS";
62
63//-*****************************************************************************
64template <class ARCHIVE_CTOR>
65 OArchive CreateArchiveWithInfo(
69 ARCHIVE_CTOR iCtor,
70
72 const std::string &iFileName,
73
75 const std::string & iApplicationWriter,
76
79 const std::string & iUserDescription,
80
82 const Argument &iArg0 = Argument(),
83
85 const Argument &iArg1 = Argument() );
86
87//-*****************************************************************************
88template <class ARCHIVE_CTOR>
89 OArchive CreateArchiveWithInfo(
93 ARCHIVE_CTOR iCtor,
94
96 const std::string &iFileName,
97
99 double iDCCFPS,
100
102 const std::string & iApplicationWriter,
103
106 const std::string & iUserDescription,
107
109 const Argument &iArg0 = Argument(),
110
112 const Argument &iArg1 = Argument() );
113
114//-*****************************************************************************
115ALEMBIC_EXPORT void
116GetArchiveInfo(
118 IArchive & iArchive,
119
121 std::string & oApplicationWriter,
122
124 std::string & oAlembicVersion,
125
127 Util::uint32_t & oAlembicApiVersion,
128
130 std::string & oDateWritten,
131
133 std::string & oUserDescription );
134
135//-*****************************************************************************
136ALEMBIC_EXPORT void
137GetArchiveInfo(
139 IArchive & iArchive,
140
142 std::string & oApplicationWriter,
143
145 std::string & oAlembicVersion,
146
148 Util::uint32_t & oAlembicApiVersion,
149
151 std::string & oDateWritten,
152
154 std::string & oUserDescription,
155
158 double & oDCCFPS);
159
160//-*****************************************************************************
167ALEMBIC_EXPORT void
168GetArchiveStartAndEndTime(
170 IArchive & iArchive,
172 double & oStartTime,
174 double & oEndTime );
175
176//-*****************************************************************************
177template <class ARCHIVE_CTOR>
178 OArchive CreateArchiveWithInfo(
179 ARCHIVE_CTOR iCtor,
180 const std::string &iFileName,
181 double iDCCFPS,
182 const std::string &iApplicationWriter,
183 const std::string &iUserDescription,
184 const Argument &iArg0,
185 const Argument &iArg1 )
186{
187 AbcA::MetaData md = GetMetaData( iArg0, iArg1 );
188 ErrorHandler::Policy policy = GetErrorHandlerPolicyFromArgs( iArg0, iArg1 );
189
190 if ( iApplicationWriter != "" )
191 {
192 md.set( kApplicationNameKey, iApplicationWriter );
193 }
194
195 time_t rawtimeNow;
196 time( &rawtimeNow );
197 char dateBuf [128];
198#if defined _WIN32 || defined _WIN64
199 ctime_s( dateBuf, 128, &rawtimeNow);
200#else
201 ctime_r( &rawtimeNow, dateBuf );
202#endif
203
204 std::size_t bufLen = strlen( dateBuf );
205 if ( bufLen > 0 && dateBuf[bufLen - 1] == '\n' )
206 {
207 dateBuf[bufLen - 1] = '\0';
208 }
209 md.set( kDateWrittenKey, dateBuf );
210
211 if ( iUserDescription != "" )
212 {
213 md.set( kUserDescriptionKey, iUserDescription );
214 }
215
216 if ( iDCCFPS > 0.0 )
217 {
218 md.set( kDCCFPSKey, std::to_string( iDCCFPS ) );
219 }
220
221 return OArchive( iCtor, iFileName, md, policy );
222
223}
224
225template <class ARCHIVE_CTOR>
226 OArchive CreateArchiveWithInfo(
227 ARCHIVE_CTOR iCtor,
228 const std::string &iFileName,
229 const std::string &iApplicationWriter,
230 const std::string &iUserDescription,
231 const Argument &iArg0,
232 const Argument &iArg1 )
233{
234 return CreateArchiveWithInfo( iCtor, iFileName, 0, iApplicationWriter,
235 iUserDescription, iArg0, iArg1 );
236}
237
238} // End namespace ALEMBIC_VERSION_NS
239
240using namespace ALEMBIC_VERSION_NS;
241
242} // End namespace Abc
243} // End namespace Alembic
244
245#endif
Alembic::Abc::ALEMBIC_VERSION_NS::Argument
Definition Argument.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::IArchive
Definition IArchive.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::OArchive
Definition OArchive.h:53
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData
Definition MetaData.h:60
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39