Field3D
IData.cpp
Go to the documentation of this file.
1//-*****************************************************************************
2//
3// Copyright (c) 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 Industrial Light & Magic nor the names of
19// its contributors may be used to endorse or promote products derived
20// from this software without specific prior written permission.
21//
22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33//
34//-*****************************************************************************
35
36#include "Foundation.h"
37#include "IGroup.h"
38#include "IData.h"
39#include "IStreams.h"
40
41namespace Alembic {
42namespace Ogawa {
43namespace ALEMBIC_VERSION_NS {
44
45class IData::PrivateData
46{
47public:
48 PrivateData(IStreamsPtr iStreams)
49 {
50 streams = iStreams;
51 };
52
53 ~PrivateData() {};
54
55 IStreamsPtr streams;
56
57 // set after freeze
58 Alembic::Util::uint64_t pos;
59 Alembic::Util::uint64_t size;
60};
61
62IData::~IData()
63{
64
65}
66
67IData::IData(IStreamsPtr iStreams,
68 Alembic::Util::uint64_t iPos,
69 std::size_t iThreadId) :
70 mData(new IData::PrivateData(iStreams))
71{
72 mData->size = 0;
73
74 // strip off the top bit (indicates data) to get our seek position
75 mData->pos = iPos & INVALID_GROUP;
76
77 Alembic::Util::uint64_t size = 0;
78
79 // not the empty group? then figure out our size
80 if ( mData->pos != 0 )
81 {
82 mData->streams->read(iThreadId, mData->pos, 8, &size);
83 mData->size = size;
84 }
85}
86
87void IData::read(Alembic::Util::uint64_t iSize, void * iData,
88 Alembic::Util::uint64_t iOffset, std::size_t iThreadId)
89{
90 // don't read anything if we will read beyond our buffer
91 if (iSize == 0 || mData->size == 0 || iOffset + iSize > mData->size)
92 {
93 return;
94 }
95
96 // +8 is to account for the size
97 mData->streams->read(iThreadId, mData->pos + iOffset + 8, iSize, iData);
98}
99
100Alembic::Util::uint64_t IData::getSize() const
101{
102 return mData->size;
103}
104
105Alembic::Util::uint64_t IData::getPos() const
106{
107 return mData->pos;
108}
109
110} // End namespace ALEMBIC_VERSION_NS
111} // End namespace Ogawa
112} // End namespace Alembic
#define FIELD3D_MTX_T
Definition StdMathLib.h:99