Skip to content

Commit e040821

Browse files
committed
Better namespace for our object definition/wrapping.
- Move our wrapper object from WFoo to wrapper::Foo. The wrapper objects have the same name that the wrapped objects but in different namespace. - Move wrapper.pxd to zim.pxd Now, all cpp classes, whatever they come from libzim (zim namespace) or our wrapper (wrapper namespace), are now defined in "zim" python namespace (submodule). We can now access the cpp classes simply using their name, without carring if they are wrapped or not. - Class defined in `wrapper.pyx` are now in a separated namespace/module that the Cpp classes. They can now have the same name. So PyArchive/PyQuery is renamed to Archive/Query. - As classes are now in two different namespace, we must import zim module from `wrapper.pyx` (we didn't have to include wrapper at all before) And we must be explicit about the `zim.` module.
1 parent 15593f6 commit e040821

File tree

5 files changed

+128
-130
lines changed

5 files changed

+128
-130
lines changed

libzim/libwrapper.h

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,60 +90,60 @@ class Wrapper {
9090

9191
#define FORWARD(OUT, NAME) template<class... ARGS> OUT NAME(ARGS&&... args) const { return mp_base->NAME(std::forward<ARGS>(args)...); }
9292

93-
93+
namespace wrapper {
9494
// Wrapping blob is not necessary as we can default construct a zim::Blob.
9595
// But it is nice to have for consistancy.
96-
class WBlob : public Wrapper<zim::Blob>
96+
class Blob : public Wrapper<zim::Blob>
9797
{
9898
public:
99-
WBlob() = default;
100-
WBlob(const zim::Blob& o) : Wrapper(o) {}
101-
WBlob(const char* data, zim::size_type size) : Wrapper(zim::Blob(data, size)) {};
99+
Blob() = default;
100+
Blob(const zim::Blob& o) : Wrapper(o) {}
101+
Blob(const char* data, zim::size_type size) : Wrapper(zim::Blob(data, size)) {};
102102
operator zim::Blob() { return *mp_base; }
103103
FORWARD(const char*, data)
104104
FORWARD(const char*, end)
105105
FORWARD(zim::size_type, size)
106106
};
107107

108-
class WItem : public Wrapper<zim::Item>
108+
class Item : public Wrapper<zim::Item>
109109
{
110110
public:
111-
WItem() = default;
112-
WItem(const zim::Item& o) : Wrapper(o) {}
111+
Item() = default;
112+
Item(const zim::Item& o) : Wrapper(o) {}
113113
FORWARD(std::string, getTitle)
114114
FORWARD(std::string, getPath)
115115
FORWARD(std::string, getMimetype)
116-
FORWARD(WBlob, getData)
116+
FORWARD(wrapper::Blob, getData)
117117
FORWARD(zim::size_type, getSize)
118118
FORWARD(zim::entry_index_type, getIndex)
119119
};
120120

121-
class WEntry : public Wrapper<zim::Entry>
121+
class Entry : public Wrapper<zim::Entry>
122122
{
123123
public:
124-
WEntry() = default;
125-
WEntry(const zim::Entry& o) : Wrapper(o) {}
124+
Entry() = default;
125+
Entry(const zim::Entry& o) : Wrapper(o) {}
126126
FORWARD(std::string, getTitle)
127127
FORWARD(std::string, getPath)
128128
FORWARD(bool, isRedirect)
129-
FORWARD(WItem, getItem)
130-
FORWARD(WItem, getRedirect)
131-
FORWARD(WEntry, getRedirectEntry)
129+
FORWARD(wrapper::Item, getItem)
130+
FORWARD(wrapper::Item, getRedirect)
131+
FORWARD(wrapper::Entry, getRedirectEntry)
132132
FORWARD(zim::entry_index_type, getIndex)
133133
};
134134

135-
class WArchive : public Wrapper<zim::Archive>
135+
class Archive : public Wrapper<zim::Archive>
136136
{
137137
public:
138-
WArchive() = default;
139-
WArchive(const std::string& filename) : Wrapper(zim::Archive(filename)) {};
140-
WArchive(const zim::Archive& o) : Wrapper(o) {};
138+
Archive() = default;
139+
Archive(const std::string& filename) : Wrapper(zim::Archive(filename)) {};
140+
Archive(const zim::Archive& o) : Wrapper(o) {};
141141
zim::Archive& operator*() const { return *mp_base; }
142142

143-
FORWARD(WEntry, getEntryByPath)
144-
FORWARD(WEntry, getEntryByTitle)
145-
FORWARD(WEntry, getMainEntry)
146-
FORWARD(WItem, getIllustrationItem)
143+
FORWARD(wrapper::Entry, getEntryByPath)
144+
FORWARD(wrapper::Entry, getEntryByTitle)
145+
FORWARD(wrapper::Entry, getMainEntry)
146+
FORWARD(wrapper::Item, getIllustrationItem)
147147
std::string getUuid() const
148148
{ auto u = mp_base->getUuid();
149149
std::string uuids(u.data, u.size());
@@ -169,39 +169,39 @@ class WArchive : public Wrapper<zim::Archive>
169169
FORWARD(bool, check)
170170
};
171171

172-
class WSearchResultSet : public Wrapper<zim::SearchResultSet>
172+
class SearchResultSet : public Wrapper<zim::SearchResultSet>
173173
{
174174
public:
175-
WSearchResultSet() = default;
176-
WSearchResultSet(const zim::SearchResultSet& o) : Wrapper(o) {};
175+
SearchResultSet() = default;
176+
SearchResultSet(const zim::SearchResultSet& o) : Wrapper(o) {};
177177

178178

179179
FORWARD(zim::SearchIterator, begin)
180180
FORWARD(zim::SearchIterator, end)
181181
FORWARD(int, size)
182182
};
183183

184-
class WSearch : public Wrapper<zim::Search>
184+
class Search : public Wrapper<zim::Search>
185185
{
186186
public:
187-
WSearch() = default;
188-
WSearch(zim::Search&& s) : Wrapper(std::move(s)) {};
187+
Search() = default;
188+
Search(zim::Search&& s) : Wrapper(std::move(s)) {};
189189

190190
FORWARD(int, getEstimatedMatches)
191-
FORWARD(WSearchResultSet, getResults)
191+
FORWARD(wrapper::SearchResultSet, getResults)
192192
};
193193

194-
class WSearcher : public Wrapper<zim::Searcher>
194+
class Searcher : public Wrapper<zim::Searcher>
195195
{
196196
public:
197-
WSearcher() = default;
198-
WSearcher(const WArchive& a) : Wrapper(zim::Searcher(*a)) {};
199-
WSearcher(const zim::Searcher& o) : Wrapper(o) {};
197+
Searcher() = default;
198+
Searcher(const wrapper::Archive& a) : Wrapper(zim::Searcher(*a)) {};
199+
Searcher(const zim::Searcher& o) : Wrapper(o) {};
200200

201201
FORWARD(void, setVerbose)
202-
FORWARD(WSearch, search)
202+
FORWARD(wrapper::Search, search)
203203
};
204-
204+
} // namespace wrapper
205205
#undef FORWARD
206206

207207

libzim/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515
# flake8: noqa
16-
from .wrapper import PyArchive as Archive, Entry, Item
16+
from .wrapper import Archive, Entry, Item
1717

1818

1919
__all__ = ["Archive", "Entry", "Item"]

libzim/searcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515
# flake8: noqa
16-
from .wrapper import Searcher, PyQuery as Query
16+
from .wrapper import Searcher, Query
1717

1818

1919
__all__ = ["Searcher", "Query"]

0 commit comments

Comments
 (0)