"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/bibSearcher.h" (12 Feb 2021, 6633 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bibSearcher.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef BIBSEARCHER_H
    8 #define BIBSEARCHER_H
    9 
   10 #include "documentCache.h"
   11 #include "searchPattern.h"
   12 
   13 #include <QObject>
   14 #include <QStringList>
   15 
   16 
   17 class bibParser;
   18 class bibReference;
   19 
   20 
   21 class bibSearcher : public QObject
   22 {
   23 
   24     Q_OBJECT
   25 
   26 public:
   27     explicit bibSearcher(bibParser* bp, QObject* parento = 0);
   28     bibSearcher(bibParser* bp, const QString& bib_dir, QObject* parento = 0);
   29     inline ~bibSearcher() {}
   30 
   31     static QString searchDocumentKeyword(const QString& bibtexfn, const QString& documentfn, const QString& keyword);
   32 
   33     void addPattern(bool Not, bool caseSensitive, const QString& patternType, const QString& scope,
   34                     const QChar& yearScope, const QString& pattern);
   35     void clear();
   36     void exec();
   37 
   38     inline void setBoolean(bool AND)
   39     {
   40         _boolean_and = AND;
   41     }
   42     inline void setSearchScope(const QString& file, const QString& dir, bool all, bool documents)
   43     {
   44         _bibtex_file = file;
   45         _bibtex_dir = dir;
   46         _all_bibtex_files = all;
   47         _include_documents = documents;
   48     }
   49     inline void setSimplifySource(bool simplify)
   50     {
   51         _simplify_source = simplify;
   52     }
   53     inline int errorsCount() const
   54     {
   55         return _error_counter;
   56     }
   57     inline int hitsCount() const
   58     {
   59         return _result_references.count();
   60     }
   61     inline QString hitsString() const
   62     {
   63         return _result_string;
   64     }
   65     inline QString hitHtmlDatum(const int index) const
   66     {
   67         return index < _result_html_data.count() ? _result_html_data.at(index) : QString();
   68     }
   69     inline QString hitHtmlAbstract(const int index) const
   70     {
   71         return index < _result_html_abstracts.count() ? _result_html_abstracts.at(index) : QString();
   72     }
   73     inline int patternsCount() const
   74     {
   75         return _patterns.count();
   76     }
   77     inline int referencesCount() const
   78     {
   79         return _reference_counter;
   80     }
   81     inline QString logString() const
   82     {
   83         return _log_string;
   84     }
   85     inline bool isSearchSimilar() const
   86     {
   87         return _do_search_similar;
   88     }
   89 
   90 
   91 public slots:
   92     void abort();
   93 
   94 
   95 private:
   96     bibSearcher();
   97 
   98 
   99     QString excerpts(const QString& contents);
  100     QString highlight(const QString& abstract);
  101     QString location(const QString& fn, const bibReference& ref) const;
  102     void search(const QString& bib_file);
  103     void searchReference(const QString& bib_file, const bibReference& ref);
  104     void searchSimilarReferences(const QString& bib_file, const bibReference& ref);
  105     void setTitleRank(const QString& title);
  106 
  107     template <typename T1, typename T2, typename T3, typename T4>
  108     void quadrupleSortDescending(int start, int end, T1* v1, T2* v2, T3* v3, T4* v4)
  109     {
  110         // Template quadrupleSortDescending was adapted from qSortHelper by Pere Constans.
  111         // qSortHelper is copyrighted by
  112         // (C) 2011 Nokia Corporation and/or its subsidiary(-ies),
  113         // and released under GLP/LGPL license.
  114 top:
  115         int span = end - start;
  116         if (span < 2)
  117             return;
  118         --end;
  119         int low = start;
  120         int high = end - 1;
  121         int pivot = start + span / 2;
  122         if (v1->at(end) > v1->at(start))
  123         {
  124             std::swap((*v1)[end], (*v1)[start]);
  125             std::swap((*v2)[end], (*v2)[start]);
  126             std::swap((*v3)[end], (*v3)[start]);
  127             std::swap((*v4)[end], (*v4)[start]);
  128         }
  129         if (span == 2)
  130             return;
  131         if (v1->at(pivot) > v1->at(start))
  132         {
  133             std::swap((*v1)[pivot], (*v1)[start]);
  134             std::swap((*v2)[pivot], (*v2)[start]);
  135             std::swap((*v3)[pivot], (*v3)[start]);
  136             std::swap((*v4)[pivot], (*v4)[start]);
  137         }
  138         if (v1->at(end) > v1->at(pivot))
  139         {
  140             std::swap((*v1)[end], (*v1)[pivot]);
  141             std::swap((*v2)[end], (*v2)[pivot]);
  142             std::swap((*v3)[end], (*v3)[pivot]);
  143             std::swap((*v4)[end], (*v4)[pivot]);
  144         }
  145         if (span == 3)
  146             return;
  147         std::swap((*v1)[pivot], (*v1)[end]);
  148         std::swap((*v2)[pivot], (*v2)[end]);
  149         std::swap((*v3)[pivot], (*v3)[end]);
  150         std::swap((*v4)[pivot], (*v4)[end]);
  151         while (low < high)
  152         {
  153             while (low < high && v1->at(low) > v1->at(end))
  154                 ++low;
  155             while (high > low && v1->at(end) > v1->at(high))
  156                 --high;
  157             if (low < high)
  158             {
  159                 std::swap((*v1)[low], (*v1)[high]);
  160                 std::swap((*v2)[low], (*v2)[high]);
  161                 std::swap((*v3)[low], (*v3)[high]);
  162                 std::swap((*v4)[low], (*v4)[high]);
  163                 ++low;
  164                 --high;
  165             }
  166             else
  167                 break;
  168         }
  169         if (v1->at(low) > v1->at(end))
  170             ++low;
  171         std::swap((*v1)[end], (*v1)[low]);
  172         std::swap((*v2)[end], (*v2)[low]);
  173         std::swap((*v3)[end], (*v3)[low]);
  174         std::swap((*v4)[end], (*v4)[low]);
  175         quadrupleSortDescending(start, low, v1, v2, v3, v4);
  176         start = low + 1;
  177         ++end;
  178         goto top;
  179     }
  180     template <typename T1, typename T2, typename T3, typename T4>
  181     void quadrupleSortDescending(T1* v1, T2* v2, T3* v3, T4* v4)
  182     {
  183         const int n(v1->size());
  184         if (n != v2->size() && n != v3->size() && n != v4->size())
  185             c2bUtils::warn(tr("Invalid array dimensions at quadrupleSortDescending"));
  186         else
  187             quadrupleSortDescending(0, n, v1, v2, v3, v4);
  188     }
  189 
  190     QList<double> _result_scores;
  191     QString _result_string;
  192     QStringList _result_html_abstracts;
  193     QStringList _result_html_data;
  194     QStringList _result_references;
  195 
  196     QList<searchPattern> _patterns;
  197     QString _bibtex_dir;
  198     QString _bibtex_file;
  199     QString _do_search_similar_citeid;
  200     QString _log_string;
  201     QStringList _scopes;
  202     bibParser* _bpP;
  203     bool _aborted;
  204     bool _all_bibtex_files;
  205     bool _boolean_and;
  206     bool _include_documents;
  207     bool _simplify_source;
  208     documentCache _documents;
  209     double _reference_score;
  210     int _bibtex_counter;
  211     int _document_counter;
  212     int _error_counter;
  213     int _reference_counter;
  214     int _reference_match_counter;
  215 
  216     const bool _do_rank_results;
  217     const bool _do_search_similar;
  218 };
  219 
  220 #endif