Annotation of parser3/src/types/pa_vhashfile.h, revision 1.23
1.1 parser 1: /** @file
2: Parser: @b hashfile parser type decl.
3:
1.17 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (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.23 ! paf 11: static const char* IDENT_VHASHFILE_H="$Date: 2003/11/06 11:53:06 $";
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:
19: #include "apr_sdbm.h"
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: true
1.17 paf 37: override bool is_defined() const { return true; }
1.1 parser 38:
39: /// VHashfile: convert to VHash
1.20 paf 40: override HashStringValue *get_hash();
1.1 parser 41:
42: /// VHashfile: (key)=value
1.17 paf 43: override Value* get_element(const String& aname, Value& aself, bool looking_up) {
1.1 parser 44: // $CLASS,$method
1.17 paf 45: if(Value *result=VStateless_object::get_element(aname, aself, looking_up))
1.1 parser 46: return result;
47:
48: // $element
1.17 paf 49: return get_field(aname);
1.1 parser 50: }
51:
1.5 parser 52: /// VHashfile: (key)=value, (key)=(value+expires)
1.17 paf 53: override bool put_element(const String& aname, Value* avalue, bool /*replace*/) {
54: put_field(aname, avalue);
55: return false; // nobody is supposed to derive from hashfile, so does not matter
1.6 parser 56: }
1.1 parser 57:
58: public: // usage
59:
1.23 ! paf 60: VHashfile(Pool& apool): Pooled(apool), db(0) {}
1.18 paf 61: override ~VHashfile();
1.9 paf 62:
1.17 paf 63: void open(const String& afile_name);
1.22 paf 64: void make_writable();
1.17 paf 65: void clear();
1.19 paf 66: void remove(const String& aname);
1.21 paf 67:
1.22 paf 68: void for_each(void callback(apr_sdbm_datum_t, void*), void* info) const;
1.21 paf 69: void for_each(void callback(const String::Body, const String&, void*), void* info) const;
1.9 paf 70:
1.1 parser 71: private:
72:
1.9 paf 73: Value *get_field(const String& aname);
74: void put_field(const String& aname, Value *avalue);
1.1 parser 75:
76: private:
77:
1.22 paf 78: const char* file_name;
1.17 paf 79: apr_sdbm_t *db;
80:
1.1 parser 81: };
82:
83: #endif
E-mail: