Annotation of parser3/src/types/pa_vhashfile.C, revision 1.22
1.1 parser 1: /** @file
2: Parser: @b table class.
3:
1.20 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: */
7:
1.22 ! paf 8: static const char* IDENT="$Date: 2003/07/24 11:31:27 $";
1.1 parser 9:
10: #include "pa_vtable.h"
11: #include "pa_vstring.h"
12: #include "pa_vhashfile.h"
13: #include "pa_threads.h"
1.8 parser 14: #include "pa_globals.h"
1.1 parser 15:
16: // methods
17:
1.22 ! paf 18: void check(const char *step, apr_status_t status) {
! 19: if(status==APR_SUCCESS)
! 20: return;
! 21:
! 22: throw Exception("todo.todo",
! 23: 0,
! 24: "%s error: %d", step, status);
! 25: }
! 26:
! 27: void VHashfile::open(const String& afile_name) {
! 28: check("apr_sdbm_open", apr_sdbm_open(&db, afile_name.cstr(String::L_FILE_SPEC),
! 29: APR_WRITE|APR_CREATE,
! 30: 0664, 0));
! 31: }
! 32:
! 33: VHashfile::~VHashfile() {
! 34: if(db)
! 35: check("apr_sdbm_close", apr_sdbm_close(db));
! 36: }
! 37:
! 38: void VHashfile::clear() {
! 39: }
! 40:
1.8 parser 41: void VHashfile::put_field(const String& aname, Value *avalue) {
1.22 ! paf 42: #if LATER
1.8 parser 43: time_t time_to_die=0;
44: const String *value_string;
45:
1.22 ! paf 46: if(HashStringValue *hash=avalue->get_hash(&aname)) {
1.8 parser 47: if(Value *value_value=(Value *)hash->get(*value_name)) {
1.9 parser 48: if(value_value->get_junction())
1.8 parser 49: throw Exception(0, 0,
50: &value_value->name(),
51: "must not be code");
52:
53: value_string=&value_value->as_string();
54:
55: if(Value *expires_value=(Value *)hash->get(*expires_name))
56: time_to_die=time(0)+(time_t)expires_value->as_double();
57: } else
58: throw Exception(0, 0,
59: &aname,
60: "put hash value must contain .%s", VALUE_NAME);
61: } else
62: value_string=&avalue->as_string();
1.5 parser 63:
1.17 paf 64: get_table_ptr(&aname)->put(aname, *value_string, time_to_die);
1.22 ! paf 65: #endif
1.1 parser 66: }
67:
1.11 paf 68: Value *VHashfile::get_field(const String& aname) {
1.22 ! paf 69: #if LATER
1.17 paf 70: if(String *string=get_table_ptr(&aname)->get(pool(), aname, 0))
1.3 parser 71: return NEW VString(*string);
72: else
73: return 0;
1.22 ! paf 74: #endif
! 75: return 0;
1.1 parser 76: }
77:
1.22 ! paf 78: HashStringValue *VHashfile::get_hash(const String *source) {
! 79: #if LATER
1.17 paf 80: DB_Cursor cursor(*get_table_ptr(source), source);
1.11 paf 81:
1.22 ! paf 82: HashStringValue& result=*NEW HashStringValue(pool());
1.4 parser 83:
84: while(true) {
1.5 parser 85: String *key;
86: String *data;
1.11 paf 87: if(!cursor.get(pool(), key, data, DB_NEXT))
1.4 parser 88: break;
89:
1.13 paf 90: if(!key)
91: continue; // expired
92:
93: result.put(*key, NEW VString(*data));
1.4 parser 94: }
95:
96: return &result;
1.22 ! paf 97: #endif
! 98: return 0;
1.1 parser 99: }
E-mail: