Annotation of parser3/src/types/pa_vhashfile.C, revision 1.10

1.1       parser      1: /** @file
                      2:        Parser: @b table class.
                      3: 
                      4:        Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
                      5:        Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)
                      6: 
1.10    ! paf         7:        $Id: pa_vhashfile.C,v 1.9 2001/10/24 10:09:13 parser Exp $
1.1       parser      8: */
                      9: 
                     10: #include "pa_config_includes.h"
                     11: #ifdef HAVE_LIBDB
                     12: 
                     13: #include "pa_vtable.h"
                     14: #include "pa_vstring.h"
                     15: #include "pa_vhashfile.h"
                     16: #include "pa_threads.h"
1.8       parser     17: #include "pa_globals.h"
1.1       parser     18: 
                     19: // methods
                     20: 
1.3       parser     21: void VHashfile_cleanup(void *vhashfile) {
                     22:        //_asm int 3;
                     23:        static_cast<VHashfile *>(vhashfile)->cleanup();
1.1       parser     24: }
                     25: 
1.8       parser     26: void VHashfile::put_field(const String& aname, Value *avalue) {
                     27:        time_t time_to_die=0;
                     28:        const String *value_string;
                     29: 
                     30:        if(Hash *hash=avalue->get_hash(&aname)) {
                     31:                if(Value *value_value=(Value *)hash->get(*value_name)) {
1.9       parser     32:                        if(value_value->get_junction())
1.8       parser     33:                                throw Exception(0, 0,
                     34:                                        &value_value->name(),
                     35:                                        "must not be code");
                     36: 
                     37:                        value_string=&value_value->as_string();
                     38: 
                     39:                        if(Value *expires_value=(Value *)hash->get(*expires_name))
                     40:                                time_to_die=time(0)+(time_t)expires_value->as_double();
                     41:                } else
                     42:                        throw Exception(0, 0,
                     43:                                &aname,
                     44:                                "put hash value must contain .%s", VALUE_NAME);
                     45:        } else
                     46:                value_string=&avalue->as_string();
1.5       parser     47: 
1.10    ! paf        48:        get_table(&aname).put(aname, *value_string, time_to_die);
1.1       parser     49: }
                     50: 
                     51: Value *VHashfile::get_field(const String& name) {
1.10    ! paf        52:        if(String *string=get_table(&name).get(name))
1.3       parser     53:                return NEW VString(*string);
                     54:        else
                     55:                return 0;
1.1       parser     56: }
                     57: 
1.4       parser     58: Hash *VHashfile::get_hash(const String *source) {
                     59:        Hash& result=*NEW Hash(pool());
1.10    ! paf        60:        DB_Cursor cursor(get_table(source), source);
1.4       parser     61: 
                     62:        while(true) {
1.5       parser     63:                String *key;
                     64:                String *data;
1.4       parser     65:                if(!cursor.get(key, data, DB_NEXT))
                     66:                        break;
                     67: 
1.7       parser     68:                if(key) // not expired
                     69:                        result.put(*key, NEW VString(*data));
1.4       parser     70:        }
                     71: 
                     72:        return &result;
1.1       parser     73: }
                     74: 
                     75: #endif

E-mail: