Skip to content

Instantly share code, notes, and snippets.

@bw2012
Last active February 20, 2019 15:02
Show Gist options
  • Save bw2012/35faa74f5d703f92e6157b3f1b6d14b3 to your computer and use it in GitHub Desktop.
Save bw2012/35faa74f5d703f92e6157b3f1b6d14b3 to your computer and use it in GitHub Desktop.
kvdb example
#include "kvdb.h"
#include <cstring>
typedef struct TestStr {
int id = 0;
}TestStr;
int main() {
std::string fileName = "d://test_storage.dat";
// create empty storage file
std::unordered_map<int, TestStr> test;
kvdb::KvFile<int, TestStr>::create(fileName, test);
// open storage file
kvdb::KvFile<int, TestStr> testDb;
if (testDb.open(fileName)) {
// save structure
testDb.put(3, TestStr());
// load structure
int key = 3;
std::shared_ptr<TestStr> tmp = testDb[key];
if (tmp == nullptr) {
printf("key %d -> not found", key);
} else {
printf("key %d -> %d", key, tmp->id);
}
} else {
printf("Unable to open file\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment