Annotation of parser3/src/types/pa_vhashfile.C, revision 1.11
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.11 ! paf 7: $Id: pa_vhashfile.C,v 1.10 2001/10/25 13:17:54 paf 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.8 parser 21: void VHashfile::put_field(const String& aname, Value *avalue) {
22: time_t time_to_die=0;
23: const String *value_string;
24:
25: if(Hash *hash=avalue->get_hash(&aname)) {
26: if(Value *value_value=(Value *)hash->get(*value_name)) {
1.9 parser 27: if(value_value->get_junction())
1.8 parser 28: throw Exception(0, 0,
29: &value_value->name(),
30: "must not be code");
31:
32: value_string=&value_value->as_string();
33:
34: if(Value *expires_value=(Value *)hash->get(*expires_name))
35: time_to_die=time(0)+(time_t)expires_value->as_double();
36: } else
37: throw Exception(0, 0,
38: &aname,
39: "put hash value must contain .%s", VALUE_NAME);
40: } else
41: value_string=&avalue->as_string();
1.5 parser 42:
1.11 ! paf 43: get_table_ptr(&aname)->put(current_transaction, aname, *value_string, time_to_die);
1.1 parser 44: }
45:
1.11 ! paf 46: Value *VHashfile::get_field(const String& aname) {
! 47: if(String *string=get_table_ptr(&aname)->get(current_transaction, pool(), aname))
1.3 parser 48: return NEW VString(*string);
49: else
50: return 0;
1.1 parser 51: }
52:
1.4 parser 53: Hash *VHashfile::get_hash(const String *source) {
1.11 ! paf 54: DB_Cursor cursor(*get_table_ptr(source), current_transaction, source);
! 55:
1.4 parser 56: Hash& result=*NEW Hash(pool());
57:
58: while(true) {
1.5 parser 59: String *key;
60: String *data;
1.11 ! paf 61: if(!cursor.get(pool(), key, data, DB_NEXT))
1.4 parser 62: break;
63:
1.7 parser 64: if(key) // not expired
65: result.put(*key, NEW VString(*data));
1.4 parser 66: }
67:
68: return &result;
1.1 parser 69: }
70:
71: #endif
E-mail: