2018-12-01 23:55:15 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
#define HAVE_IRCD_M_EVENT_PREV_H
|
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
bool for_each(const event::prev &, const event::id::closure_bool &);
|
|
|
|
size_t degree(const event::prev &);
|
|
|
|
size_t count(const event::prev &);
|
|
|
|
|
|
|
|
std::ostream &pretty(std::ostream &, const event::prev &);
|
|
|
|
std::string pretty(const event::prev &);
|
|
|
|
|
|
|
|
std::ostream &pretty_oneline(std::ostream &, const event::prev &);
|
|
|
|
std::string pretty_oneline(const event::prev &);
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:59:33 +02:00
|
|
|
/// Interface to the previous-references of an event. This interface overlays
|
|
|
|
/// on the m::event tuple and adds functionality focused specifically on the
|
|
|
|
/// various reference properties in the event data.
|
|
|
|
///
|
|
|
|
/// Instances of this class "overlay" on the event tuple, meaning one just
|
|
|
|
/// passes an m::event (or a json::object which would be passed to an m::event)
|
|
|
|
/// to the constructor of this class. This class only has the properties of
|
|
|
|
/// the event which contain references, and a suite of functions to work with
|
|
|
|
/// those references.
|
2018-12-01 23:55:15 +01:00
|
|
|
struct ircd::m::event::prev
|
|
|
|
:json::tuple
|
|
|
|
<
|
|
|
|
json::property<name::prev_events, json::array>
|
|
|
|
>
|
|
|
|
{
|
2020-09-17 08:55:48 +02:00
|
|
|
static constexpr const size_t &MAX
|
|
|
|
{
|
|
|
|
20
|
|
|
|
};
|
|
|
|
|
2020-12-17 02:06:10 +01:00
|
|
|
template<size_t N> vector_view<event::id> ids(event::id (&)[N]) const;
|
|
|
|
template<size_t N> vector_view<event::idx> idxs(event::idx (&)[N]) const;
|
2019-07-03 22:24:01 +02:00
|
|
|
std::tuple<event::id, json::object> prev_events(const size_t &idx) const;
|
2019-04-29 19:57:43 +02:00
|
|
|
event::id prev_event(const size_t &idx) const;
|
2019-04-29 20:05:43 +02:00
|
|
|
bool prev_event_exists(const size_t &idx) const;
|
2018-12-01 23:55:15 +01:00
|
|
|
bool prev_events_has(const event::id &) const;
|
2019-04-29 20:05:43 +02:00
|
|
|
size_t prev_events_count() const;
|
2019-09-05 23:38:41 +02:00
|
|
|
size_t prev_events_exist() const;
|
2020-06-10 08:07:34 +02:00
|
|
|
bool prev_exist() const;
|
|
|
|
|
2018-12-01 23:55:15 +01:00
|
|
|
using super_type::tuple;
|
|
|
|
using super_type::operator=;
|
|
|
|
};
|
2020-12-17 02:06:10 +01:00
|
|
|
|
|
|
|
template<size_t N>
|
|
|
|
inline ircd::vector_view<ircd::m::event::idx>
|
|
|
|
ircd::m::event::prev::idxs(event::idx (&out)[N])
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return vector_view<event::idx>
|
|
|
|
(
|
2020-12-19 06:09:47 +01:00
|
|
|
out, m::index(out, *this)
|
2020-12-17 02:06:10 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N>
|
|
|
|
inline ircd::vector_view<ircd::m::event::id>
|
|
|
|
ircd::m::event::prev::ids(event::id (&out)[N])
|
|
|
|
const
|
|
|
|
{
|
|
|
|
size_t i(0);
|
|
|
|
m::for_each(*this, [&i, &out](const event::id &event_id)
|
|
|
|
{
|
|
|
|
out[i++] = event_id;
|
|
|
|
return i < N;
|
|
|
|
});
|
|
|
|
|
|
|
|
return vector_view<event::id>
|
|
|
|
(
|
|
|
|
out, i
|
|
|
|
);
|
|
|
|
}
|