2019-01-15 21:49:53 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
2019-07-08 02:59:55 +02:00
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
2019-01-15 21:49:53 +01:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
2019-07-08 02:59:55 +02:00
|
|
|
#define HAVE_IRCD_M_GET_H
|
2019-01-15 21:49:53 +01:00
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
2022-08-17 04:47:24 +02:00
|
|
|
// Fetch the value for a single property of multiple events in parallel into the closure.
|
|
|
|
uint64_t get(std::nothrow_t, const vector_view<const event::idx> &, const string_view &key, const event::fetch::views_closure &);
|
|
|
|
void get(const vector_view<const event::idx> &, const string_view &key, const event::fetch::views_closure &);
|
|
|
|
|
2019-02-12 19:03:20 +01:00
|
|
|
// Fetch the value for a single property of an event into the closure.
|
2019-01-15 21:49:53 +01:00
|
|
|
bool get(std::nothrow_t, const event::idx &, const string_view &key, const event::fetch::view_closure &);
|
|
|
|
bool get(std::nothrow_t, const event::id &, const string_view &key, const event::fetch::view_closure &);
|
|
|
|
void get(const event::idx &, const string_view &key, const event::fetch::view_closure &);
|
|
|
|
void get(const event::id &, const string_view &key, const event::fetch::view_closure &);
|
|
|
|
|
2019-02-12 19:03:20 +01:00
|
|
|
// Copies value into buffer returning view.
|
2019-01-15 21:49:53 +01:00
|
|
|
const_buffer get(std::nothrow_t, const event::idx &, const string_view &key, const mutable_buffer &out);
|
|
|
|
const_buffer get(std::nothrow_t, const event::id &, const string_view &key, const mutable_buffer &out);
|
|
|
|
const_buffer get(const event::idx &, const string_view &key, const mutable_buffer &out);
|
|
|
|
const_buffer get(const event::id &, const string_view &key, const mutable_buffer &out);
|
2019-02-08 16:05:29 +01:00
|
|
|
|
2019-02-12 19:03:20 +01:00
|
|
|
// Allocates and copies into string.
|
|
|
|
std::string get(std::nothrow_t, const event::idx &, const string_view &key);
|
|
|
|
std::string get(std::nothrow_t, const event::id &, const string_view &key);
|
|
|
|
std::string get(const event::idx &, const string_view &key);
|
|
|
|
std::string get(const event::id &, const string_view &key);
|
|
|
|
|
2019-02-08 16:05:29 +01:00
|
|
|
template<class T>
|
|
|
|
typename std::enable_if<std::is_integral<T>::value, bool>::type
|
|
|
|
get(const event::idx &, const string_view &key, T &ret);
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
typename std::enable_if<std::is_integral<T>::value, T>::type
|
|
|
|
get(const event::idx &, const string_view &key);
|
2020-02-19 21:36:01 +01:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
typename std::enable_if<std::is_integral<T>::value, T>::type
|
|
|
|
get(std::nothrow_t, const event::idx &, const string_view &key, T ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2020-12-12 01:35:03 +01:00
|
|
|
inline typename std::enable_if<std::is_integral<T>::value, T>::type
|
2020-02-19 21:36:01 +01:00
|
|
|
ircd::m::get(std::nothrow_t,
|
|
|
|
const event::idx &event_idx,
|
|
|
|
const string_view &key,
|
|
|
|
T ret)
|
|
|
|
{
|
|
|
|
get(event_idx, key, ret);
|
|
|
|
return ret;
|
2019-02-08 16:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2020-12-12 01:35:03 +01:00
|
|
|
inline typename std::enable_if<std::is_integral<T>::value, T>::type
|
2019-02-08 16:05:29 +01:00
|
|
|
ircd::m::get(const event::idx &event_idx,
|
|
|
|
const string_view &key)
|
|
|
|
{
|
|
|
|
T ret;
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
reinterpret_cast<char *>(&ret), sizeof(ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
get(event_idx, key, buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2020-12-12 01:35:03 +01:00
|
|
|
inline typename std::enable_if<std::is_integral<T>::value, bool>::type
|
2019-02-08 16:05:29 +01:00
|
|
|
ircd::m::get(const event::idx &event_idx,
|
|
|
|
const string_view &key,
|
|
|
|
T &ret)
|
|
|
|
{
|
|
|
|
const mutable_buffer buf
|
|
|
|
{
|
|
|
|
reinterpret_cast<char *>(&ret), sizeof(ret)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto rbuf
|
|
|
|
{
|
|
|
|
get(std::nothrow, event_idx, key, buf)
|
|
|
|
};
|
|
|
|
|
2019-09-23 06:13:45 +02:00
|
|
|
assert(empty(rbuf) || size(rbuf) >= sizeof(T));
|
2019-02-08 16:05:29 +01:00
|
|
|
return !empty(rbuf);
|
2019-01-15 21:49:53 +01:00
|
|
|
}
|