hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
LevelDB.cpp
Go to the documentation of this file.
1 
15 
16 
17 
18 #ifdef _USE_LEVEL_DB_
19 
20 
21 #include "LevelDB.hpp"
22 
23 
24 namespace HCE
25 {
26 
27 LevelDB::LevelDB():_db(nullptr){
28  leveldb::Status status;
29  _options.create_if_missing = true;
30  assert( status.ok() );
31  if ( !status.ok() ) {
32  Poco::Message msg ("LevelDB",status.ToString(),Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
34  }
35 }
36 
38  if (this->_db != nullptr) {
39  delete this->_db;
40  }
41 }
42 
43 void LevelDB::setDatabaseName(const std::string& dbName) {
44  leveldb::Status status;
45  BaseDB::_dbName = dbName;
46  status = leveldb::DB::Open( _options, _dbName, this->&_db );
47  assert(status.ok());
48  if (!status.ok()) {
49  Poco::Message msg ("LevelDB",status.ToString(),Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
51  }
52 }
53 
54 void LevelDB::put(const std::string& key, const std::string& value) {
55  leveldb::Status status;
57  if ( status.ok() ) {
58  status = _db->Put(leveldb::WriteOptions(), key, value);
59  }
60  if (!status.ok()) {
62  Poco::Message msg ("LevelDB",status.ToString(),Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
64  }
65 }
66 
67 std::string LevelDB::get(const std::string& key) {
68  leveldb::Status status;
70  std::string value;
71  if ( status.ok() ) {
73  status = _db->Get(leveldb::ReadOptions(), key, &value);
74  if ( status.ok() ) {
76  }
77  }
78  return value;
79 }
80 
81 std::vector<std::string> LevelDB::get_all() {}
82 
83 void LevelDB::del(const std::string& key) {
84  leveldb::Status status;
86  if ( status.ok() ) {
87  status = _db->Delete(leveldb::WriteOptions(), key);
88  }
89  if (!status.ok()) {
91  Poco::Message msg ("LevelDB",status.ToString(),Poco::Message::PRIO_CRITICAL,__FILE__,__LINE__);
93  }
94 }
95 
96 
97 }
98 
99 #endif