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

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.8     ! paf         7:        $Id: pa_vhashfile.h,v 1.7 2001/10/24 11:06: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.8     ! paf        17: #include "pa_db_table.h"
1.1       parser     18: 
1.7       parser     19: // externs
                     20: 
1.3       parser     21: extern Methoded *hashfile_base_class;
1.1       parser     22: 
1.7       parser     23: // forwards
                     24: 
                     25: class Autosave_marked_to_cancel_cache ;
                     26: 
1.1       parser     27: /// value of type 'hashfile', implemented with GDBM library
                     28: class VHashfile : public VStateless_class {
1.2       parser     29:        friend void VHashfile_cleanup(void *);
1.7       parser     30:        friend Autosave_marked_to_cancel_cache ;
1.1       parser     31: public: // value
                     32: 
                     33:        const char *type() const { return "hashfile"; }
                     34: 
                     35:        /// VHashfile: true
                     36:        bool is_defined() const { return true; }
                     37: 
                     38:        /// VHashfile: convert to VHash
1.4       parser     39:        Hash *get_hash(const String *source);
1.1       parser     40: 
                     41:        /// VHashfile: 0
                     42:        VStateless_class *get_class() { return 0; }
                     43: 
                     44:        /// VHashfile: (key)=value
                     45:        Value *get_element(const String& name) { 
                     46:                // $CLASS,$method
                     47:                if(Value *result=VStateless_class::get_element(name))
                     48:                        return result;
                     49:                
                     50:                // $element
                     51:                return get_field(name);
                     52:        }
                     53:        
1.5       parser     54:        /// VHashfile: (key)=value, (key)=(value+expires)
1.6       parser     55:        void put_element(const String& name, Value *value) {
                     56:                put_field(name, value);
                     57:        }
1.1       parser     58: 
                     59: public: // usage
                     60: 
1.3       parser     61:        VHashfile(Pool& apool) : VStateless_class(apool, hashfile_base_class),
1.8     ! paf        62:                ftable(0), fmarked_to_cancel_cache(false) {
1.2       parser     63:                register_cleanup(VHashfile_cleanup, this);
1.1       parser     64:        }
1.2       parser     65: private:
                     66:        void cleanup() {
1.8     ! paf        67:                if(ftable)
        !            68:                        ftable->close();  // cache it
1.1       parser     69:        }
1.2       parser     70: public:
1.1       parser     71: 
1.8     ! paf        72:        void set_table(DB_Table& atable) { ftable=&atable; }
        !            73:        DB_Table& get_table(const String *source) const { 
        !            74:                if(!ftable)
1.1       parser     75:                        throw Exception(0, 0,
                     76:                                source,
                     77:                                "can not be applied to uninitialized instance");
                     78: 
1.8     ! paf        79:                return *ftable;
1.1       parser     80:        }
                     81: 
1.7       parser     82:        void mark_to_cancel_cache() { fmarked_to_cancel_cache=true; }
                     83:        bool marked_to_cancel_cache() { return fmarked_to_cancel_cache; }
                     84: 
1.1       parser     85: private:
                     86: 
                     87:        Value *get_field(const String& name);
1.6       parser     88:        void put_field(const String& name, Value *value);
1.1       parser     89: 
                     90: private:
                     91: 
1.8     ! paf        92:        DB_Table *ftable;
1.7       parser     93:        bool fmarked_to_cancel_cache;
1.1       parser     94: 
1.7       parser     95: };
                     96: 
1.8     ! paf        97: ///    Auto-object used for temporary changing DB_Table::tid.
1.7       parser     98: class Autosave_marked_to_cancel_cache {
                     99:        VHashfile& fhashfile;
                    100:        bool saved;
                    101: public:
                    102:        Autosave_marked_to_cancel_cache(VHashfile& ahashfile) : 
                    103:                fhashfile(ahashfile), saved(ahashfile.fmarked_to_cancel_cache) {
                    104:        }
                    105:        ~Autosave_marked_to_cancel_cache() {
                    106:                fhashfile.fmarked_to_cancel_cache=saved;
                    107:        }
1.1       parser    108: };
                    109: 
                    110: #endif

E-mail: