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