datastore.h 1.79 KB
Newer Older
1 2
// Copyright (c) 2017, Los Alamos National Security, LLC.
// All rights reserved.
3 4 5
#ifndef datastore_h
#define datastore_h

Rob Latham's avatar
Rob Latham committed
6
#include "kv-config.h"
7
#include "bulk.h"
8 9

#include <vector>
10 11 12

enum class Duplicates : int {ALLOW, IGNORE};

13 14
class AbstractDataStore {
public:
15 16 17

  typedef int (*comparator_fn)(const void*, size_t, const void*, size_t);
  
18 19 20
  AbstractDataStore();
  AbstractDataStore(Duplicates duplicates, bool eraseOnGet, bool debug);
  virtual ~AbstractDataStore();
21
  virtual bool openDatabase(const std::string& db_name, const std::string& path)=0;
22 23 24
  virtual bool put(const ds_bulk_t &key, const ds_bulk_t &data)=0;
  virtual bool get(const ds_bulk_t &key, ds_bulk_t &data)=0;
  virtual bool get(const ds_bulk_t &key, std::vector<ds_bulk_t> &data)=0;
25
  virtual bool exists(const ds_bulk_t &key) = 0;
Matthieu Dorier's avatar
Matthieu Dorier committed
26
  virtual bool erase(const ds_bulk_t &key) = 0;
27
  virtual void set_in_memory(bool enable)=0; // enable/disable in-memory mode (where supported)
28
  virtual void set_comparison_function(comparator_fn less)=0;
29
  virtual void set_no_overwrite()=0;
30 31 32 33 34 35 36 37 38 39 40

  std::vector<ds_bulk_t> list_keys(
          const ds_bulk_t &start_key, size_t count, const ds_bulk_t& prefix=ds_bulk_t()) {
      return vlist_keys(start_key, count, prefix);
  }

  std::vector<std::pair<ds_bulk_t,ds_bulk_t>> list_keyvals(
          const ds_bulk_t &start_key, size_t count, const ds_bulk_t& prefix=ds_bulk_t()) {
    return vlist_keyvals(start_key, count, prefix);
  }

41 42 43 44
protected:
  Duplicates _duplicates;
  bool _eraseOnGet;
  bool _debug;
45
  bool _in_memory;
46 47 48 49 50

  virtual std::vector<ds_bulk_t> vlist_keys(
          const ds_bulk_t &start_key, size_t count, const ds_bulk_t& prefix) = 0;
  virtual std::vector<std::pair<ds_bulk_t,ds_bulk_t>> vlist_keyvals(
          const ds_bulk_t &start_key, size_t count, const ds_bulk_t& prefix) = 0;
51 52 53
};

#endif // datastore_h