Annotation of parser3/src/types/pa_vhashfile.h, revision 1.6

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

E-mail: