Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

cxx_seq.cpp

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: cxx_seq.cpp,v 12.2 2005/10/13 20:49:47 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #include <errno.h>
00013 #include <string.h>
00014 
00015 #include "db_cxx.h"
00016 #include "dbinc/cxx_int.h"
00017 
00018 #include "db_int.h"
00019 
00020 // Helper macro for simple methods that pass through to the
00021 // underlying C method. It may return an error or raise an exception.
00022 // Note this macro expects that input _argspec is an argument
00023 // list element (e.g., "char *arg") and that _arglist is the arguments
00024 // that should be passed through to the C method (e.g., "(db, arg)")
00025 //
00026 #define DBSEQ_METHOD(_name, _argspec, _arglist, _destructor)            \
00027 int DbSequence::_name _argspec                                          \
00028 {                                                                       \
00029         int ret;                                                        \
00030         DB_SEQUENCE *seq = unwrap(this);                                \
00031         DbEnv *dbenv = DbEnv::get_DbEnv(seq->seq_dbp->dbenv);           \
00032                                                                         \
00033         ret = seq->_name _arglist;                                      \
00034         if (_destructor)                                                \
00035                 imp_ = 0;                                               \
00036         if (!DB_RETOK_STD(ret))                                         \
00037                 DB_ERROR(dbenv,                                         \
00038                     "DbSequence::" # _name, ret, ON_ERROR_UNKNOWN);     \
00039         return (ret);                                                   \
00040 }
00041 
00042 DbSequence::DbSequence(Db *db, u_int32_t flags)
00043 :       imp_(0)
00044 {
00045         DB_SEQUENCE *seq;
00046         int ret;
00047 
00048         if ((ret = db_sequence_create(&seq, unwrap(db), flags)) != 0)
00049                 DB_ERROR(db->get_env(), "DbSequence::DbSequence", ret,
00050                     ON_ERROR_UNKNOWN);
00051         else {
00052                 imp_ = seq;
00053                 seq->api_internal = this;
00054         }
00055 }
00056 
00057 DbSequence::DbSequence(DB_SEQUENCE *seq)
00058 :       imp_(seq)
00059 {
00060         seq->api_internal = this;
00061 }
00062 
00063 DbSequence::~DbSequence()
00064 {
00065         DB_SEQUENCE *seq;
00066 
00067         seq = unwrap(this);
00068         if (seq != NULL)
00069                 (void)seq->close(seq, 0);
00070 }
00071 
00072 DBSEQ_METHOD(open, (DbTxn *txnid, Dbt *key, u_int32_t flags),
00073     (seq, unwrap(txnid), key, flags), 0)
00074 DBSEQ_METHOD(initial_value, (db_seq_t value), (seq, value), 0)
00075 DBSEQ_METHOD(close, (u_int32_t flags), (seq, flags), 1)
00076 DBSEQ_METHOD(remove, (DbTxn *txnid, u_int32_t flags),
00077     (seq, unwrap(txnid), flags), 1)
00078 DBSEQ_METHOD(stat, (DB_SEQUENCE_STAT **sp, u_int32_t flags),
00079     (seq, sp, flags), 0)
00080 DBSEQ_METHOD(stat_print, (u_int32_t flags), (seq, flags), 0)
00081 
00082 DBSEQ_METHOD(get,
00083     (DbTxn  *txnid, int32_t delta, db_seq_t *retp, u_int32_t flags),
00084     (seq, unwrap(txnid), delta, retp, flags), 0)
00085 DBSEQ_METHOD(get_cachesize, (int32_t *sizep), (seq, sizep), 0)
00086 DBSEQ_METHOD(set_cachesize, (int32_t size), (seq, size), 0)
00087 DBSEQ_METHOD(get_flags, (u_int32_t *flagsp), (seq, flagsp), 0)
00088 DBSEQ_METHOD(set_flags, (u_int32_t flags), (seq, flags), 0)
00089 DBSEQ_METHOD(get_range, (db_seq_t *minp, db_seq_t *maxp), (seq, minp, maxp), 0)
00090 DBSEQ_METHOD(set_range, (db_seq_t min, db_seq_t max), (seq, min, max), 0)
00091 
00092 Db *DbSequence::get_db()
00093 {     
00094         DB_SEQUENCE *seq = unwrap(this);
00095         DB *db;
00096         (void)seq->get_db(seq, &db);
00097         return Db::get_Db(db);
00098 } 
00099 
00100 Dbt *DbSequence::get_key()
00101 {     
00102         DB_SEQUENCE *seq = unwrap(this);
00103         memset(&key_, 0, sizeof (DBT));
00104         (void)seq->get_key(seq, &key_);
00105         return Dbt::get_Dbt(&key_);
00106 } 
00107 
00108 // static method
00109 DbSequence *DbSequence::wrap_DB_SEQUENCE(DB_SEQUENCE *seq)
00110 {
00111         DbSequence *wrapped_seq = get_DbSequence(seq);
00112         return (wrapped_seq != NULL) ? wrapped_seq : new DbSequence(seq);
00113 }

Generated on Sun Dec 25 12:14:18 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2