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

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.10    ! paf         7:        $Id: pa_vhashfile.h,v 1.9 2001/10/26 13:48:19 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.7       parser     84:        void mark_to_cancel_cache() { fmarked_to_cancel_cache=true; }
                     85:        bool marked_to_cancel_cache() { return fmarked_to_cancel_cache; }
                     86: 
1.9       paf        87: public:
                     88: 
                     89:        DB_Transaction *current_transaction;
                     90: 
1.1       parser     91: private:
                     92: 
1.9       paf        93:        Value *get_field(const String& aname);
                     94:        void put_field(const String& aname, Value *avalue);
1.1       parser     95: 
                     96: private:
                     97: 
1.9       paf        98:        const String *fdb_home;
                     99:        const String *ffile_name;
1.7       parser    100:        bool fmarked_to_cancel_cache;
1.1       parser    101: 
1.7       parser    102: };
                    103: 
1.8       paf       104: ///    Auto-object used for temporary changing DB_Table::tid.
1.7       parser    105: class Autosave_marked_to_cancel_cache {
                    106:        VHashfile& fhashfile;
                    107:        bool saved;
                    108: public:
                    109:        Autosave_marked_to_cancel_cache(VHashfile& ahashfile) : 
                    110:                fhashfile(ahashfile), saved(ahashfile.fmarked_to_cancel_cache) {
                    111:        }
                    112:        ~Autosave_marked_to_cancel_cache() {
                    113:                fhashfile.fmarked_to_cancel_cache=saved;
                    114:        }
1.1       parser    115: };
                    116: 
                    117: #endif

E-mail: