strus  0.17
databaseCursorInterface.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef _STRUS_DATABASE_CURSOR_INTERFACE_HPP_INCLUDED
11 #define _STRUS_DATABASE_CURSOR_INTERFACE_HPP_INCLUDED
12 #include <string>
13 
14 namespace strus
15 {
16 
19 {
20 public:
22  class Slice
23  {
24  public:
27  :m_ptr(0),m_size(0){}
31  Slice( const char* ptr_, std::size_t size_)
32  :m_ptr(ptr_),m_size(size_){}
35  Slice( const Slice& o)
36  :m_ptr(o.m_ptr),m_size(o.m_size){}
37 
40  const char* ptr() const {return m_ptr;}
43  std::size_t size() const {return m_size;}
44 
46  std::string tostring() const {return std::string(m_ptr,m_size);}
48  operator std::string() const {return std::string(m_ptr,m_size);}
51  bool defined() const {return m_ptr!=0;}
52 
53  private:
54  const char* m_ptr;
55  std::size_t m_size;
56  };
57 
58 public:
61 
67  virtual Slice seekUpperBound(
68  const char* keystr,
69  std::size_t keysize,
70  std::size_t domainkeysize)=0;
71 
78  virtual Slice seekUpperBoundRestricted(
79  const char* keystr,
80  std::size_t keysize,
81  const char* upkey,
82  std::size_t upkeysize)=0;
83 
88  virtual Slice seekFirst(
89  const char* domainkey,
90  std::size_t domainkeysize)=0;
91 
96  virtual Slice seekLast(
97  const char* domainkey,
98  std::size_t domainkeysize)=0;
99 
102  virtual Slice seekNext()=0;
103 
106  virtual Slice seekPrev()=0;
107 
110  virtual Slice key() const=0;
111 
114  virtual Slice value() const=0;
115 };
116 
117 }//namespace
118 #endif
119 
120 
std::size_t size() const
Get the size of the data in bytes.
Definition: databaseCursorInterface.hpp:43
virtual ~DatabaseCursorInterface()
Destructor.
Definition: databaseCursorInterface.hpp:60
Interface to database cursor.
Definition: databaseCursorInterface.hpp:18
virtual Slice seekNext()=0
Move cursor to the next key stored in the database in the current key domain.
Chunk data structure without ownership for keys and values of the database cursor.
Definition: databaseCursorInterface.hpp:22
bool defined() const
Evaluate if the chunk is defined or a NULL reference.
Definition: databaseCursorInterface.hpp:51
virtual Slice key() const =0
Get the key of the current element.
Slice()
Defaul constructor.
Definition: databaseCursorInterface.hpp:26
virtual Slice seekPrev()=0
Move cursor to the previous key stored in the database in the current key domain. ...
virtual Slice seekUpperBoundRestricted(const char *keystr, std::size_t keysize, const char *upkey, std::size_t upkeysize)=0
Move cursor to the least upper bound key stored in the database with upper limit specified by key and...
Slice(const Slice &o)
Copy constructor.
Definition: databaseCursorInterface.hpp:35
std::string tostring() const
Return the data as a string.
Definition: databaseCursorInterface.hpp:46
const char * ptr() const
Get the pointer to data.
Definition: databaseCursorInterface.hpp:40
virtual Slice value() const =0
Get the value of the current element.
virtual Slice seekFirst(const char *domainkey, std::size_t domainkeysize)=0
Move cursor to the first key stored in the database in a defined key domain.
Slice(const char *ptr_, std::size_t size_)
Constructor.
Definition: databaseCursorInterface.hpp:31
virtual Slice seekLast(const char *domainkey, std::size_t domainkeysize)=0
Move cursor to the last key stored in the database in a defined key domain.
virtual Slice seekUpperBound(const char *keystr, std::size_t keysize, std::size_t domainkeysize)=0
Move cursor to the least upper bound key stored in the database.