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

1.1       parser      1: /** @file
                      2:        Parser: @b hashfile parser type decl.
                      3: 
1.14    ! paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.12      paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.1       parser      6: 
1.14    ! paf         7:        $Id: pa_vhashfile.h,v 1.13 2002/01/24 17:18:49 paf 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.8       paf        17: #include "pa_db_table.h"
1.9       paf        18: #include "pa_db_manager.h"
1.1       parser     19: 
1.7       parser     20: // externs
                     21: 
1.3       parser     22: extern Methoded *hashfile_base_class;
1.1       parser     23: 
1.7       parser     24: // forwards
                     25: 
                     26: class Autosave_marked_to_cancel_cache ;
                     27: 
1.1       parser     28: /// value of type 'hashfile', implemented with GDBM library
                     29: class VHashfile : public VStateless_class {
1.2       parser     30:        friend void VHashfile_cleanup(void *);
1.10      paf        31:        friend class Autosave_marked_to_cancel_cache;
1.1       parser     32: public: // value
                     33: 
                     34:        const char *type() const { return "hashfile"; }
                     35: 
                     36:        /// VHashfile: true
                     37:        bool is_defined() const { return true; }
                     38: 
                     39:        /// VHashfile: convert to VHash
1.4       parser     40:        Hash *get_hash(const String *source);
1.1       parser     41: 
                     42:        /// VHashfile: 0
                     43:        VStateless_class *get_class() { return 0; }
                     44: 
                     45:        /// VHashfile: (key)=value
                     46:        Value *get_element(const String& name) { 
                     47:                // $CLASS,$method
                     48:                if(Value *result=VStateless_class::get_element(name))
                     49:                        return result;
                     50:                
                     51:                // $element
                     52:                return get_field(name);
                     53:        }
                     54:        
1.5       parser     55:        /// VHashfile: (key)=value, (key)=(value+expires)
1.6       parser     56:        void put_element(const String& name, Value *value) {
                     57:                put_field(name, value);
                     58:        }
1.1       parser     59: 
                     60: public: // usage
                     61: 
1.3       parser     62:        VHashfile(Pool& apool) : VStateless_class(apool, hashfile_base_class),
1.9       paf        63:                fdb_home(0), ffile_name(0), 
                     64:                fmarked_to_cancel_cache(false) {
1.1       parser     65:        }
1.9       paf        66: 
                     67:        void assign(const String& adb_home, const String& afile_name) { 
                     68:                fdb_home=&adb_home;
                     69:                ffile_name=&afile_name;
1.1       parser     70:        }
1.9       paf        71:        DB_Table_ptr get_table_ptr(const String *source) {
                     72:                if(!fdb_home)
1.1       parser     73:                        throw Exception(0, 0,
                     74:                                source,
                     75:                                "can not be applied to uninitialized instance");
                     76: 
1.9       paf        77:                return 
                     78:                        DB_manager->
                     79:                        get_connection_ptr(*fdb_home, source)->
                     80:                        get_table_ptr(*ffile_name, source);
1.1       parser     81:        }
                     82: 
1.11      paf        83:        void mark_to_cancel_cache() { 
1.13      paf        84:                fmarked_to_cancel_cache=true; 
1.11      paf        85:        }
1.7       parser     86:        bool marked_to_cancel_cache() { return fmarked_to_cancel_cache; }
1.9       paf        87: 
1.1       parser     88: private:
                     89: 
1.9       paf        90:        Value *get_field(const String& aname);
                     91:        void put_field(const String& aname, Value *avalue);
1.1       parser     92: 
                     93: private:
                     94: 
1.9       paf        95:        const String *fdb_home;
                     96:        const String *ffile_name;
1.7       parser     97:        bool fmarked_to_cancel_cache;
1.1       parser     98: 
1.7       parser     99: };
                    100: 
1.8       paf       101: ///    Auto-object used for temporary changing DB_Table::tid.
1.7       parser    102: class Autosave_marked_to_cancel_cache {
                    103:        VHashfile& fhashfile;
                    104:        bool saved;
                    105: public:
                    106:        Autosave_marked_to_cancel_cache(VHashfile& ahashfile) : 
                    107:                fhashfile(ahashfile), saved(ahashfile.fmarked_to_cancel_cache) {
                    108:        }
                    109:        ~Autosave_marked_to_cancel_cache() {
                    110:                fhashfile.fmarked_to_cancel_cache=saved;
                    111:        }
1.1       parser    112: };
                    113: 
                    114: #endif

E-mail: