kcplantdb.h | kcplantdb.h | |||
---|---|---|---|---|
skipping to change at line 206 | skipping to change at line 206 | |||
* Jump the cursor to the first record for forward scan. | * Jump the cursor to the first record for forward scan. | |||
* @return true on success, or false on failure. | * @return true on success, or false on failure. | |||
*/ | */ | |||
bool jump() { | bool jump() { | |||
_assert_(true); | _assert_(true); | |||
ScopedRWLock lock(&db_->mlock_, false); | ScopedRWLock lock(&db_->mlock_, false); | |||
if (db_->omode_ == 0) { | if (db_->omode_ == 0) { | |||
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |||
return false; | return false; | |||
} | } | |||
back_ = false; | ||||
if (kbuf_) clear_position(); | if (kbuf_) clear_position(); | |||
bool err = false; | bool err = false; | |||
if (!set_position(db_->first_)) err = true; | if (!set_position(db_->first_)) err = true; | |||
back_ = false; | ||||
return !err; | return !err; | |||
} | } | |||
/** | /** | |||
* Jump the cursor to a record for forward scan. | * Jump the cursor to a record for forward scan. | |||
* @param kbuf the pointer to the key region. | * @param kbuf the pointer to the key region. | |||
* @param ksiz the size of the key region. | * @param ksiz the size of the key region. | |||
* @return true on success, or false on failure. | * @return true on success, or false on failure. | |||
*/ | */ | |||
bool jump(const char* kbuf, size_t ksiz) { | bool jump(const char* kbuf, size_t ksiz) { | |||
_assert_(kbuf && ksiz <= MEMMAXSIZ); | _assert_(kbuf && ksiz <= MEMMAXSIZ); | |||
ScopedRWLock lock(&db_->mlock_, false); | ScopedRWLock lock(&db_->mlock_, false); | |||
if (db_->omode_ == 0) { | if (db_->omode_ == 0) { | |||
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |||
return false; | return false; | |||
} | } | |||
back_ = false; | ||||
if (kbuf_) clear_position(); | if (kbuf_) clear_position(); | |||
set_position(kbuf, ksiz, 0); | set_position(kbuf, ksiz, 0); | |||
bool err = false; | bool err = false; | |||
if (!adjust_position()) { | if (!adjust_position()) { | |||
if (kbuf_) clear_position(); | if (kbuf_) clear_position(); | |||
err = true; | err = true; | |||
} | } | |||
back_ = false; | ||||
return !err; | return !err; | |||
} | } | |||
/** | /** | |||
* Jump the cursor to a record for forward scan. | * Jump the cursor to a record for forward scan. | |||
* @note Equal to the original Cursor::jump method except that the para meter is std::string. | * @note Equal to the original Cursor::jump method except that the para meter is std::string. | |||
*/ | */ | |||
bool jump(const std::string& key) { | bool jump(const std::string& key) { | |||
_assert_(true); | _assert_(true); | |||
return jump(key.c_str(), key.size()); | return jump(key.c_str(), key.size()); | |||
} | } | |||
skipping to change at line 256 | skipping to change at line 256 | |||
* @note This method is dedicated to tree databases. Some database typ es, especially hash | * @note This method is dedicated to tree databases. Some database typ es, especially hash | |||
* databases, may provide a dummy implementation. | * databases, may provide a dummy implementation. | |||
*/ | */ | |||
bool jump_back() { | bool jump_back() { | |||
_assert_(true); | _assert_(true); | |||
ScopedRWLock lock(&db_->mlock_, false); | ScopedRWLock lock(&db_->mlock_, false); | |||
if (db_->omode_ == 0) { | if (db_->omode_ == 0) { | |||
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |||
return false; | return false; | |||
} | } | |||
back_ = true; | ||||
if (kbuf_) clear_position(); | if (kbuf_) clear_position(); | |||
bool err = false; | bool err = false; | |||
if (!set_position_back(db_->last_)) err = true; | if (!set_position_back(db_->last_)) err = true; | |||
back_ = true; | ||||
return !err; | return !err; | |||
} | } | |||
/** | /** | |||
* Jump the cursor to a record for backward scan. | * Jump the cursor to a record for backward scan. | |||
* @param kbuf the pointer to the key region. | * @param kbuf the pointer to the key region. | |||
* @param ksiz the size of the key region. | * @param ksiz the size of the key region. | |||
* @return true on success, or false on failure. | * @return true on success, or false on failure. | |||
*/ | */ | |||
bool jump_back(const char* kbuf, size_t ksiz) { | bool jump_back(const char* kbuf, size_t ksiz) { | |||
_assert_(kbuf && ksiz <= MEMMAXSIZ); | _assert_(kbuf && ksiz <= MEMMAXSIZ); | |||
ScopedRWLock lock(&db_->mlock_, false); | ScopedRWLock lock(&db_->mlock_, false); | |||
if (db_->omode_ == 0) { | if (db_->omode_ == 0) { | |||
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |||
return false; | return false; | |||
} | } | |||
back_ = true; | ||||
if (kbuf_) clear_position(); | if (kbuf_) clear_position(); | |||
set_position(kbuf, ksiz, 0); | set_position(kbuf, ksiz, 0); | |||
bool err = false; | bool err = false; | |||
if (adjust_position()) { | if (adjust_position()) { | |||
if (db_->reccomp_.comp->compare(kbuf, ksiz, kbuf_, ksiz_) < 0) { | if (db_->reccomp_.comp->compare(kbuf, ksiz, kbuf_, ksiz_) < 0) { | |||
bool hit = false; | bool hit = false; | |||
if (lid_ > 0 && !back_position_spec(&hit)) err = true; | if (lid_ > 0 && !back_position_spec(&hit)) err = true; | |||
if (!err && !hit) { | if (!err && !hit) { | |||
db_->mlock_.unlock(); | db_->mlock_.unlock(); | |||
db_->mlock_.lock_writer(); | db_->mlock_.lock_writer(); | |||
skipping to change at line 297 | skipping to change at line 298 | |||
} else { | } else { | |||
db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | |||
err = true; | err = true; | |||
} | } | |||
} | } | |||
} | } | |||
} else { | } else { | |||
if (kbuf_) clear_position(); | if (kbuf_) clear_position(); | |||
if (!set_position_back(db_->last_)) err = true; | if (!set_position_back(db_->last_)) err = true; | |||
} | } | |||
back_ = true; | ||||
return !err; | return !err; | |||
} | } | |||
/** | /** | |||
* Jump the cursor to a record for backward scan. | * Jump the cursor to a record for backward scan. | |||
* @note Equal to the original Cursor::jump_back method except that the parameter is | * @note Equal to the original Cursor::jump_back method except that the parameter is | |||
* std::string. | * std::string. | |||
*/ | */ | |||
bool jump_back(const std::string& key) { | bool jump_back(const std::string& key) { | |||
_assert_(true); | _assert_(true); | |||
return jump_back(key.c_str(), key.size()); | return jump_back(key.c_str(), key.size()); | |||
} | } | |||
/** | /** | |||
* Step the cursor to the next record. | * Step the cursor to the next record. | |||
* @return true on success, or false on failure. | * @return true on success, or false on failure. | |||
*/ | */ | |||
bool step() { | bool step() { | |||
_assert_(true); | _assert_(true); | |||
back_ = false; | ||||
DB::Visitor visitor; | DB::Visitor visitor; | |||
if (!accept(&visitor, false, true)) return false; | if (!accept(&visitor, false, true)) return false; | |||
if (!kbuf_) { | if (!kbuf_) { | |||
db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | |||
return false; | return false; | |||
} | } | |||
back_ = false; | ||||
return true; | return true; | |||
} | } | |||
/** | /** | |||
* Step the cursor to the previous record. | * Step the cursor to the previous record. | |||
* @return true on success, or false on failure. | * @return true on success, or false on failure. | |||
*/ | */ | |||
bool step_back() { | bool step_back() { | |||
_assert_(true); | _assert_(true); | |||
db_->mlock_.lock_reader(); | db_->mlock_.lock_reader(); | |||
if (db_->omode_ == 0) { | if (db_->omode_ == 0) { | |||
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); | |||
db_->mlock_.unlock(); | db_->mlock_.unlock(); | |||
return false; | return false; | |||
} | } | |||
if (!kbuf_) { | if (!kbuf_) { | |||
db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | |||
db_->mlock_.unlock(); | db_->mlock_.unlock(); | |||
return false; | return false; | |||
} | } | |||
back_ = true; | ||||
bool err = false; | bool err = false; | |||
bool hit = false; | bool hit = false; | |||
if (lid_ > 0 && !back_position_spec(&hit)) err = true; | if (lid_ > 0 && !back_position_spec(&hit)) err = true; | |||
if (!err && !hit) { | if (!err && !hit) { | |||
db_->mlock_.unlock(); | db_->mlock_.unlock(); | |||
db_->mlock_.lock_writer(); | db_->mlock_.lock_writer(); | |||
if (kbuf_) { | if (kbuf_) { | |||
if (!back_position_atom()) err = true; | if (!back_position_atom()) err = true; | |||
} else { | } else { | |||
db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); | |||
err = true; | err = true; | |||
} | } | |||
} | } | |||
db_->mlock_.unlock(); | db_->mlock_.unlock(); | |||
back_ = true; | ||||
return !err; | return !err; | |||
} | } | |||
/** | /** | |||
* Get the database object. | * Get the database object. | |||
* @return the database object. | * @return the database object. | |||
*/ | */ | |||
PlantDB* db() { | PlantDB* db() { | |||
_assert_(true); | _assert_(true); | |||
return db_; | return db_; | |||
} | } | |||
End of changes. 12 change blocks. | ||||
6 lines changed or deleted | 6 lines changed or added | |||