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

1.1       parser      1: /** @file
                      2:        Parser: @b hashfile parser type decl.
                      3: 
1.27      paf         4:        Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.15      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       parser      6: */
                      7: 
                      8: #ifndef PA_VHASHFILE_H
                      9: #define PA_VHASHFILE_H
                     10: 
1.31    ! paf        11: static const char * const IDENT_VHASHFILE_H="$Date: 2005/07/28 10:02:27 $";
1.17      paf        12: 
1.1       parser     13: #include "classes.h"
1.23      paf        14: #include "pa_pool.h"
1.1       parser     15: #include "pa_value.h"
                     16: #include "pa_hash.h"
                     17: #include "pa_vint.h"
1.17      paf        18: 
                     19: #include "apr_sdbm.h"
                     20: 
                     21: // defines
                     22: 
                     23: #define VHASHFILE_TYPE "hashfile"
1.1       parser     24: 
1.7       parser     25: // externs
                     26: 
1.17      paf        27: extern Methoded *hashfile_class;
1.1       parser     28: 
1.17      paf        29: /// value of type 'hashfile', implemented with SDBM library bundled in ../libs/sdbm
1.23      paf        30: class VHashfile : public VStateless_object, Pooled {
1.1       parser     31: public: // value
                     32: 
1.17      paf        33:        override const char *type() const { return VHASHFILE_TYPE; }
                     34:        override VStateless_class *get_class() { return hashfile_class; }
1.1       parser     35: 
                     36:        /// VHashfile: convert to VHash
1.20      paf        37:        override HashStringValue *get_hash();
1.1       parser     38: 
                     39:        /// VHashfile: (key)=value
1.17      paf        40:        override Value* get_element(const String& aname, Value& aself, bool looking_up) { 
1.1       parser     41:                // $CLASS,$method
1.17      paf        42:                if(Value *result=VStateless_object::get_element(aname, aself, looking_up))
1.1       parser     43:                        return result;
                     44:                
                     45:                // $element
1.17      paf        46:                return get_field(aname);
1.1       parser     47:        }
                     48:        
1.5       parser     49:        /// VHashfile: (key)=value, (key)=(value+expires)
1.31    ! paf        50:        override const Junction* put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*replace*/) { 
1.17      paf        51:                put_field(aname, avalue);
                     52:                return false; // nobody is supposed to derive from hashfile, so does not matter
1.6       parser     53:        }
1.1       parser     54: 
                     55: public: // usage
                     56: 
1.24      paf        57:        VHashfile(Pool& apool): Pooled(apool), m_db(0) {}
1.18      paf        58:        override ~VHashfile();
1.9       paf        59: 
1.17      paf        60:        void open(const String& afile_name);
1.24      paf        61:        void close();
                     62:        void check_db() const;
                     63:        apr_sdbm_t *get_db_for_reading() const;
                     64:        apr_sdbm_t *get_db_for_writing();
1.17      paf        65:        void clear();
1.24      paf        66:        void delete_files();
1.19      paf        67:        void remove(const String& aname);
1.21      paf        68: 
1.22      paf        69:        void for_each(void callback(apr_sdbm_datum_t, void*), void* info) const;
1.25      paf        70:        void for_each(void callback(const String::Body, const String&, void*), void* info);
                     71: 
                     72: public:
                     73: 
                     74:        void remove(const apr_sdbm_datum_t key);
                     75: 
                     76:        apr_sdbm_datum_t serialize_value(const String& string, time_t time_to_die) const;
                     77:        const String* deserialize_value(const apr_sdbm_datum_t key, const apr_sdbm_datum_t value);
1.9       paf        78: 
1.1       parser     79: private:
                     80: 
1.9       paf        81:        Value *get_field(const String& aname);
                     82:        void put_field(const String& aname, Value *avalue);
1.1       parser     83: 
                     84: private:
                     85: 
1.22      paf        86:        const char* file_name;
1.24      paf        87:        apr_sdbm_t *m_db;
1.17      paf        88: 
1.1       parser     89: };
                     90: 
                     91: #endif

E-mail: