Skip to content

Instantly share code, notes, and snippets.

View berkeley-db's full-sized avatar

Dave Segleau berkeley-db

View GitHub Profile
typedef dbstl::db_map<const char *, Car> owner_car_map_t; // (1)
owner_car_map_t ocmap;
while (has more owner-car pairs to input) {
// Accept input data for owner name and car, create car.
cin>>owner>>len>>width>>height>>hp>>ncyl>>displ;
Engine *pEngine = new Engine(hp, ncyl, displ);
Car car(len, width, height, pEngine);
ocmap[owner.c_str()] = car; // (2)
u_int32_t CarSize(const Car &car) // (3)
{
return sizeof(length) * 3 + model.length() + 1 +
sizeof(*engine); // (4)
}
void CopyCar(void *dest, const Car&car) // (5)
{
// Copy all bytes of the car object into memory chunk M
// referenced by dest.
class Car {
size_t length, width, height;
Engine *engine;
string model;
// Member functions follow ...
};
class Engine {
size_t horse_power;
typedef std::map<const char *, Car> owner_car_map_t;
owner_car_map_t ocmap;
while (has more owner-car pairs to input) {
// Accept input data for owner name and car, create car.
cin>>owner>>len>>width>>height>>hp>>ncyl>>displ;
Engine *pEngine = new Engine(hp, ncyl, displ);
Car car(len, width, height, pEngine);
ocmap[owner.c_str()] = car;
for(dbl_vec_t::iterator itr = v1.begin(); itr != v1.end(); ++itr)
*itr *= 2;
for (int i = 0; i < v1.size(); i++)
v1[i] += 3;
v1.swap(v2); // Swap the vector's contents.
v2 = v1; // Assign one vector to another.
assert(v1 == v2);
std::reverse(v1.begin(), v1.end());
#include "db_map.h" // Berkeley DB's STL Map support
using namespace dbstl;
main()
{
std::string key = "hello";
int value = 1234;
Db *dbp = NULL;
DbEnv *envp = NULL;
int vector_test(int, char**)
{
typedef dbstl::db_vector <double, ElementHolder<double> > dbl_vec_t;
DbEnv *penv = new DbEnv(DB_CXX_NO_EXCEPTIONS); // (2)
penv->open("dbenv",
flags | DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0777); // (3)
pdb = dbstl::open_db(penv, "vector2.db",
DB_RECNO, DB_CREATE | dboflags, 0); // (4)
dbstl::register_db_env(penv); // (5)
dbstl::register_db(pdb); // (6)
int vector_test(int, char**)
{
typedef dbstl::db_vector <double, ElementHolder<double> > dbl_vec_t; // (1)
dbl_vec_t v1; // Empty vector of doubles. (1)
v1.push_back(32.1);
v1.push_back(40.5);
// The rest follows ...
int vector_test(int, char**)
{
typedef std::vector<double> dbl_vec_t; // (1)
dbl_vec_t v1; // Empty vector of doubles. (1)
v1.push_back(32.1);
v1.push_back(40.5);
// The rest follows ...