/src/alembic/lib/Alembic/Ogawa/IData.cpp
Line | Count | Source (jump to first uncovered line) |
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 <Alembic/Ogawa/Foundation.h> |
37 | | #include <Alembic/Ogawa/IGroup.h> |
38 | | #include <Alembic/Ogawa/IData.h> |
39 | | #include <Alembic/Ogawa/IStreams.h> |
40 | | |
41 | | namespace Alembic { |
42 | | namespace Ogawa { |
43 | | namespace ALEMBIC_VERSION_NS { |
44 | | |
45 | | class IData::PrivateData |
46 | | { |
47 | | public: |
48 | | PrivateData(IStreamsPtr iStreams) |
49 | 984 | { |
50 | 984 | streams = iStreams; |
51 | 984 | }; |
52 | | |
53 | 984 | ~PrivateData() {}; |
54 | | |
55 | | IStreamsPtr streams; |
56 | | |
57 | | // set after freeze |
58 | | Alembic::Util::uint64_t pos; |
59 | | Alembic::Util::uint64_t size; |
60 | | }; |
61 | | |
62 | | IData::~IData() |
63 | 956 | { |
64 | | |
65 | 956 | } |
66 | | |
67 | | IData::IData(IStreamsPtr iStreams, |
68 | | Alembic::Util::uint64_t iPos, |
69 | | std::size_t iThreadId) : |
70 | 984 | mData(new IData::PrivateData(iStreams)) |
71 | 984 | { |
72 | 984 | mData->size = 0; |
73 | | |
74 | | // strip off the top bit (indicates data) to get our seek position |
75 | 984 | mData->pos = iPos & INVALID_GROUP; |
76 | | |
77 | 984 | Alembic::Util::uint64_t size = 0; |
78 | | |
79 | | // not the empty group? then figure out our size |
80 | 984 | if ( mData->pos != 0 ) |
81 | 936 | { |
82 | 936 | mData->streams->read(iThreadId, mData->pos, 8, &size); |
83 | 936 | if (mData->streams->getSize() < size) |
84 | 7 | { |
85 | 7 | throw std::runtime_error("Ogawa IData illegal size."); |
86 | 7 | } |
87 | 929 | else |
88 | 929 | { |
89 | 929 | mData->size = size; |
90 | 929 | } |
91 | 936 | } |
92 | 984 | } |
93 | | |
94 | | void IData::read(Alembic::Util::uint64_t iSize, void * iData, |
95 | | Alembic::Util::uint64_t iOffset, std::size_t iThreadId) |
96 | 796 | { |
97 | | // don't read anything if we will read beyond our buffer |
98 | 796 | if (iSize == 0 || mData->size == 0 || iOffset + iSize > mData->size) |
99 | 0 | { |
100 | 0 | return; |
101 | 0 | } |
102 | | |
103 | | // +8 is to account for the size |
104 | 796 | mData->streams->read(iThreadId, mData->pos + iOffset + 8, iSize, iData); |
105 | 796 | } |
106 | | |
107 | | Alembic::Util::uint64_t IData::getSize() const |
108 | 1.63k | { |
109 | 1.63k | return mData->size; |
110 | 1.63k | } |
111 | | |
112 | | Alembic::Util::uint64_t IData::getPos() const |
113 | 0 | { |
114 | 0 | return mData->pos; |
115 | 0 | } |
116 | | |
117 | | } // End namespace ALEMBIC_VERSION_NS |
118 | | } // End namespace Ogawa |
119 | | } // End namespace Alembic |