ANN: BDB++ 0.99b released

Discussion in 'C++' started by Ahn Ki-yung, May 6, 2004.

  1. Ahn Ki-yung

    Ahn Ki-yung Guest

    Hello! It is a pleasure to release the BDB++ library
    again, with the idioms supoorting secondary indexes.
    Happy Berkeley DB programming in C++ with BDB++!

    == Abstract ==
    BDB++ is a C++ Standard Library style API built on top of the Berkeley
    DB C++ API. BDB++ allows programmers to utilize Berkeley DB within the
    C++ Standard Library framework.

    == Motive ==
    If you are a C++ programmer with C++ Standard Library background and you
    have an experience of Berkeley DB programming, I am sure that you had
    wished for a cozy C++ Standard Library container/iterator style
    interface for the Berkeley DB. Conceptually, it is clear that the
    Berkeley DB database is a container and the cursor to the database is an
    iterator. However, there weren't such libraries available, as far as I
    have searched for. As a result, I decied to make one: BDB++. Enjoy!

    == Websites ==

    Visit the BDB++ project websites for more information.
    We welcome your participations or suggestions.

    Sourcforge Project Summary

    http://sf.net/projects/bdbplusplus

    Project Homepage

    http://bdbplusplus.sf.net/

    == Examples ==
    These are examples inlcluded in the recent distribution.
    === bdbmap ===
    {{{#!vim cpp
    #include <iostream>
    #include "bdbmap.hpp"

    using namespace std;
    using namespace bdbplusplus;

    typedef bdbmap<int, int> bdbcont;

    int main(void)
    {
    u_int32_t DBENV_ctor_flag = 0;
    u_int32_t DBENV_open_flag = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE;

    DbEnv dbenv(DBENV_ctor_flag);

    try {
    dbenv.set_error_stream(&cerr);
    dbenv.open("./db_home",DBENV_open_flag,0644);

    try {
    bdbcont cppdb(&dbenv);

    for (int i=0; i<5; i++) cppdb.insert(make_pair(i,i+1));

    for (bdbcont::iterator i=cppdb.begin(); i!=cppdb.end(); ++i)
    cout <<(*i).first <<"," <<i->second <<endl;

    cppdb.insert(make_pair(1,1));
    cppdb.insert(make_pair(1,3));
    cppdb.insert(make_pair(11,4));

    for (bdbcont::reverse_iterator i=cppdb.rbegin(); i!=cppdb.rend(); ++i)
    cout <<(*i).first <<"," <<i->second <<endl;

    } catch (DbMemoryException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (DbException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (...) { dbenv.errx("Unknown exception!"); }
    dbenv.close(0);
    } catch (DbMemoryException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (DbException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (...) { dbenv.errx("Unknown exception!");
    }

    return 0;
    }
    }}}

    Output

    {{{
    0,1
    1,2
    2,3
    3,4
    4,5
    11,4
    4,5
    3,4
    2,3
    1,2
    0,1
    }}}
    === bdbmultimap ===
    {{{#!vim cpp
    #include <iostream>
    #include "bdbmultimap.hpp"

    using namespace std;
    using namespace bdbplusplus;

    typedef bdbmultimap<int, int> bdbcont;

    int main(void)
    {
    u_int32_t DBENV_ctor_flag = 0;
    u_int32_t DBENV_open_flag = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE;

    DbEnv dbenv(DBENV_ctor_flag);

    try {
    dbenv.set_error_stream(&cerr);
    dbenv.open("./db_home",DBENV_open_flag,0644);

    try {
    bdbcont cppdb(&dbenv,0,
    DbMultiMapSortConfig<
    DbtCompareType<int>::less ,
    DbtCompareType<int>::less >()
    );

    for (int i=0; i<5; i++) cppdb.insert(make_pair(i,i+1));

    for (bdbcont::iterator i=cppdb.begin(); i!=cppdb.end(); ++i)
    cout <<(*i).first <<"," <<i->second <<endl;

    cppdb.insert(make_pair(1,1));
    cppdb.insert(make_pair(1,3));
    cppdb.insert(make_pair(11,4));

    for (bdbcont::reverse_iterator i=cppdb.rbegin(); i!=cppdb.rend(); ++i)
    cout <<(*i).first <<"," <<i->second <<endl;

    } catch (DbMemoryException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (DbException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (...) { dbenv.errx("Unknown exception!");
    }
    dbenv.close(0);
    } catch (DbMemoryException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (DbException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (...) { dbenv.errx("Unknown exception!");
    }

    return 0;
    }
    }}}

    Output

    {{{
    0,1
    1,2
    2,3
    3,4
    4,5
    11,4
    4,5
    3,4
    2,3
    1,3
    1,2
    1,1
    0,1
    }}}

    === secondary index ===
    {{{#!vim cpp
    #include <iostream>

    #include "bdbmap.hpp"
    #include "bdbmultimap.hpp"

    using namespace std;
    using namespace bdbplusplus;

    struct Data
    {
    int company;
    int salary;
    Data(int c=0, int s=0) : company(c), salary(s) { }
    };

    typedef bdbmap<int, Data> bdbcont;
    typedef IndexTypeDef<int, Data, int>::bdbmultimap bdbindex;

    template <>
    const int& MakeIndex<int, Data, int>::eek:perator()(const int& k, const
    Data& d)
    { return *(const int*)(&d); }

    int main(void)
    {
    u_int32_t DBENV_ctor_flag = 0;
    u_int32_t DBENV_open_flag = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE;

    DbEnv dbenv(DBENV_ctor_flag);

    try {
    dbenv.set_error_stream(&cerr);
    dbenv.open("./db_home",DBENV_open_flag,0644);

    try {
    bdbcont cppdb(&dbenv);
    bdbindex cppidx(&dbenv, 0,
    IndexConfig <
    DbMultiMapConfig<bdbindex::comp_type,
    bdbindex::cast_type>,
    bdbcont >(cppdb) );

    for (int i=0; i<10; i++) cppdb.insert(make_pair(i,Data(i%3,i+100)));
    for (bdbcont::iterator i=cppdb.begin(); i!=cppdb.end(); ++i)
    cout <<(*i).first <<","
    <<i->second.company <<',' <<i->second.salary <<endl;
    cout <<endl;
    for (bdbindex::iterator i=cppidx.begin(); i!=cppidx.end(); ++i)
    cout <<(*i).first <<"," <<i->pkey <<','
    <<i->second.company <<',' <<i->second.salary <<endl;
    cout <<endl;
    pair<bdbindex::iterator,bdbindex::iterator> p=cppidx.equal_range(2);
    for (bdbindex::iterator i=p.first; i!=p.second; ++i)
    cout <<(*i).first <<"," <<i->pkey <<','
    <<i->second.company <<',' <<i->second.salary <<endl;

    } catch (DbMemoryException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (DbException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (...) { dbenv.errx("Unknown exception!");
    }
    dbenv.close(0);
    } catch (DbMemoryException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (DbException& e) { dbenv.err(e.get_errno(),"prefix");
    } catch (...) { dbenv.errx("Unknown exception!");
    }

    return 0;
    }
    }}}

    Output

    {{{
    0,0,100
    1,1,101
    2,2,102
    3,0,103
    4,1,104
    5,2,105
    6,0,106
    7,1,107
    8,2,108
    9,0,109

    0,0,0,100
    0,3,0,103
    0,6,0,106
    0,9,0,109
    1,1,1,101
    1,4,1,104
    1,7,1,107
    2,2,2,102
    2,5,2,105
    2,8,2,108

    2,2,2,102
    2,5,2,105
    2,8,2,108
    }}}

    --
    Ahn Ki-yung
    http://bawi.org/~kyagrd/
     
    Ahn Ki-yung, May 6, 2004
    #1
    1. Advertising

  2. Ahn Ki-yung

    Volker Lukas Guest

    Volker Lukas, May 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahn Ki-yung

    ANN: BDB++ 1.0 release

    Ahn Ki-yung, Jan 26, 2005, in forum: C++
    Replies:
    0
    Views:
    331
    Ahn Ki-yung
    Jan 26, 2005
  2. Ahn Ki-yung

    ANN: BDB++ 1.1 release

    Ahn Ki-yung, Apr 5, 2005, in forum: C++
    Replies:
    0
    Views:
    345
    Ahn Ki-yung
    Apr 5, 2005
  3. Emiliano Heyns

    Installer for BDB 4.1.25/BDBXML 1.1.0

    Emiliano Heyns, Oct 9, 2003, in forum: Python
    Replies:
    2
    Views:
    328
    Emiliano
    Oct 16, 2003
  4. Philippe C. Martin

    BDB frontend problem

    Philippe C. Martin, Nov 10, 2004, in forum: Python
    Replies:
    0
    Views:
    334
    Philippe C. Martin
    Nov 10, 2004
  5. Philippe C. Martin

    bdb question

    Philippe C. Martin, Dec 16, 2004, in forum: Python
    Replies:
    0
    Views:
    368
    Philippe C. Martin
    Dec 16, 2004
Loading...

Share This Page