forked from xNVSE/NVSE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISegmentStream.cpp
More file actions
76 lines (57 loc) · 1.66 KB
/
Copy pathISegmentStream.cpp
File metadata and controls
76 lines (57 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "common/ISegmentStream.h"
ISegmentStream::ISegmentStream()
{
streamLength = 0;
}
ISegmentStream::~ISegmentStream()
{
}
void ISegmentStream::AttachStream(IDataStream * inStream)
{
parent = inStream;
streamLength = 0;
streamOffset = 0;
}
void ISegmentStream::AddSegment(UInt64 offset, UInt64 length, UInt64 parentOffset)
{
segmentInfo.push_back(SegmentInfo(offset, length, parentOffset));
if(streamLength < (parentOffset + length))
streamLength = parentOffset + length;
}
void ISegmentStream::ReadBuf(void * buf, UInt32 inLength)
{
UInt32 remain = inLength;
UInt8 * out = (UInt8 *)buf;
while(remain > 0)
{
SegmentInfo * info = LookupInfo(streamOffset);
ASSERT(info);
UInt64 segmentOffset = streamOffset - info->offset;
UInt64 transferLength = info->length - segmentOffset;
if(transferLength > remain)
transferLength = remain;
parent->SetOffset(info->parentOffset + segmentOffset);
parent->ReadBuf(out, transferLength);
streamOffset += transferLength;
remain -= transferLength;
}
}
void ISegmentStream::WriteBuf(const void * buf, UInt32 inLength)
{
HALT("ISegmentStream::WriteBuf: writing unsupported");
}
void ISegmentStream::SetOffset(SInt64 inOffset)
{
SegmentInfo * info = LookupInfo(inOffset);
ASSERT(info);
UInt64 segmentOffset = inOffset - info->offset;
parent->SetOffset(info->parentOffset + segmentOffset);
streamOffset = inOffset;
}
ISegmentStream::SegmentInfo * ISegmentStream::LookupInfo(UInt64 offset)
{
for(SegmentInfoListType::iterator iter = segmentInfo.begin(); iter != segmentInfo.end(); iter++)
if((offset >= (*iter).offset) && (offset < (*iter).offset + (*iter).length))
return &(*iter);
return NULL;
}