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