ANN: BDB++ 0.99b released

A

Ahn Ki-yung

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
}}}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top