Annotation of parser3/src/types/pa_vhashfile.C, revision 1.19
1.1 parser 1: /** @file
2: Parser: @b table class.
3:
1.18 paf 4: Copyright(c) 2001, 2002 ArtLebedev Group(http://www.artlebedev.com)
1.19 ! paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 parser 6:
1.19 ! paf 7: $Id: pa_vhashfile.C,v 1.18 2002/02/08 07:27:53 paf Exp $
1.1 parser 8: */
9:
10: #include "pa_config_includes.h"
1.12 paf 11: #ifdef DB2
1.1 parser 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.17 paf 43: get_table_ptr(&aname)->put(aname, *value_string, time_to_die);
1.1 parser 44: }
45:
1.11 paf 46: Value *VHashfile::get_field(const String& aname) {
1.17 paf 47: if(String *string=get_table_ptr(&aname)->get(pool(), aname, 0))
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.17 paf 54: DB_Cursor cursor(*get_table_ptr(source), source);
1.11 paf 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.13 paf 64: if(!key)
65: continue; // expired
66:
67: result.put(*key, NEW VString(*data));
1.4 parser 68: }
69:
70: return &result;
1.1 parser 71: }
72:
73: #endif
E-mail: