Annotation of parser3/src/types/pa_vhashfile.h, revision 1.2
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.2 ! parser 7: $Id: pa_vhashfile.h,v 1.1 2001/10/22 12:30:24 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:
19: extern Methoded *hash_base_class;
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
32: Hash *get_hash();
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:
55: VHashfile(Pool& apool) : VStateless_class(apool, hash_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.2 ! parser 66: void assign(const String& file_spec, const String& request_origin) {
! 67: fconnection=&DB_manager->get_connection(file_spec, request_origin);
1.1 parser 68: }
1.2 ! parser 69: DB_Connection& get_connection(const String *source) const {
! 70: if(!fconnection)
1.1 parser 71: throw Exception(0, 0,
72: source,
73: "can not be applied to uninitialized instance");
74:
1.2 ! parser 75: return *fconnection;
1.1 parser 76: }
77:
78: private:
79:
80: Value *get_field(const String& name);
81: void put_field(const String& name, Value *value);
82:
83: private:
84:
1.2 ! parser 85: DB_Connection *fconnection;
1.1 parser 86:
87: };
88:
89: #endif
E-mail: