This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car { | |
size_t length, width, height; | |
Engine *engine; | |
string model; | |
// Member functions follow ... | |
}; | |
class Engine { | |
size_t horse_power; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |