LCOV - code coverage report
Current view: top level - include/xapian - expanddecider.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 13 13 100.0 %
Date: 2019-06-30 05:20:33 Functions: 8 8 100.0 %
Branches: 7 14 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file expanddecider.h
       2                 :            :  * @brief Allow rejection of terms during ESet generation.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2011,2013,2014,2015,2016 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_EXPANDDECIDER_H
      22                 :            : #define XAPIAN_INCLUDED_EXPANDDECIDER_H
      23                 :            : 
      24                 :            : #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
      25                 :            : # error "Never use <xapian/expanddecider.h> directly; include <xapian.h> instead."
      26                 :            : #endif
      27                 :            : 
      28                 :            : #include <set>
      29                 :            : #include <string>
      30                 :            : 
      31                 :            : #include <xapian/intrusive_ptr.h>
      32                 :            : #include <xapian/visibility.h>
      33                 :            : 
      34                 :            : namespace Xapian {
      35                 :            : 
      36                 :            : /** Virtual base class for expand decider functor. */
      37                 :            : class XAPIAN_VISIBILITY_DEFAULT ExpandDecider
      38                 :            :     : public Xapian::Internal::opt_intrusive_base {
      39                 :            :     /// Don't allow assignment.
      40                 :            :     void operator=(const ExpandDecider &) = delete;
      41                 :            : 
      42                 :            :     /// Don't allow copying.
      43                 :            :     ExpandDecider(const ExpandDecider &) = delete;
      44                 :            : 
      45                 :            :   public:
      46                 :            :     /// Default constructor.
      47                 :        464 :     ExpandDecider() { }
      48                 :            : 
      49                 :            :     /** Do we want this term in the ESet?
      50                 :            :      *
      51                 :            :      *  @param term     The term to test.
      52                 :            :      */
      53                 :            :     virtual bool operator()(const std::string &term) const = 0;
      54                 :            : 
      55                 :            :     /** Virtual destructor, because we have virtual methods. */
      56                 :            :     virtual ~ExpandDecider();
      57                 :            : 
      58                 :            :     /** Start reference counting this object.
      59                 :            :      *
      60                 :            :      *  You can hand ownership of a dynamically allocated ExpandDecider
      61                 :            :      *  object to Xapian by calling release() and then passing the object to a
      62                 :            :      *  Xapian method.  Xapian will arrange to delete the object once it is no
      63                 :            :      *  longer required.
      64                 :            :      */
      65                 :        189 :     ExpandDecider * release() {
      66                 :        189 :         opt_intrusive_base::release();
      67                 :        189 :         return this;
      68                 :            :     }
      69                 :            : 
      70                 :            :     /** Start reference counting this object.
      71                 :            :      *
      72                 :            :      *  You can hand ownership of a dynamically allocated ExpandDecider
      73                 :            :      *  object to Xapian by calling release() and then passing the object to a
      74                 :            :      *  Xapian method.  Xapian will arrange to delete the object once it is no
      75                 :            :      *  longer required.
      76                 :            :      */
      77                 :            :     const ExpandDecider * release() const {
      78                 :            :         opt_intrusive_base::release();
      79                 :            :         return this;
      80                 :            :     }
      81                 :            : };
      82                 :            : 
      83                 :            : /** ExpandDecider subclass which rejects terms using two ExpandDeciders.
      84                 :            :  *
      85                 :            :  *  Terms are only accepted if they are accepted by both of the specified
      86                 :            :  *  ExpandDecider objects.
      87                 :            :  */
      88         [ -  + ]:        112 : class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderAnd : public ExpandDecider {
      89                 :            :     Internal::opt_intrusive_ptr<const ExpandDecider> first, second;
      90                 :            : 
      91                 :            :   public:
      92                 :            :     /** Terms will be checked with @a first, and if accepted, then checked
      93                 :            :      *  with @a second.
      94                 :            :      *
      95                 :            :      *  @param first_   First ExpandDecider object to test with.
      96                 :            :      *  @param second_  ExpandDecider object to test with if first_ accepts.
      97                 :            :      */
      98                 :            :     ExpandDeciderAnd(const ExpandDecider &first_,
      99                 :            :                      const ExpandDecider &second_)
     100                 :            :         : first(&first_), second(&second_) { }
     101                 :            : 
     102                 :            :     /** Compatibility method.
     103                 :            :      *
     104                 :            :      *  @param first_   First ExpandDecider object to test with.
     105                 :            :      *  @param second_  ExpandDecider object to test with if first_ accepts.
     106                 :            :      */
     107                 :         28 :     ExpandDeciderAnd(const ExpandDecider *first_,
     108                 :            :                      const ExpandDecider *second_)
     109                 :         28 :         : first(first_), second(second_) { }
     110                 :            : 
     111                 :            :     virtual bool operator()(const std::string &term) const;
     112                 :            : };
     113                 :            : 
     114                 :            : /** ExpandDecider subclass which rejects terms in a specified list.
     115                 :            :  *
     116                 :            :  *  ExpandDeciderFilterTerms provides an easy way to filter out terms from
     117                 :            :  *  a fixed list when generating an ESet.
     118                 :            :  */
     119         [ -  + ]:        420 : class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderFilterTerms : public ExpandDecider {
     120                 :            :     std::set<std::string> rejects;
     121                 :            : 
     122                 :            :   public:
     123                 :            :     /** The two iterators specify a list of terms to be rejected.
     124                 :            :      *
     125                 :            :      *  @param reject_begin     Begin iterator for the list of terms to
     126                 :            :      *                          reject.  It can be any input_iterator type
     127                 :            :      *                          which returns std::string or char * (e.g.
     128                 :            :      *                          TermIterator or char **).
     129                 :            :      *  @param reject_end       End iterator for the list of terms to reject.
     130                 :            :      */
     131                 :            :     template<class Iterator>
     132                 :        105 :     ExpandDeciderFilterTerms(Iterator reject_begin, Iterator reject_end)
     133 [ +  - ][ +  - ]:        105 :         : rejects(reject_begin, reject_end) { }
                 [ +  - ]
     134                 :            : 
     135                 :            :     virtual bool operator()(const std::string &term) const;
     136                 :            : };
     137                 :            : 
     138                 :            : /** ExpandDecider subclass which restrict terms to a particular prefix
     139                 :            :  *
     140                 :            :  *  ExpandDeciderFilterPrefix provides an easy way to choose terms with a
     141                 :            :  *  particular prefix when generating an ESet.
     142                 :            :  */
     143         [ -  + ]:         16 : class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderFilterPrefix : public ExpandDecider {
     144                 :            :     std::string prefix;
     145                 :            : 
     146                 :            :   public:
     147                 :            :     /** The parameter specify the prefix of terms to be retained
     148                 :            :      *  @param prefix_   restrict terms to the particular prefix_
     149                 :            :      */
     150                 :          8 :     explicit ExpandDeciderFilterPrefix(const std::string &prefix_)
     151         [ +  - ]:          8 :         : prefix(prefix_) { }
     152                 :            : 
     153                 :            :     virtual bool operator() (const std::string &term) const;
     154                 :            : };
     155                 :            : 
     156                 :            : }
     157                 :            : 
     158                 :            : #endif // XAPIAN_INCLUDED_EXPANDDECIDER_H

Generated by: LCOV version 1.11