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

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.11    ! paf         7:        $Id: pa_vhashfile.h,v 1.10 2001/10/29 08:23: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:                current_transaction(0), 
                     65:                fmarked_to_cancel_cache(false) {
1.1       parser     66:        }
1.9       paf        67: 
                     68:        void assign(const String& adb_home, const String& afile_name) { 
                     69:                fdb_home=&adb_home;
                     70:                ffile_name=&afile_name;
1.1       parser     71:        }
1.9       paf        72:        DB_Table_ptr get_table_ptr(const String *source) {
                     73:                if(!fdb_home)
1.1       parser     74:                        throw Exception(0, 0,
                     75:                                source,
                     76:                                "can not be applied to uninitialized instance");
                     77: 
1.9       paf        78:                return 
                     79:                        DB_manager->
                     80:                        get_connection_ptr(*fdb_home, source)->
                     81:                        get_table_ptr(*ffile_name, source);
1.1       parser     82:        }
                     83: 
1.11    ! paf        84:        void mark_to_cancel_cache() { 
        !            85:                if(current_transaction) // do something only inside of ^cache
        !            86:                        fmarked_to_cancel_cache=true; 
        !            87:        }
1.7       parser     88:        bool marked_to_cancel_cache() { return fmarked_to_cancel_cache; }
                     89: 
1.9       paf        90: public:
                     91: 
                     92:        DB_Transaction *current_transaction;
                     93: 
1.1       parser     94: private:
                     95: 
1.9       paf        96:        Value *get_field(const String& aname);
                     97:        void put_field(const String& aname, Value *avalue);
1.1       parser     98: 
                     99: private:
                    100: 
1.9       paf       101:        const String *fdb_home;
                    102:        const String *ffile_name;
1.7       parser    103:        bool fmarked_to_cancel_cache;
1.1       parser    104: 
1.7       parser    105: };
                    106: 
1.8       paf       107: ///    Auto-object used for temporary changing DB_Table::tid.
1.7       parser    108: class Autosave_marked_to_cancel_cache {
                    109:        VHashfile& fhashfile;
                    110:        bool saved;
                    111: public:
                    112:        Autosave_marked_to_cancel_cache(VHashfile& ahashfile) : 
                    113:                fhashfile(ahashfile), saved(ahashfile.fmarked_to_cancel_cache) {
                    114:        }
                    115:        ~Autosave_marked_to_cancel_cache() {
                    116:                fhashfile.fmarked_to_cancel_cache=saved;
                    117:        }
1.1       parser    118: };
                    119: 
                    120: #endif

E-mail: