#include "zim-sys/zim-bind.h" #include "zim-sys/src/binding.rs.h" using namespace zim; #include "rust/cxx.h" using rust::Str; #include using std::make_unique; using std::unique_ptr; #include using std::string; // FILE: archive.h unique_ptr archive_ctor_file(rust::Str path) { try { return make_unique(string(path)); } catch (...) { return NULL; } } const string &archive_getFilename(const Archive &archive) { return archive.getFilename(); } size_type archive_getFilesize(const Archive &archive) { return archive.getFilesize(); } entry_index_type archive_getAllEntryCount(const Archive &archive) { return archive.getAllEntryCount(); } entry_index_type archive_getEntryCount(const Archive &archive) { return archive.getEntryCount(); } entry_index_type archive_getArticleCount(const Archive &archive) { return archive.getArticleCount(); } unique_ptr archive_getUuid(const Archive &archive) { try { return make_unique(archive.getUuid()); } catch (...) { return NULL; } } unique_ptr archive_getMetadata(const Archive &archive, rust::Str name) { try { return make_unique(archive.getMetadata(string(name))); } catch (...) { return NULL; } } unique_ptr archive_getMetadataItem(const Archive &archive, rust::Str name) { try { return make_unique(archive.getMetadataItem(string(name))); } catch (...) { return NULL; } } unique_ptr> archive_getMetadataKeys(const Archive &archive) { try { return make_unique>(archive.getMetadataKeys()); } catch (...) { return NULL; } } // Item archive_getIllustrationItem(const Archive &archive, unsigned int size = 48); // vector archive_getIllustrationSizes(const Archive &archive); // std::set probably has no bridge to rust unique_ptr archive_getEntryByPath_idx(const Archive &archive, entry_index_type idx) { try { return make_unique(archive.getEntryByPath(idx)); } catch (...) { return NULL; } } unique_ptr archive_getEntryByPath_str(const Archive &archive, rust::Str path) { try { return make_unique(archive.getEntryByPath(string(path))); } catch (...) { return NULL; } } unique_ptr archive_getEntryByTitle_idx(const Archive &archive, entry_index_type idx) { try { return make_unique(archive.getEntryByTitle(idx)); } catch (...) { return NULL; } } unique_ptr archive_getEntryByTitle_str(const Archive &archive, rust::Str title) { try { return make_unique(archive.getEntryByTitle(string(title))); } catch (...) { return NULL; } } unique_ptr archive_getEntryByClusterOrder(const Archive &archive, entry_index_type idx) { try { return make_unique(archive.getEntryByClusterOrder(idx)); } catch (...) { return NULL; } } unique_ptr archive_getMainEntry(const Archive &archive) { try { return make_unique(archive.getMainEntry()); } catch (...) { return NULL; } } unique_ptr archive_getRandomEntry(const Archive &archive) { try { return make_unique(archive.getRandomEntry()); } catch (...) { return NULL; } } bool archive_hasEntryByPath(const Archive &archive, rust::Str path) { return archive.hasEntryByPath(string(path)); } bool archive_hasEntryByTitle(const Archive &archive, rust::Str title) { return archive.hasEntryByTitle(string(title)); } bool archive_hasMainEntry(const Archive &archive) { return archive.hasMainEntry(); } // bool archive_hasIllustration(const Archive &archive, unsigned int size = 48); bool archive_hasFulltextIndex(const Archive &archive) { return archive.hasFulltextIndex(); } bool archive_hasTitleIndex(const Archive &archive) { return archive.hasTitleIndex(); } // EntryRange functions bool archive_hasChecksum(const Archive &archive) { return archive.hasChecksum(); } unique_ptr archive_getChecksum(const Archive &archive) { return make_unique(archive.getChecksum()); } bool archive_check(const Archive &archive) { return archive.check(); } // bool archive_checkIntegrity(const Archive &archive, IntegrityCheck checkType); bool archive_isMultiPart(const Archive &archive) { return archive.isMultiPart(); } bool archive_hasNewNamespaceScheme(const Archive &archive) { return archive.hasNewNamespaceScheme(); } unique_ptr archive_iterEfficient(const Archive& archive) { return make_unique(archive.iterEfficient()); } unique_ptr entryrangeefficient_begin(const EntryRangeEfficient& range) { return make_unique(range.inner.begin()); } unique_ptr entryrangeefficient_end(const EntryRangeEfficient& range){ return make_unique(range.inner.end()); } bool iterefficient_eq(const IterEfficient& iter, const IterEfficient& other) { return iter.inner.operator==(other.inner); } unique_ptr iterefficient_star(const IterEfficient& iter) { try { return make_unique(iter.inner.operator*()); } catch (...) { return NULL; } } void iterefficient_inc(IterEfficient& iter) { iter.inner.operator++(); } // FILE: blob.h unique_ptr blob_ctor() { return make_unique(); } const char *blob_data(const Blob &blob) { return blob.data(); } size_type blob_size(const Blob &blob) { return blob.size(); } // FILE: entry.h bool entry_isRedirect(const Entry &entry) { return entry.isRedirect(); } unique_ptr entry_getTitle(const Entry &entry) { return make_unique(entry.getTitle()); } unique_ptr entry_getPath(const Entry &entry) { return make_unique(entry.getPath()); } unique_ptr entry_getItem(const Entry &entry, bool follow) { try { return make_unique(entry.getItem(follow)); } catch (...) { return NULL; } } unique_ptr entry_getRedirect(const Entry &entry) { try { return make_unique(entry.getRedirect()); } catch (...) { return NULL; } } unique_ptr entry_getRedirectEntry(const Entry &entry) { try { return make_unique(entry.getRedirectEntry()); } catch (...) { return NULL; } } /* entry_index_type entry_getRedirectEntryIndex(const Entry &entry) { try { return entry.getRedirectEntryIndex(); } catch (...) { // TODO: fix this with appropriate error handling return 0; } } */ entry_index_type entry_getIndex(const Entry &entry) { return entry.getIndex(); } // FILE: item.h unique_ptr item_getTitle(const Item &item) { return make_unique(item.getTitle()); } unique_ptr item_getPath(const Item &item) { return make_unique(item.getPath()); } unique_ptr item_getMimetype(const Item &item) { try { // can throw in FileImpl::getMimeType return make_unique(item.getMimetype()); } catch (...) { return NULL; } } unique_ptr item_getData(const Item &item) { try { return make_unique(item.getData()); } catch (...) { return NULL; } } unique_ptr item_getData_offset(const Item &item, offset_type offset, size_type size) { try { return make_unique(item.getData(offset, size)); } catch (...) { return NULL; } } size_type item_getSize(const Item &item) { return item.getSize(); } unique_ptr item_getDirectAccess(const Item &item) { try { return make_unique(item.getDirectAccessInformation()); } catch (...) { return NULL; } } entry_index_type item_getIndex(const Item &item) { return item.getIndex(); } unique_ptr directAccess_getPath(const DirectAccess & dAccess) { return make_unique(dAccess.inner.first); } offset_type directAccess_getOffset(const DirectAccess & dAccess) { return dAccess.inner.second; } // FILE: search.h unique_ptr searcher_ctor(const Archive &archive) { return make_unique(archive); } void searcher_addArchive(Searcher &searcher, const Archive &archive) { searcher.addArchive(archive); } unique_ptr searcher_search(Searcher &searcher, const Query &query) { try { return make_unique(searcher.search(query)); } catch (...) { return NULL; } } void searcher_setVerbose(Searcher &searcher, bool verbose) { searcher.setVerbose(verbose); } unique_ptr query_ctor(rust::Str query) { return make_unique(string(query)); } void query_setQuery(Query &query, rust::Str query_str) { query.setQuery(string(query_str)); } void query_setGeorange(Query &query, float latitude, float longitude, float distance) { query.setGeorange(latitude, longitude, distance); } unique_ptr search_getResults(const Search &search, int start, int maxResults) { return make_unique(search.getResults(start, maxResults)); } int search_getEstimatedMatches(const Search &search) { return search.getEstimatedMatches(); } unique_ptr searchresultset_begin(const SearchResultSet &searchresultset) { return make_unique(searchresultset.begin()); } unique_ptr searchresultset_end(const SearchResultSet &searchresultset) { return make_unique(searchresultset.end()); } int searchresultset_size(const SearchResultSet &searchresultset) { return searchresultset.size(); } // FILE: search_iterator.h bool searchiterator_operator_eq(const SearchIterator &searchiterator, const SearchIterator &o) { return searchiterator.operator==(o); } bool searchiterator_operator_neq(const SearchIterator &searchiterator, const SearchIterator &o) { return searchiterator.operator!=(o); } void searchiterator_operator_inc(SearchIterator &searchiterator) { searchiterator.operator++(); } unique_ptr searchiterator_operator_star(const SearchIterator &searchiterator) { try { return make_unique(searchiterator.operator*()); } catch (...) { return NULL; } } // FILE: suggestion.h unique_ptr suggestionsearcher_ctor(const Archive &archive) { return make_unique(archive); } unique_ptr suggestionsearcher_suggest(SuggestionSearcher &suggestionsearcher, rust::Str query) { try { return make_unique(suggestionsearcher.suggest(string(query))); } catch (...) { return NULL; } } void suggestionsearcher_setVerbose(SuggestionSearcher &suggestionsearcher, bool verbose) { suggestionsearcher.setVerbose(verbose); } unique_ptr suggestionsearch_getResults(const SuggestionSearch &suggestionsearch, int start, int maxResults) { return make_unique(suggestionsearch.getResults(start, maxResults)); } int suggestionsearch_getEstimatedMatches(const SuggestionSearch &suggestionsearch) { return suggestionsearch.getEstimatedMatches(); } unique_ptr suggestionresultset_begin(const SuggestionResultSet &suggestionresultset) { return make_unique(suggestionresultset.begin()); } unique_ptr suggestionresultset_end(const SuggestionResultSet &suggestionresultset) { return make_unique(suggestionresultset.end()); } int suggestionresultset_size(const SuggestionResultSet &suggestionresultset) { return suggestionresultset.size(); } // FILE: suggestion_iterator.h bool suggestioniterator_operator_eq(const SuggestionIterator &suggestioniterator, const SuggestionIterator &o) { return suggestioniterator.operator==(o); } bool suggestioniterator_operator_neq(const SuggestionIterator &suggestioniterator, const SuggestionIterator &o) { return suggestioniterator.operator!=(o); } void suggestioniterator_operator_inc(SuggestionIterator &suggestioniterator) { suggestioniterator.operator++(); } unique_ptr suggestioniterator_operator_star(SuggestionIterator &suggestioniterator) { try { return make_unique(suggestioniterator.operator*()); } catch (...) { return NULL; } } unique_ptr suggestioniterator_getEntry(const SuggestionIterator &suggestioniterator) { try { return make_unique(suggestioniterator.getEntry()); } catch (...) { return NULL; } } unique_ptr suggestionitem_getTitle(const SuggestionItem &suggestionitem) { return make_unique(suggestionitem.getTitle()); } unique_ptr suggestionitem_getPath(const SuggestionItem &suggestionitem) { return make_unique(suggestionitem.getPath()); } unique_ptr suggestionitem_getSnippet(const SuggestionItem &suggestionitem) { return make_unique(suggestionitem.getSnippet()); } bool suggestionitem_hasSnippet(const SuggestionItem &suggestionitem) { return suggestionitem.hasSnippet(); } // FILE: uuid.h unique_ptr uuid_ctor() { try { return make_unique(); } catch (...) { return NULL; } } unique_ptr uuid_ctor_str(rust::Str uuid) { if (uuid.size() != 16) { return NULL; } try { string s = string(uuid); const char *cs = s.c_str(); return make_unique(cs); } catch (...) { return NULL; } } unique_ptr uuid_generate(rust::Str value) { try { return make_unique(Uuid::generate(string(value))); } catch (...) { return NULL; } } bool uuid_operator_eq(const Uuid &uuid, const Uuid &o) { return uuid.operator==(o); } unique_ptr uuid_std_string(const Uuid &uuid) { try { string s = static_cast(uuid); return make_unique(s); } catch (...) { return NULL; } }