1// MultiStream.h
2
3#ifndef __MULTI_STREAM_H
4#define __MULTI_STREAM_H
5
6#include "../../../Common/MyCom.h"
7#include "../../../Common/MyVector.h"
8
9#include "../../IStream.h"
10
11class CMultiStream:
12  public IInStream,
13  public CMyUnknownImp
14{
15  UInt64 _pos;
16  UInt64 _totalLength;
17  int _streamIndex;
18public:
19  struct CSubStreamInfo
20  {
21    CMyComPtr<IInStream> Stream;
22    UInt64 Size;
23    UInt64 GlobalOffset;
24    UInt64 LocalPos;
25  };
26  CObjectVector<CSubStreamInfo> Streams;
27
28  HRESULT Init()
29  {
30    UInt64 total = 0;
31    for (int i = 0; i < Streams.Size(); i++)
32    {
33      CSubStreamInfo &s = Streams[i];
34      s.GlobalOffset = total;
35      total += Streams[i].Size;
36      RINOK(s.Stream->Seek(0, STREAM_SEEK_CUR, &s.LocalPos));
37    }
38    _totalLength = total;
39    _pos = 0;
40    _streamIndex = 0;
41    return S_OK;
42  }
43
44  MY_UNKNOWN_IMP1(IInStream)
45
46  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
47  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
48};
49
50/*
51class COutMultiStream:
52  public IOutStream,
53  public CMyUnknownImp
54{
55  int _streamIndex; // required stream
56  UInt64 _offsetPos; // offset from start of _streamIndex index
57  UInt64 _absPos;
58  UInt64 _length;
59
60  struct CSubStreamInfo
61  {
62    CMyComPtr<ISequentialOutStream> Stream;
63    UInt64 Size;
64    UInt64 Pos;
65 };
66  CObjectVector<CSubStreamInfo> Streams;
67public:
68  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
69  void Init()
70  {
71    _streamIndex = 0;
72    _offsetPos = 0;
73    _absPos = 0;
74    _length = 0;
75  }
76
77  MY_UNKNOWN_IMP1(IOutStream)
78
79  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
80  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
81};
82*/
83
84#endif
85