Annotation of parser3/src/types/pa_vhash.h, revision 1.13

1.10      paf         1: /** @file
                      2:        Parser: @b hash parser type decl.
                      3: 
1.1       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.3       paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1       paf         6: 
1.13    ! paf         7:        $Id: pa_vhash.h,v 1.12 2001/05/07 14:00:54 paf Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef PA_VHASH_H
                     11: #define PA_VHASH_H
                     12: 
1.13    ! paf        13: #include "classes.h"
1.1       paf        14: #include "pa_value.h"
                     15: #include "pa_hash.h"
                     16: 
1.13    ! paf        17: extern Methoded *hash_base_class;
        !            18: 
1.11      paf        19: /// value of type 'hash', implemented with Hash
1.13    ! paf        20: class VHash : public VStateless_class {
1.1       paf        21: public: // value
                     22: 
1.2       paf        23:        const char *type() const { return "hash"; }
1.1       paf        24: 
1.11      paf        25:        /// VHash: fhash
1.8       paf        26:        Hash *get_hash() { return &fhash; }
1.7       paf        27: 
1.11      paf        28:        /// VHash: (key)=value
1.1       paf        29:        Value *get_element(const String& name) { 
1.13    ! paf        30:                // $CLASS,$BASE,$method
        !            31:                if(Value *result=VStateless_class::get_element(name))
        !            32:                        return result;
        !            33: 
        !            34:                // $element
        !            35:                Value *result=static_cast<Value *>(fhash.get(name));
        !            36:                return result?result:fdefault;
1.1       paf        37:        }
                     38:        
1.11      paf        39:        /// VHash: (key)=value
1.1       paf        40:        void put_element(const String& name, Value *value) { 
1.5       paf        41:                fhash.put(name, value);
1.1       paf        42:        }
                     43: 
                     44: public: // usage
                     45: 
1.13    ! paf        46:        VHash(Pool& apool) : VStateless_class(apool, hash_base_class), 
        !            47:                fhash(apool), 
        !            48:                fdefault(0) {
        !            49:        }
1.7       paf        50: 
                     51:        Hash& hash() { return fhash; }
1.1       paf        52: 
1.13    ! paf        53:        void set_default(Value& adefault) { fdefault=&adefault; }
        !            54:        Value *get_default() { return fdefault; }
        !            55: 
1.1       paf        56: private:
1.6       paf        57: 
1.9       paf        58:        Hash fhash;
1.13    ! paf        59:        Value *fdefault;
1.6       paf        60: 
1.1       paf        61: };
                     62: 
                     63: #endif

E-mail: