xref: /third_party/lzma/CPP/7zip/Archive/7z/7zItem.h (revision 370b324c)
1// 7zItem.h
2
3#ifndef ZIP7_INC_7Z_ITEM_H
4#define ZIP7_INC_7Z_ITEM_H
5
6#include "../../../Common/MyBuffer.h"
7#include "../../../Common/MyString.h"
8
9#include "../../Common/MethodId.h"
10
11#include "7zHeader.h"
12
13namespace NArchive {
14namespace N7z {
15
16typedef UInt32 CNum;
17const CNum kNumMax     = 0x7FFFFFFF;
18const CNum kNumNoIndex = 0xFFFFFFFF;
19
20struct CCoderInfo
21{
22  CMethodId MethodID;
23  CByteBuffer Props;
24  UInt32 NumStreams;
25
26  bool IsSimpleCoder() const { return NumStreams == 1; }
27};
28
29
30struct CBond
31{
32  UInt32 PackIndex;
33  UInt32 UnpackIndex;
34};
35
36
37struct CFolder
38{
39  Z7_CLASS_NO_COPY(CFolder)
40public:
41  CObjArray2<CCoderInfo> Coders;
42  CObjArray2<CBond> Bonds;
43  CObjArray2<UInt32> PackStreams;
44
45  CFolder() {}
46
47  bool IsDecodingSupported() const { return Coders.Size() <= 32; }
48
49  int Find_in_PackStreams(UInt32 packStream) const
50  {
51    FOR_VECTOR(i, PackStreams)
52      if (PackStreams[i] == packStream)
53        return (int)i;
54    return -1;
55  }
56
57  int FindBond_for_PackStream(UInt32 packStream) const
58  {
59    FOR_VECTOR(i, Bonds)
60      if (Bonds[i].PackIndex == packStream)
61        return (int)i;
62    return -1;
63  }
64
65  /*
66  int FindBond_for_UnpackStream(UInt32 unpackStream) const
67  {
68    FOR_VECTOR(i, Bonds)
69      if (Bonds[i].UnpackIndex == unpackStream)
70        return i;
71    return -1;
72  }
73
74  int FindOutCoder() const
75  {
76    for (int i = (int)Coders.Size() - 1; i >= 0; i--)
77      if (FindBond_for_UnpackStream(i) < 0)
78        return i;
79    return -1;
80  }
81  */
82
83  bool IsEncrypted() const
84  {
85    FOR_VECTOR(i, Coders)
86      if (Coders[i].MethodID == k_AES)
87        return true;
88    return false;
89  }
90};
91
92
93struct CUInt32DefVector
94{
95  CBoolVector Defs;
96  CRecordVector<UInt32> Vals;
97
98  void ClearAndSetSize(unsigned newSize)
99  {
100    Defs.ClearAndSetSize(newSize);
101    Vals.ClearAndSetSize(newSize);
102  }
103
104  void Clear()
105  {
106    Defs.Clear();
107    Vals.Clear();
108  }
109
110  void ReserveDown()
111  {
112    Defs.ReserveDown();
113    Vals.ReserveDown();
114  }
115
116  bool GetItem(unsigned index, UInt32 &value) const
117  {
118    if (index < Defs.Size() && Defs[index])
119    {
120      value = Vals[index];
121      return true;
122    }
123    value = 0;
124    return false;
125  }
126
127  bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; }
128
129  bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
130
131  void SetItem(unsigned index, bool defined, UInt32 value);
132  void if_NonEmpty_FillResedue_with_false(unsigned numItems)
133  {
134    if (Defs.Size() != 0 && Defs.Size() < numItems)
135      SetItem(numItems - 1, false, 0);
136  }
137};
138
139
140struct CUInt64DefVector
141{
142  CBoolVector Defs;
143  CRecordVector<UInt64> Vals;
144
145  void Clear()
146  {
147    Defs.Clear();
148    Vals.Clear();
149  }
150
151  void ReserveDown()
152  {
153    Defs.ReserveDown();
154    Vals.ReserveDown();
155  }
156
157  bool GetItem(unsigned index, UInt64 &value) const
158  {
159    if (index < Defs.Size() && Defs[index])
160    {
161      value = Vals[index];
162      return true;
163    }
164    value = 0;
165    return false;
166  }
167
168  bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
169
170  void SetItem(unsigned index, bool defined, UInt64 value);
171};
172
173
174struct CFileItem
175{
176  UInt64 Size;
177  UInt32 Crc;
178  /*
179  int Parent;
180  bool IsAltStream;
181  */
182  bool HasStream; // Test it !!! it means that there is
183                  // stream in some folder. It can be empty stream
184  bool IsDir;
185  bool CrcDefined;
186
187  /*
188  void Clear()
189  {
190    HasStream = true;
191    IsDir = false;
192    CrcDefined = false;
193  }
194
195  CFileItem():
196    // Parent(-1),
197    // IsAltStream(false),
198    HasStream(true),
199    IsDir(false),
200    CrcDefined(false),
201      {}
202  */
203};
204
205}}
206
207#endif
208