Annotation of parser3/src/types/pa_vhashfile.h, revision 1.4
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.4 ! parser 7: $Id: pa_vhashfile.h,v 1.3 2001/10/23 12:41:05 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:
47: /// VHashfile: (key)=value
48: void put_element(const String& name, Value *value) {
49: put_field(name, value);
50: }
51:
52:
53: public: // usage
54:
1.3 parser 55: VHashfile(Pool& apool) : VStateless_class(apool, hashfile_base_class),
1.2 parser 56: fconnection(0) {
57: register_cleanup(VHashfile_cleanup, this);
1.1 parser 58: }
1.2 parser 59: private:
60: void cleanup() {
61: if(fconnection)
62: fconnection->close(); // cache it
1.1 parser 63: }
1.2 parser 64: public:
1.1 parser 65:
1.3 parser 66: void set_connection(DB_Connection& aconnection) { fconnection=&aconnection; }
1.2 parser 67: DB_Connection& get_connection(const String *source) const {
68: if(!fconnection)
1.1 parser 69: throw Exception(0, 0,
70: source,
71: "can not be applied to uninitialized instance");
72:
1.2 parser 73: return *fconnection;
1.1 parser 74: }
75:
76: private:
77:
78: Value *get_field(const String& name);
79: void put_field(const String& name, Value *value);
80:
81: private:
82:
1.2 parser 83: DB_Connection *fconnection;
1.1 parser 84:
85: };
86:
87: #endif
E-mail: