Parent: [c1fad4] (diff)

Download this file

docseq.cpp    132 lines (116 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright (C) 2005 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include "docseq.h"
#include "filtseq.h"
#include "sortseq.h"
#include "log.h"
#include "internfile.h"
std::mutex DocSequence::o_dblock;
string DocSequence::o_sort_trans;
string DocSequence::o_filt_trans;
int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
{
int ret = 0;
for (int num = offs; num < offs + cnt; num++, ret++) {
result.push_back(ResListEntry());
if (!getDoc(num, result.back().doc, &result.back().subHeader)) {
result.pop_back();
return ret;
}
}
return ret;
}
bool DocSequence::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{
Rcl::Db *db = getDb();
if (db == 0) {
LOGERR("DocSequence::getEnclosing: no db\n" );
return false;
}
std::unique_lock<std::mutex> locker(o_dblock);
string udi;
if (!FileInterner::getEnclosingUDI(doc, udi))
return false;
bool dbret = db->getDoc(udi, doc, pdoc);
return dbret && pdoc.pc != -1;
}
// Remove stacked modifying sources (sort, filter) until we get to a real one
void DocSource::stripStack()
{
if (!m_seq)
return;
while (m_seq->getSourceSeq()) {
m_seq = m_seq->getSourceSeq();
}
}
bool DocSource::buildStack()
{
LOGDEB2("DocSource::buildStack()\n" );
stripStack();
if (!m_seq)
return false;
// Filtering must be done before sorting, (which may
// truncates the original list)
if (m_seq->canFilter()) {
if (!m_seq->setFiltSpec(m_fspec)) {
LOGERR("DocSource::buildStack: setfiltspec failed\n" );
}
} else {
if (m_fspec.isNotNull()) {
m_seq =
std::shared_ptr<DocSequence>(new DocSeqFiltered(m_config, m_seq, m_fspec));
}
}
if (m_seq->canSort()) {
if (!m_seq->setSortSpec(m_sspec)) {
LOGERR("DocSource::buildStack: setsortspec failed\n" );
}
} else {
if (m_sspec.isNotNull()) {
m_seq = std::shared_ptr<DocSequence>(new DocSeqSorted(m_seq, m_sspec));
}
}
return true;
}
string DocSource::title()
{
if (!m_seq)
return string();
string qual;
if (m_fspec.isNotNull() && !m_sspec.isNotNull())
qual = string(" (") + o_filt_trans + string(")");
else if (!m_fspec.isNotNull() && m_sspec.isNotNull())
qual = string(" (") + o_sort_trans + string(")");
else if (m_fspec.isNotNull() && m_sspec.isNotNull())
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans + string(")");
return m_seq->title() + qual;
}
bool DocSource::setFiltSpec(const DocSeqFiltSpec &f)
{
LOGDEB2("DocSource::setFiltSpec\n" );
m_fspec = f;
buildStack();
return true;
}
bool DocSource::setSortSpec(const DocSeqSortSpec &s)
{
LOGDEB2("DocSource::setSortSpec\n" );
m_sspec = s;
buildStack();
return true;
}