Annotation of parser3/src/types/pa_vhashfile.h, revision 1.5
1.1 parser 1: /** @file
2: Parser: @b hashfile parser type decl.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
6:
1.5 ! parser 7: $Id: pa_vhashfile.h,v 1.4 2001/10/23 14:43:44 parser Exp $
1.1 parser 8: */
9:
10: #ifndef PA_VHASHFILE_H
11: #define PA_VHASHFILE_H
12:
13: #include "classes.h"
14: #include "pa_value.h"
15: #include "pa_hash.h"
16: #include "pa_vint.h"
1.2 parser 17: #include "pa_db_connection.h"
1.1 parser 18:
1.3 parser 19: extern Methoded *hashfile_base_class;
1.1 parser 20:
21: /// value of type 'hashfile', implemented with GDBM library
22: class VHashfile : public VStateless_class {
1.2 parser 23: friend void VHashfile_cleanup(void *);
1.1 parser 24: public: // value
25:
26: const char *type() const { return "hashfile"; }
27:
28: /// VHashfile: true
29: bool is_defined() const { return true; }
30:
31: /// VHashfile: convert to VHash
1.4 parser 32: Hash *get_hash(const String *source);
1.1 parser 33:
34: /// VHashfile: 0
35: VStateless_class *get_class() { return 0; }
36:
37: /// VHashfile: (key)=value
38: Value *get_element(const String& name) {
39: // $CLASS,$method
40: if(Value *result=VStateless_class::get_element(name))
41: return result;
42:
43: // $element
44: return get_field(name);
45: }
46:
1.5 ! parser 47: /// VHashfile: (key)=value, (key)=(value+expires)
! 48: void put_element(const String& name, Value *value);
1.1 parser 49:
50: public: // usage
51:
1.3 parser 52: VHashfile(Pool& apool) : VStateless_class(apool, hashfile_base_class),
1.2 parser 53: fconnection(0) {
54: register_cleanup(VHashfile_cleanup, this);
1.1 parser 55: }
1.2 parser 56: private:
57: void cleanup() {
58: if(fconnection)
59: fconnection->close(); // cache it
1.1 parser 60: }
1.2 parser 61: public:
1.1 parser 62:
1.3 parser 63: void set_connection(DB_Connection& aconnection) { fconnection=&aconnection; }
1.2 parser 64: DB_Connection& get_connection(const String *source) const {
65: if(!fconnection)
1.1 parser 66: throw Exception(0, 0,
67: source,
68: "can not be applied to uninitialized instance");
69:
1.2 parser 70: return *fconnection;
1.1 parser 71: }
72:
73: private:
74:
75: Value *get_field(const String& name);
1.5 ! parser 76: void put_field(const String& name, Value *value, time_t time_to_die);
1.1 parser 77:
78: private:
79:
1.2 parser 80: DB_Connection *fconnection;
1.1 parser 81:
82: };
83:
84: #endif
E-mail: