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