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

1.1       parser      1: /** @file
                      2:        Parser: @b hashfile parser type decl.
                      3: 
1.33      paf         4:        Copyright (c) 2001-2005 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.36    ! misha      11: static const char * const IDENT_VHASHFILE_H="$Date: 2007/04/20 10:17:57 $";
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.32      paf        50:        override const VJunction* 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.35      misha      61:        bool VHashfile::is_open();
1.24      paf        62:        void close();
1.35      misha      63:        void check_db();
                     64:        apr_sdbm_t *get_db_for_reading();
1.24      paf        65:        apr_sdbm_t *get_db_for_writing();
1.36    ! misha      66:        // void clear();
1.24      paf        67:        void delete_files();
1.19      paf        68:        void remove(const String& aname);
1.21      paf        69: 
1.35      misha      70:        void for_each(bool callback(apr_sdbm_datum_t, void*), void* info);
1.34      paf        71:        void for_each(bool callback(const String::Body, const String&, void*), void* info);
1.25      paf        72: 
                     73: public:
                     74: 
                     75:        void remove(const apr_sdbm_datum_t key);
                     76: 
                     77:        apr_sdbm_datum_t serialize_value(const String& string, time_t time_to_die) const;
                     78:        const String* deserialize_value(const apr_sdbm_datum_t key, const apr_sdbm_datum_t value);
1.9       paf        79: 
1.1       parser     80: private:
                     81: 
1.9       paf        82:        Value *get_field(const String& aname);
                     83:        void put_field(const String& aname, Value *avalue);
1.1       parser     84: 
                     85: private:
                     86: 
1.22      paf        87:        const char* file_name;
1.24      paf        88:        apr_sdbm_t *m_db;
1.17      paf        89: 
1.1       parser     90: };
                     91: 
                     92: #endif

E-mail: