1 | /** @file registry.h |
2 | * @brief Class for looking up user subclasses during unserialisation. |
3 | */ |
4 | /* Copyright 2009 Lemur Consulting Ltd |
5 | * Copyright 2009,2011 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_REGISTRY_H |
24 | #define XAPIAN_INCLUDED_REGISTRY_H |
25 | |
26 | #include <xapian/base.h> |
27 | #include <xapian/visibility.h> |
28 | #include <string> |
29 | |
30 | namespace Xapian { |
31 | |
32 | // Forward declarations. |
33 | class MatchSpy; |
34 | class PostingSource; |
35 | class Weight; |
36 | |
37 | /** Registry for user subclasses. |
38 | * |
39 | * This class provides a way for the remote server to look up user subclasses |
40 | * when unserialising. |
41 | */ |
42 | class XAPIAN_VISIBILITY_DEFAULT Registry { |
43 | public: |
44 | /// Class holding details of the registry. |
45 | class Internal; |
46 | |
47 | private: |
48 | /// @internal Reference counted internals. |
49 | Xapian::Internal::RefCntPtr<Internal> internal; |
50 | |
51 | public: |
52 | /** Copy constructor. |
53 | * |
54 | * The internals are reference counted, so copying is cheap. |
55 | * |
56 | * @param other The object to copy. |
57 | */ |
58 | Registry(const Registry & other); |
59 | |
60 | /** Assignment operator. |
61 | * |
62 | * The internals are reference counted, so assignment is cheap. |
63 | * |
64 | * @param other The object to copy. |
65 | */ |
66 | Registry & operator=(const Registry & other); |
67 | |
68 | /** Default constructor. |
69 | * |
70 | * The registry will contain all standard subclasses of user-subclassable |
71 | * classes. |
72 | */ |
73 | Registry(); |
74 | |
75 | ~Registry(); |
76 | |
77 | /** Register a weighting scheme. |
78 | * |
79 | * @param wt The weighting scheme to register. |
80 | */ |
81 | void register_weighting_scheme(const Xapian::Weight &wt); |
82 | |
83 | /** Get the weighting scheme given a name. |
84 | * |
85 | * @param name The name of the weighting scheme to find. |
86 | * @return An object with the requested name, or NULL if the |
87 | * weighting scheme could not be found. The returned |
88 | * object is owned by the registry and so must not be |
89 | * deleted by the caller. |
90 | */ |
91 | const Xapian::Weight * |
92 | get_weighting_scheme(const std::string & name) const; |
93 | |
94 | /** Register a user-defined posting source class. |
95 | * |
96 | * @param source The posting source to register. |
97 | */ |
98 | void register_posting_source(const Xapian::PostingSource &source); |
99 | |
100 | /** Get a posting source given a name. |
101 | * |
102 | * @param name The name of the posting source to find. |
103 | * @return An object with the requested name, or NULL if the |
104 | * posting source could not be found. The returned |
105 | * object is owned by the registry and so must not be |
106 | * deleted by the caller. |
107 | */ |
108 | const Xapian::PostingSource * |
109 | get_posting_source(const std::string & name) const; |
110 | |
111 | /** Register a user-defined match spy class. |
112 | * |
113 | * @param spy The match spy to register. |
114 | */ |
115 | void register_match_spy(const Xapian::MatchSpy &spy); |
116 | |
117 | /** Get a match spy given a name. |
118 | * |
119 | * @param name The name of the match spy to find. |
120 | * @return An object with the requested name, or NULL if the |
121 | * match spy could not be found. The returned |
122 | * object is owned by the registry and so must not be |
123 | * deleted by the caller. |
124 | */ |
125 | const Xapian::MatchSpy * |
126 | get_match_spy(const std::string & name) const; |
127 | }; |
128 | |
129 | } |
130 | |
131 | #endif /* XAPIAN_INCLUDED_REGISTRY_H */ |
132 | |