Switch to unified view

a/src/utils/circache.h b/src/utils/circache.h
...
...
22
 *
22
 *
23
 * A single file is used to stored objects. The file grows to a
23
 * A single file is used to stored objects. The file grows to a
24
 * specified maximum size, then is rewritten from the start,
24
 * specified maximum size, then is rewritten from the start,
25
 * overwriting older entries.
25
 * overwriting older entries.
26
 *
26
 *
27
 * Data objects inside the cache each have two parts: a data segment and an 
27
 * Data objects inside the cache each have two parts: a data segment and an
28
 * attribute (metadata) dictionary.
28
 * attribute (metadata) dictionary.
29
 * They are named using the same identifiers that are used inside the Recoll
29
 * They are named using the same identifiers that are used inside the Recoll
30
 * index (the UDI).
30
 * index (the UDI).
31
 *
31
 *
32
 * Inside the file. the UDIs are stored inside the entry dictionary
32
 * Inside the file. the UDIs are stored inside the entry dictionary
33
 * under the key "udi".
33
 * under the key "udi".
34
 * 
34
 *
35
 * It is assumed that the dictionary are small (they are routinely read/parsed)
35
 * It is assumed that the dictionary are small (they are routinely read/parsed)
36
 *
36
 *
37
 */
37
 */
38
38
39
#include <sys/types.h>
39
#include <sys/types.h>
40
40
41
#include <string>
41
#include <string>
42
42
43
#ifndef NO_NAMESPACES
44
using std::string;
45
#endif
46
47
class ConfSimple;
43
class ConfSimple;
48
class CirCacheInternal;
44
class CirCacheInternal;
49
45
50
class CirCache {
46
class CirCache {
51
public:
47
public:
52
    CirCache(const string& dir);
48
    CirCache(const std::string& dir);
53
    virtual ~CirCache();
49
    virtual ~CirCache();
54
50
55
    virtual string getReason();
51
    virtual std::string getReason();
56
52
57
    enum CreateFlags {CC_CRNONE=0, 
53
    enum CreateFlags {CC_CRNONE = 0,
58
            // Unique entries: erase older instances when same udi
54
                      // Unique entries: erase older instances when same udi
59
            // is stored.
55
                      // is stored.
60
            CC_CRUNIQUE=1,
56
                      CC_CRUNIQUE = 1,
61
            // Truncate file (restart from scratch).
57
                      // Truncate file (restart from scratch).
62
            CC_CRTRUNCATE = 2};
58
                      CC_CRTRUNCATE = 2
59
                     };
63
    virtual bool create(off_t maxsize, int flags);
60
    virtual bool create(off_t maxsize, int flags);
64
61
65
    enum OpMode {CC_OPREAD, CC_OPWRITE};
62
    enum OpMode {CC_OPREAD, CC_OPWRITE};
66
    virtual bool open(OpMode mode);
63
    virtual bool open(OpMode mode);
67
64
68
    virtual std::string getpath();
65
    virtual std::string getpath();
69
66
70
    virtual bool get(const string& udi, string& dic, string& data, 
67
    virtual bool get(const std::string& udi, std::string& dic,
71
                     int instance = -1);
68
                     std::string& data, int instance = -1);
72
69
73
    // Note: the dicp MUST have an udi entry
70
    // Note: the dicp MUST have an udi entry
74
    enum PutFlags {NoCompHint = 1};
71
    enum PutFlags {NoCompHint = 1};
75
    virtual bool put(const string& udi, const ConfSimple *dicp, 
72
    virtual bool put(const std::string& udi, const ConfSimple *dicp,
76
                     const string& data, unsigned int flags = 0);
73
                     const std::string& data, unsigned int flags = 0);
77
74
78
    virtual bool erase(const string& udi);
75
    virtual bool erase(const std::string& udi);
79
76
80
    /** Walk the archive.
77
    /** Walk the archive.
81
     *
78
     *
82
     * Maybe we'll have separate iterators one day, but this is good
79
     * Maybe we'll have separate iterators one day, but this is good
83
     * enough for now. No put() operations should be performed while
80
     * enough for now. No put() operations should be performed while
84
     * using these.
81
     * using these.
85
     */
82
     */
86
    /** Back to oldest */
83
    /** Back to oldest */
87
    virtual bool rewind(bool& eof);
84
    virtual bool rewind(bool& eof);
88
    /** Get entry under cursor */
85
    /** Get entry under cursor */
89
    virtual bool getCurrent(string& udi, string& dic, string& data);
86
    virtual bool getCurrent(std::string& udi, std::string& dic,
87
                            std::string& data);
90
    /** Get current entry udi only. Udi can be empty (erased empty), caller
88
    /** Get current entry udi only. Udi can be empty (erased empty), caller
91
     * should call again */
89
     * should call again */
92
    virtual bool getCurrentUdi(string& udi);
90
    virtual bool getCurrentUdi(std::string& udi);
93
    /** Skip to next. (false && !eof) -> error, (false&&eof)->EOF. */
91
    /** Skip to next. (false && !eof) -> error, (false&&eof)->EOF. */
94
    virtual bool next(bool& eof);
92
    virtual bool next(bool& eof);
95
93
96
    /* Debug. This writes the entry headers to stdout */
94
    /* Debug. This writes the entry headers to stdout */
97
    virtual bool dump();
95
    virtual bool dump();
98
96
99
protected:
97
protected:
100
    CirCacheInternal *m_d;
98
    CirCacheInternal *m_d;
101
    string m_dir;
99
    std::string m_dir;
102
private:
100
private:
103
    CirCache(const CirCache&) {}
101
    CirCache(const CirCache&) {}
104
    CirCache& operator=(const CirCache&) {return *this;}
102
    CirCache& operator=(const CirCache&) {
103
        return *this;
104
    }
105
};
105
};
106
106
107
#endif /* _circache_h_included_ */
107
#endif /* _circache_h_included_ */