mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-07-14 17:13:15 -07:00
RethinkDB native connector work, minor fixes.
This commit is contained in:
parent
a6203ed038
commit
4e88c80a22
219 changed files with 33295 additions and 0 deletions
76
ext/librethinkdbxx/src/cursor.h
Normal file
76
ext/librethinkdbxx/src/cursor.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
namespace RethinkDB {
|
||||
|
||||
// The response from the server, as returned by run.
|
||||
// The response is either a single datum or a stream:
|
||||
// * If it is a stream, the cursor represents each element of the stream.
|
||||
// - Batches are fetched from the server as needed.
|
||||
// * If it is a single datum, is_single() returns true.
|
||||
// - If it is an array, the cursor represents each element of that array
|
||||
// - Otherwise, to_datum() returns the datum and iteration throws an exception.
|
||||
// The cursor can only be iterated over once, it discards data that has already been read.
|
||||
class CursorPrivate;
|
||||
class Cursor {
|
||||
public:
|
||||
Cursor() = delete;
|
||||
~Cursor();
|
||||
|
||||
Cursor(Cursor&&); // movable
|
||||
Cursor& operator=(Cursor&&);
|
||||
Cursor(const Cursor&) = delete; // not copyable
|
||||
Cursor& operator=(const Cursor&) = delete;
|
||||
|
||||
// Returned by begin() and end()
|
||||
class iterator {
|
||||
public:
|
||||
iterator(Cursor*);
|
||||
iterator& operator++ ();
|
||||
Datum& operator* ();
|
||||
bool operator!= (const iterator&) const;
|
||||
|
||||
private:
|
||||
Cursor *cursor;
|
||||
};
|
||||
|
||||
// Consume the next element
|
||||
Datum& next(double wait = FOREVER) const;
|
||||
|
||||
// Peek at the next element
|
||||
Datum& peek(double wait = FOREVER) const;
|
||||
|
||||
// Call f on every element of the Cursor
|
||||
void each(std::function<void(Datum&&)> f, double wait = FOREVER) const;
|
||||
|
||||
// Consume and return all elements
|
||||
Array&& to_array() &&;
|
||||
|
||||
// If is_single(), returns the single datum. Otherwise returns to_array().
|
||||
Datum to_datum() &&;
|
||||
Datum to_datum() const &;
|
||||
|
||||
// Efficiently consume and return all elements
|
||||
Array to_array() const &;
|
||||
|
||||
// Close the cursor
|
||||
void close() const;
|
||||
|
||||
// Returns false if there are no more elements
|
||||
bool has_next(double wait = FOREVER) const;
|
||||
|
||||
// Returns false if the cursor is a stream
|
||||
bool is_single() const;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
private:
|
||||
explicit Cursor(CursorPrivate *dd);
|
||||
std::unique_ptr<CursorPrivate> d;
|
||||
|
||||
friend class Connection;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue