Annotation of parser3/src/types/pa_vhashfile.h, revision 1.42
1.1 parser 1: /** @file
2: Parser: @b hashfile parser type decl.
3:
1.40 moko 4: Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.15 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 parser 6: */
7:
8: #ifndef PA_VHASHFILE_H
9: #define PA_VHASHFILE_H
10:
1.42 ! moko 11: #define IDENT_PA_VHASHFILE_H "$Id: pa_vhashfile.h,v 1.41 2012/06/08 02:02:31 misha Exp $"
1.17 paf 12:
1.1 parser 13: #include "classes.h"
1.23 paf 14: #include "pa_pool.h"
1.1 parser 15: #include "pa_value.h"
16: #include "pa_hash.h"
17: #include "pa_vint.h"
1.17 paf 18:
1.39 moko 19: #include "pa_sdbm.h"
1.17 paf 20:
21: // defines
22:
23: #define VHASHFILE_TYPE "hashfile"
1.1 parser 24:
1.7 parser 25: // externs
26:
1.17 paf 27: extern Methoded *hashfile_class;
1.1 parser 28:
1.17 paf 29: /// value of type 'hashfile', implemented with SDBM library bundled in ../libs/sdbm
1.23 paf 30: class VHashfile : public VStateless_object, Pooled {
1.1 parser 31: public: // value
32:
1.17 paf 33: override const char *type() const { return VHASHFILE_TYPE; }
34: override VStateless_class *get_class() { return hashfile_class; }
1.1 parser 35:
36: /// VHashfile: convert to VHash
1.20 paf 37: override HashStringValue *get_hash();
1.1 parser 38:
1.41 misha 39: override HashStringValue* get_fields() { return get_hash(); }
40:
1.1 parser 41: /// VHashfile: (key)=value
1.38 misha 42: override Value* get_element(const String& aname) {
1.1 parser 43: // $CLASS,$method
1.38 misha 44: if(Value *result=VStateless_object::get_element(aname))
1.1 parser 45: return result;
46:
47: // $element
1.17 paf 48: return get_field(aname);
1.1 parser 49: }
50:
1.5 parser 51: /// VHashfile: (key)=value, (key)=(value+expires)
1.38 misha 52: override const VJunction* put_element(const String& aname, Value* avalue, bool /*replace*/) {
1.17 paf 53: put_field(aname, avalue);
1.42 ! moko 54: return 0; // nobody is supposed to derive from hashfile, so does not matter
1.6 parser 55: }
1.1 parser 56:
57: public: // usage
58:
1.24 paf 59: VHashfile(Pool& apool): Pooled(apool), m_db(0) {}
1.18 paf 60: override ~VHashfile();
1.9 paf 61:
1.17 paf 62: void open(const String& afile_name);
1.24 paf 63: void close();
1.37 misha 64: bool is_open();
1.39 moko 65: pa_sdbm_t *get_db_for_reading();
66: pa_sdbm_t *get_db_for_writing();
1.36 misha 67: // void clear();
1.24 paf 68: void delete_files();
1.19 paf 69: void remove(const String& aname);
1.21 paf 70:
1.39 moko 71: void for_each(bool callback(pa_sdbm_datum_t, void*), void* info);
1.34 paf 72: void for_each(bool callback(const String::Body, const String&, void*), void* info);
1.25 paf 73:
74: public:
75:
1.39 moko 76: void remove(const pa_sdbm_datum_t key);
1.25 paf 77:
1.39 moko 78: pa_sdbm_datum_t serialize_value(const String& string, time_t time_to_die) const;
79: const String* deserialize_value(const pa_sdbm_datum_t key, const pa_sdbm_datum_t value);
1.9 paf 80:
1.1 parser 81: private:
82:
1.9 paf 83: Value *get_field(const String& aname);
84: void put_field(const String& aname, Value *avalue);
1.1 parser 85:
86: private:
87:
1.22 paf 88: const char* file_name;
1.39 moko 89: pa_sdbm_t *m_db;
1.17 paf 90:
1.1 parser 91: };
92:
93: #endif
E-mail: