Child: [b28eaf] (diff)

Download this file

dynconf.h    124 lines (107 with data), 3.7 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
/*
* 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.
*/
#ifndef _DYNCONF_H_INCLUDED_
#define _DYNCONF_H_INCLUDED_
/* @(#$Id: dynconf.h,v 1.7 2007-06-20 13:16:11 dockes Exp $ (C) 2004 J.F.Dockes */
/**
* Dynamic configuration storage
*
* This used to be called "history" because of the initial usage.
* Used to store some parameters which would fit neither in recoll.conf,
* basically because they change a lot, nor in the QT preferences file, mostly
* because they are specific to a configuration directory.
* Examples:
* - History of documents selected for preview
* - Active and inactive external databases (depend on the
* configuration directory)
* - ...
*
* The storage is performed in a ConfSimple file, with subkeys and
* encodings which depend on the data stored. Under each section, the keys
* are sequential numeric, so this basically manages a set of lists.
*
*/
#include <string>
#include <list>
#include <utility>
#include "conftree.h"
#ifndef NO_NAMESPACES
using namespace std;
#endif
// Entry interface.
class DynConfEntry {
public:
virtual ~DynConfEntry() {}
virtual bool decode(const string &value) = 0;
virtual bool encode(string& value) = 0;
virtual bool equal(const DynConfEntry &other) = 0;
};
/** String storage generic object */
class RclSListEntry : public DynConfEntry {
public:
RclSListEntry() {}
RclSListEntry(const string& v) : value(v) {}
virtual ~RclSListEntry() {}
virtual bool decode(const string &enc);
virtual bool encode(string& enc);
virtual bool equal(const DynConfEntry& other);
string value;
};
/** The dynamic configuration class */
class RclDynConf {
public:
RclDynConf(const string &fn)
: m_data(fn.c_str()) {}
bool ok() {return m_data.getStatus() == ConfSimple::STATUS_RW;}
string getFilename() {return m_data.getFilename();}
// Generic methods
bool eraseAll(const string& sk);
bool insertNew(const string& sk, DynConfEntry &n, DynConfEntry &s,
int maxlen = -1);
template<typename Tp> list<Tp> getList(const string& sk);
// Specialized methods for simple string lists, designated by the
// subkey value
bool enterString(const string sk, const string value, int maxlen = -1);
list<string> getStringList(const string sk);
private:
unsigned int m_mlen;
ConfSimple m_data;
};
template<typename Tp> list<Tp> RclDynConf::getList(const string &sk)
{
list<Tp> mlist;
Tp entry;
list<string> names = m_data.getNames(sk);
for (list<string>::const_iterator it = names.begin();
it != names.end(); it++) {
string value;
if (m_data.get(*it, value, sk)) {
if (!entry.decode(value))
continue;
mlist.push_front(entry);
}
}
return mlist;
}
// Defined subkeys. Values in dynconf.cpp
// History
extern const string docHistSubKey;
// All external indexes
extern const string allEdbsSk;
// Active external indexes
extern const string actEdbsSk;
#endif /* _DYNCONF_H_INCLUDED_ */