Skip to content

Commit 3dd1a5b

Browse files
mgautierfrkelson42
authored andcommitted
Do not use a static value for default value for openConfig
On Windows, static member are not exported in dlls. So we don't have a value to use as default for openConfig.
1 parent 9391f33 commit 3dd1a5b

File tree

2 files changed

+98
-10
lines changed

2 files changed

+98
-10
lines changed

include/zim/archive.h

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,19 @@ namespace zim
148148
public:
149149
template<EntryOrder order> class EntryRange;
150150
template<EntryOrder order> class iterator;
151-
static const OpenConfig DEFAULT_OPEN_CONFIG;
151+
152+
/** Archive constructor.
153+
*
154+
* Construct an archive from a filename.
155+
* The file is open readonly.
156+
*
157+
* The filename is the "logical" path.
158+
* So if you want to open a split zim file (foo.zimaa, foo.zimab, ...)
159+
* you must pass the `foo.zim` path.
160+
*
161+
* @param fname The filename to the file to open (utf8 encoded)
162+
*/
163+
explicit Archive(const std::string& fname);
152164

153165
/** Archive constructor.
154166
*
@@ -162,9 +174,21 @@ namespace zim
162174
* @param fname The filename to the file to open (utf8 encoded)
163175
* @param openConfig The open configuration to use.
164176
*/
165-
Archive(const std::string& fname, OpenConfig openConfig=DEFAULT_OPEN_CONFIG);
177+
Archive(const std::string& fname, OpenConfig openConfig);
166178

167179
#ifndef _WIN32
180+
/** Archive constructor.
181+
*
182+
* Construct an archive from a file descriptor.
183+
* Fd is used only at Archive creation.
184+
* Ownership of the fd is not taken and it must be closed by caller.
185+
*
186+
* Note: This function is not available under Windows.
187+
*
188+
* @param fd The descriptor of a seekable file representing a ZIM archive
189+
*/
190+
explicit Archive(int fd);
191+
168192
/** Archive constructor.
169193
*
170194
* Construct an archive from a file descriptor.
@@ -176,7 +200,24 @@ namespace zim
176200
* @param fd The descriptor of a seekable file representing a ZIM archive
177201
* @param openConfig The open configuration to use.
178202
*/
179-
Archive(int fd, OpenConfig openConfig=DEFAULT_OPEN_CONFIG);
203+
Archive(int fd, OpenConfig openConfig);
204+
205+
/** Archive constructor.
206+
*
207+
* Construct an archive from a descriptor of a file with an embedded ZIM
208+
* archive inside.
209+
* Fd is used only at Archive creation.
210+
* Ownership of the fd is not taken and it must be closed by caller.
211+
*
212+
* Note: This function is not available under Windows.
213+
*
214+
* @param fd The descriptor of a seekable file with a continuous segment
215+
* representing a complete ZIM archive.
216+
* @param offset The offset of the ZIM archive relative to the beginning
217+
* of the file (rather than the current position associated with fd).
218+
* @param size The size of the ZIM archive.
219+
*/
220+
Archive(int fd, offset_type offset, size_type size);
180221

181222
/** Archive constructor.
182223
*
@@ -194,7 +235,21 @@ namespace zim
194235
* @param size The size of the ZIM archive.
195236
* @param openConfig The open configuration to use.
196237
*/
197-
Archive(int fd, offset_type offset, size_type size, OpenConfig openConfig=DEFAULT_OPEN_CONFIG);
238+
Archive(int fd, offset_type offset, size_type size, OpenConfig openConfig);
239+
240+
/** Archive constructor.
241+
*
242+
* Construct an archive from a descriptor of a file with an embedded ZIM
243+
* archive inside.
244+
* Fd is used only at Archive creation.
245+
* Ownership of the fd is not taken and it must be closed by caller.
246+
*
247+
* Note: This function is not available under Windows.
248+
*
249+
* @param fd A FdInput (tuple) containing the fd (int), offset (offset_type) and size (size_type)
250+
* referencing a continuous segment representing a complete ZIM archive.
251+
*/
252+
explicit Archive(FdInput fd);
198253

199254
/** Archive constructor.
200255
*
@@ -209,7 +264,22 @@ namespace zim
209264
* referencing a continuous segment representing a complete ZIM archive.
210265
* @param openConfig The open configuration to use.
211266
*/
212-
Archive(FdInput fd, OpenConfig openConfig=DEFAULT_OPEN_CONFIG);
267+
Archive(FdInput fd, OpenConfig openConfig);
268+
269+
/** Archive constructor.
270+
*
271+
* Construct an archive from several file descriptors.
272+
* Each part may be embedded in a file.
273+
* Fds are used only at Archive creation.
274+
* Ownership of the fds is not taken and they must be closed by caller.
275+
* Fds (int) can be the same between FdInput if the parts belong to the same file.
276+
*
277+
* Note: This function is not available under Windows.
278+
*
279+
* @param fds A vector of FdInput (tuple) containing the fd (int), offset (offset_type) and size (size_type)
280+
* referencing a series of segments representing a complete ZIM archive.
281+
*/
282+
explicit Archive(const std::vector<FdInput>& fds);
213283

214284
/** Archive constructor.
215285
*
@@ -225,7 +295,7 @@ namespace zim
225295
* referencing a series of segments representing a complete ZIM archive.
226296
* @param openConfig The open configuration to use.
227297
*/
228-
Archive(const std::vector<FdInput>& fds, OpenConfig openConfig=DEFAULT_OPEN_CONFIG);
298+
Archive(const std::vector<FdInput>& fds, OpenConfig openConfig);
229299
#endif
230300

231301
/** Return the filename of the zim file.

src/archive.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,49 @@ log_define("zim.archive")
3333

3434
namespace zim
3535
{
36-
const OpenConfig Archive::DEFAULT_OPEN_CONFIG;
37-
3836
OpenConfig::OpenConfig()
39-
:
37+
:
4038
m_preloadXapianDb(true),
4139
m_preloadDirentRanges(DIRENT_LOOKUP_CACHE_SIZE)
4240
{ }
4341

42+
Archive::Archive(const std::string& fname)
43+
: Archive(fname, OpenConfig())
44+
{ }
45+
4446
Archive::Archive(const std::string& fname, OpenConfig openConfig)
4547
: m_impl(new FileImpl(fname, openConfig))
4648
{ }
4749

4850
#ifndef _WIN32
51+
Archive::Archive(int fd)
52+
: Archive(fd, OpenConfig())
53+
{ }
54+
4955
Archive::Archive(int fd, OpenConfig openConfig)
5056
: m_impl(new FileImpl(fd, openConfig))
5157
{ }
5258

59+
Archive::Archive(FdInput fd)
60+
: Archive(fd, OpenConfig())
61+
{ }
62+
5363
Archive::Archive(FdInput fd, OpenConfig openConfig)
5464
: m_impl(new FileImpl(fd, openConfig))
55-
{}
65+
{ }
66+
67+
Archive::Archive(int fd, offset_type offset, size_type size)
68+
: Archive(FdInput(fd, offset, size), OpenConfig())
69+
{ }
5670

5771
Archive::Archive(int fd, offset_type offset, size_type size, OpenConfig openConfig)
5872
: Archive(FdInput(fd, offset, size), openConfig)
5973
{ }
6074

75+
Archive::Archive(const std::vector<FdInput>& fds)
76+
: Archive(fds, OpenConfig())
77+
{ }
78+
6179
Archive::Archive(const std::vector<FdInput>& fds, OpenConfig openConfig)
6280
: m_impl(new FileImpl(fds, openConfig))
6381
{ }

0 commit comments

Comments
 (0)