1 /** @file const_database_wrapper.h 2 * @brief Wrapper which exposes only the const methods of database internals. 3 */ 4 /* Copyright (C) 2009 Lemur Consulting Ltd 5 * Copyright (C) 2009 Olly Betts 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 20 * USA 21 */ 22 23 #ifndef XAPIAN_INCLUDED_CONST_DATABASE_WRAPPER_H 24 #define XAPIAN_INCLUDED_CONST_DATABASE_WRAPPER_H 25 26 #include "xapian/base.h" 27 #include "database.h" 28 #include "noreturn.h" 29 30 using namespace std; 31 32 /** Base class for databases. 33 */ 34 class ConstDatabaseWrapper : public Xapian::Database::Internal { 35 /// Copies are not allowed. 36 ConstDatabaseWrapper(const ConstDatabaseWrapper &); 37 38 /// Assignment is not allowed. 39 void operator=(const ConstDatabaseWrapper &); 40 41 /// The const database which this wrapper wraps. 42 Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> realdb; 43 44 /// Raise an exception complaining about access to a non-const method. 45 XAPIAN_NORETURN(void nonconst_access() const); 46 47 public: 48 ConstDatabaseWrapper(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> realdb_); 49 50 // Const methods: these are proxied to realdb. 51 Xapian::doccount get_doccount() const; 52 Xapian::docid get_lastdocid() const; 53 totlen_t get_total_length() const; 54 Xapian::doclength get_avlength() const; 55 Xapian::termcount get_doclength(Xapian::docid did) const; 56 Xapian::doccount get_termfreq(const string & tname) const; 57 Xapian::termcount get_collection_freq(const string & tname) const; 58 Xapian::doccount get_value_freq(Xapian::valueno slot) const; 59 std::string get_value_lower_bound(Xapian::valueno slot) const; 60 std::string get_value_upper_bound(Xapian::valueno slot) const; 61 bool term_exists(const string & tname) const; 62 bool has_positions() const; 63 LeafPostList * open_post_list(const string & tname) const; 64 ValueList * open_value_list(Xapian::valueno slot) const; 65 TermList * open_term_list(Xapian::docid did) const; 66 TermList * open_allterms(const string & prefix) const; 67 PositionList * open_position_list(Xapian::docid did, 68 const string & tname) const; 69 Xapian::Document::Internal * 70 open_document(Xapian::docid did, bool lazy) const; 71 TermList * open_spelling_termlist(const string & word) const; 72 TermList * open_spelling_wordlist() const; 73 Xapian::doccount get_spelling_frequency(const string & word) const; 74 TermList * open_synonym_termlist(const string & term) const; 75 TermList * open_synonym_keylist(const string & prefix) const; 76 string get_metadata(const string & key) const; 77 TermList * open_metadata_keylist(const std::string &prefix) const; 78 void request_document(Xapian::docid did) const; 79 Xapian::Document::Internal * collect_document(Xapian::docid did) const; 80 string get_revision_info() const; 81 string get_uuid() const; 82 void invalidate_doc_object(Xapian::Document::Internal * obj) const; 83 84 // Non-const methods: these raise Xapian::InvalidOperationError 85 void add_spelling(const string & word, Xapian::termcount freqinc) const; 86 void remove_spelling(const string & word, Xapian::termcount freqdec) const; 87 void add_synonym(const string & term, const string & synonym) const; 88 void remove_synonym(const string & term, const string & synonym) const; 89 void clear_synonyms(const string & term) const; 90 void set_metadata(const string &, const string &); 91 void reopen(); 92 void close(); 93 void commit(); 94 void cancel(); 95 void begin_transaction(bool); 96 void commit_transaction(); 97 void cancel_transaction(); 98 Xapian::docid add_document(const Xapian::Document &); 99 void delete_document(Xapian::docid); 100 void delete_document(const string &); 101 void replace_document(Xapian::docid, const Xapian::Document &); 102 Xapian::docid replace_document(const string &, const Xapian::Document &); 103 void write_changesets_to_fd(int, const std::string &, bool, 104 Xapian::ReplicationInfo *); 105 RemoteDatabase * as_remotedatabase(); 106 }; 107 108 #endif /* XAPIAN_INCLUDED_CONST_DATABASE_WRAPPER_H */ 109