avoid unneeded getDoc(0) + normalize private var names
This commit is contained in:
parent
55df39a41b
commit
43de9ebbbf
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.3 2005-12-05 12:02:01 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.4 2005-12-05 16:13:12 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@ -8,61 +8,64 @@ static char rcsid[] = "@(#$Id: docseq.cpp,v 1.3 2005-12-05 12:02:01 dockes Exp $
|
|||||||
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh)
|
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh)
|
||||||
{
|
{
|
||||||
if (sh) sh->erase();
|
if (sh) sh->erase();
|
||||||
return db ? db->getDoc(num, doc, percent) : false;
|
return m_db ? m_db->getDoc(num, doc, percent) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DocSequenceDb::getResCnt()
|
int DocSequenceDb::getResCnt()
|
||||||
{
|
{
|
||||||
if (!db)
|
if (!m_db)
|
||||||
return -1;
|
return -1;
|
||||||
// Need to fetch one document before we can get the result count
|
// Need to fetch one document before we can get the result count
|
||||||
Rcl::Doc doc;
|
if (m_rescnt < 0) {
|
||||||
int percent;
|
Rcl::Doc doc;
|
||||||
db->getDoc(0, doc, &percent);
|
int percent;
|
||||||
return db->getResCnt();
|
m_db->getDoc(0, doc, &percent);
|
||||||
|
m_rescnt= m_db->getResCnt();
|
||||||
|
}
|
||||||
|
return m_rescnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
|
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
|
||||||
string *sh) {
|
string *sh) {
|
||||||
// Retrieve history list
|
// Retrieve history list
|
||||||
if (!hist)
|
if (!m_hist)
|
||||||
return false;
|
return false;
|
||||||
if (hlist.empty())
|
if (m_hlist.empty())
|
||||||
hlist = hist->getDocHistory();
|
m_hlist = m_hist->getDocHistory();
|
||||||
|
|
||||||
if (num < 0 || num >= (int)hlist.size())
|
if (num < 0 || num >= (int)m_hlist.size())
|
||||||
return false;
|
return false;
|
||||||
int skip;
|
int skip;
|
||||||
if (prevnum >= 0 && num >= prevnum) {
|
if (m_prevnum >= 0 && num >= m_prevnum) {
|
||||||
skip = num - prevnum;
|
skip = num - m_prevnum;
|
||||||
} else {
|
} else {
|
||||||
skip = num;
|
skip = num;
|
||||||
it = hlist.begin();
|
m_it = m_hlist.begin();
|
||||||
prevtime = -1;
|
m_prevtime = -1;
|
||||||
}
|
}
|
||||||
prevnum = num;
|
m_prevnum = num;
|
||||||
while (skip--)
|
while (skip--)
|
||||||
it++;
|
m_it++;
|
||||||
if (percent)
|
if (percent)
|
||||||
*percent = 100;
|
*percent = 100;
|
||||||
if (sh) {
|
if (sh) {
|
||||||
if (prevtime < 0 || abs(prevtime - (*it).unixtime) > 86400) {
|
if (m_prevtime < 0 || abs(m_prevtime - m_it->unixtime) > 86400) {
|
||||||
prevtime = it->unixtime;
|
m_prevtime = m_it->unixtime;
|
||||||
time_t t = (time_t)(it->unixtime);
|
time_t t = (time_t)(m_it->unixtime);
|
||||||
*sh = string(ctime(&t));
|
*sh = string(ctime(&t));
|
||||||
// Get rid of the final \n in ctime
|
// Get rid of the final \n in ctime
|
||||||
sh->erase(sh->length()-1);
|
sh->erase(sh->length()-1);
|
||||||
} else
|
} else
|
||||||
sh->erase();
|
sh->erase();
|
||||||
}
|
}
|
||||||
return db->getDoc((*it).fn, (*it).ipath, doc);
|
return m_db->getDoc(m_it->fn, m_it->ipath, doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DocSequenceHistory::getResCnt()
|
int DocSequenceHistory::getResCnt()
|
||||||
{
|
{
|
||||||
if (hlist.empty())
|
if (m_hlist.empty())
|
||||||
hlist = hist->getDocHistory();
|
m_hlist = m_hist->getDocHistory();
|
||||||
return hlist.size();
|
return m_hlist.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#ifndef _DOCSEQ_H_INCLUDED_
|
#ifndef _DOCSEQ_H_INCLUDED_
|
||||||
#define _DOCSEQ_H_INCLUDED_
|
#define _DOCSEQ_H_INCLUDED_
|
||||||
/* @(#$Id: docseq.h,v 1.2 2005-11-28 15:31:01 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: docseq.h,v 1.3 2005-12-05 16:13:12 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
#include "rcldb.h"
|
#include "rcldb.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
@ -23,33 +23,34 @@ class DocSequence {
|
|||||||
to make sense */
|
to make sense */
|
||||||
class DocSequenceDb : public DocSequence {
|
class DocSequenceDb : public DocSequence {
|
||||||
public:
|
public:
|
||||||
DocSequenceDb(Rcl::Db *d) : db(d) {}
|
DocSequenceDb(Rcl::Db *d) : m_db(d), m_rescnt(-1) {}
|
||||||
virtual ~DocSequenceDb() {}
|
virtual ~DocSequenceDb() {}
|
||||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0);
|
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0);
|
||||||
virtual int getResCnt();
|
virtual int getResCnt();
|
||||||
virtual std::string title() {return string("Query results");}
|
virtual std::string title() {return string("Query results");}
|
||||||
private:
|
private:
|
||||||
Rcl::Db *db;
|
Rcl::Db *m_db;
|
||||||
|
int m_rescnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A DocSequence coming from the history file */
|
/** A DocSequence coming from the history file */
|
||||||
class DocSequenceHistory : public DocSequence {
|
class DocSequenceHistory : public DocSequence {
|
||||||
public:
|
public:
|
||||||
DocSequenceHistory(Rcl::Db *d, RclDHistory *h)
|
DocSequenceHistory(Rcl::Db *d, RclDHistory *h)
|
||||||
: db(d), hist(h), prevnum(-1), prevtime(-1) {}
|
: m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {}
|
||||||
virtual ~DocSequenceHistory() {}
|
virtual ~DocSequenceHistory() {}
|
||||||
|
|
||||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
|
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
|
||||||
virtual int getResCnt();
|
virtual int getResCnt();
|
||||||
virtual std::string title() {return string("Document history");}
|
virtual std::string title() {return string("Document history");}
|
||||||
private:
|
private:
|
||||||
Rcl::Db *db;
|
Rcl::Db *m_db;
|
||||||
RclDHistory *hist;
|
RclDHistory *m_hist;
|
||||||
int prevnum;
|
int m_prevnum;
|
||||||
long prevtime;
|
long m_prevtime;
|
||||||
|
|
||||||
std::list<RclDHistoryEntry> hlist;
|
std::list<RclDHistoryEntry> m_hlist;
|
||||||
std::list<RclDHistoryEntry>::const_iterator it;
|
std::list<RclDHistoryEntry>::const_iterator m_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _DOCSEQ_H_INCLUDED_ */
|
#endif /* _DOCSEQ_H_INCLUDED_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user