2014-01-13 19:52:22 +01:00
|
|
|
#include "rocksdb/comparator.h"
|
2014-01-24 17:11:41 +01:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include <stdexcept>
|
2014-01-13 19:52:22 +01:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using rocksdb::Comparator;
|
|
|
|
using rocksdb::Slice;
|
2014-01-24 17:11:41 +01:00
|
|
|
using rocksdb::Logger;
|
2014-01-13 19:52:22 +01:00
|
|
|
|
|
|
|
namespace py_rocks {
|
|
|
|
class ComparatorWrapper: public Comparator {
|
|
|
|
public:
|
2014-01-24 17:11:41 +01:00
|
|
|
typedef int (*compare_func)(
|
|
|
|
void*,
|
|
|
|
Logger*,
|
|
|
|
string&,
|
|
|
|
const Slice&,
|
|
|
|
const Slice&);
|
2014-01-13 19:52:22 +01:00
|
|
|
|
|
|
|
ComparatorWrapper(
|
|
|
|
string name,
|
|
|
|
void* compare_context,
|
|
|
|
compare_func compare_callback):
|
|
|
|
name(name),
|
|
|
|
compare_context(compare_context),
|
|
|
|
compare_callback(compare_callback)
|
|
|
|
{}
|
|
|
|
|
|
|
|
int Compare(const Slice& a, const Slice& b) const {
|
2014-01-24 17:11:41 +01:00
|
|
|
string error_msg;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = this->compare_callback(
|
|
|
|
this->compare_context,
|
|
|
|
this->info_log.get(),
|
|
|
|
error_msg,
|
|
|
|
a,
|
|
|
|
b);
|
|
|
|
|
|
|
|
if (error_msg.size()) {
|
|
|
|
throw std::runtime_error(error_msg.c_str());
|
|
|
|
}
|
|
|
|
return val;
|
2014-01-13 19:52:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* Name() const {
|
|
|
|
return this->name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindShortestSeparator(string* start, const Slice& limit) const {}
|
|
|
|
void FindShortSuccessor(string* key) const {}
|
|
|
|
|
2014-01-24 17:11:41 +01:00
|
|
|
void set_info_log(std::shared_ptr<Logger> info_log) {
|
|
|
|
this->info_log = info_log;
|
|
|
|
}
|
|
|
|
|
2014-01-13 19:52:22 +01:00
|
|
|
private:
|
|
|
|
string name;
|
|
|
|
void* compare_context;
|
|
|
|
compare_func compare_callback;
|
2014-01-24 17:11:41 +01:00
|
|
|
std::shared_ptr<Logger> info_log;
|
2014-01-13 19:52:22 +01:00
|
|
|
};
|
|
|
|
}
|