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

1.1       parser      1: /** @file
                      2:        Parser: @b hashfile parser type decl.
                      3: 
1.51      moko        4:        Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.49      moko        5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1       parser      6: */
                      7: 
                      8: #ifndef PA_VHASHFILE_H
                      9: #define PA_VHASHFILE_H
                     10: 
1.53    ! moko       11: #define IDENT_PA_VHASHFILE_H "$Id: pa_vhashfile.h,v 1.52 2026/10/09 20:14:28 moko Exp $"
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: 
1.39      moko       19: #include "pa_sdbm.h"
1.17      paf        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: 
1.41      misha      39:        override HashStringValue* get_fields() { return get_hash(); }
                     40: 
1.1       parser     41:        /// VHashfile: (key)=value
1.38      misha      42:        override Value* get_element(const String& aname) { 
1.53    ! moko       43:                MAYBE_GET_SPECIAL_OR_METHOD(VStateless_object::get_element(aname));
        !            44: 
1.1       parser     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.43      moko       50:        override const VJunction* put_element(const String& aname, Value* avalue) {
1.17      paf        51:                put_field(aname, avalue);
1.42      moko       52:                return 0; // nobody is supposed to derive from hashfile, so does not matter
1.6       parser     53:        }
1.1       parser     54: 
                     55: public: // usage
                     56: 
1.52      moko       57:        VHashfile(Pool& apool): Pooled(apool), file_name(0), 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();
1.37      misha      62:        bool is_open();
1.39      moko       63:        pa_sdbm_t *get_db_for_reading();
                     64:        pa_sdbm_t *get_db_for_writing();
1.36      misha      65:        // void clear();
1.24      paf        66:        void delete_files();
1.19      paf        67:        void remove(const String& aname);
1.21      paf        68: 
1.39      moko       69:        void for_each(bool callback(pa_sdbm_datum_t, void*), void* info);
1.34      paf        70:        void for_each(bool callback(const String::Body, const String&, void*), void* info);
1.25      paf        71: 
                     72: public:
                     73: 
1.39      moko       74:        void remove(const pa_sdbm_datum_t key);
1.25      paf        75: 
1.39      moko       76:        pa_sdbm_datum_t serialize_value(const String& string, time_t time_to_die) const;
                     77:        const String* deserialize_value(const pa_sdbm_datum_t key, const pa_sdbm_datum_t value);
1.9       paf        78: 
1.46      moko       79:        void check(const char *step, pa_status_t status);
                     80: 
1.1       parser     81: private:
                     82: 
1.9       paf        83:        Value *get_field(const String& aname);
                     84:        void put_field(const String& aname, Value *avalue);
1.1       parser     85: 
                     86: private:
                     87: 
1.22      paf        88:        const char* file_name;
1.39      moko       89:        pa_sdbm_t *m_db;
1.17      paf        90: 
1.1       parser     91: };
                     92: 
                     93: #endif

E-mail: