mirror of
https://github.com/matrix-construct/construct
synced 2025-02-16 16:50:12 +01:00
ircd:Ⓜ️:event: Add event_id() convenience suite to reverse index().
This commit is contained in:
parent
ec8f0c1e1c
commit
e497fe8506
3 changed files with 90 additions and 0 deletions
|
@ -35,6 +35,7 @@ namespace ircd::m
|
|||
#include "event/prev.h"
|
||||
#include "event/refs.h"
|
||||
#include "event/index.h"
|
||||
#include "event/event_id.h"
|
||||
#include "event/fetch.h"
|
||||
#include "event/get.h"
|
||||
#include "event/cached.h"
|
||||
|
|
27
include/ircd/m/event/event_id.h
Normal file
27
include/ircd/m/event/event_id.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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_EVENT_ID_H
|
||||
|
||||
// Convenience suite to reverse event::idx to event::id. Note that event::id's
|
||||
// have more many more tools and related elements than what is found in this
|
||||
// header; despite the name which merely matches the function name here.
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
bool event_id(const event::idx &, std::nothrow_t, const event::id::closure &);
|
||||
|
||||
event::id event_id(const event::idx &, event::id::buf &, std::nothrow_t);
|
||||
event::id event_id(const event::idx &, event::id::buf &);
|
||||
|
||||
event::id::buf event_id(const event::idx &, std::nothrow_t);
|
||||
event::id::buf event_id(const event::idx &);
|
||||
}
|
|
@ -948,6 +948,68 @@ ircd::m::event::fetch::opts::opts(const event::keys::selection &keys,
|
|||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// event/event_id.h
|
||||
//
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::event_id(const event::idx &event_idx)
|
||||
{
|
||||
event::id::buf ret;
|
||||
event_id(event_idx, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::event_id(const event::idx &event_idx,
|
||||
std::nothrow_t)
|
||||
{
|
||||
event::id::buf ret;
|
||||
event_id(event_idx, ret, std::nothrow);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::m::event::id
|
||||
ircd::m::event_id(const event::idx &event_idx,
|
||||
event::id::buf &buf)
|
||||
{
|
||||
const event::id ret
|
||||
{
|
||||
event_id(event_idx, buf, std::nothrow)
|
||||
};
|
||||
|
||||
if(!ret)
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"Cannot find event ID from idx[%lu]", event_idx
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::m::event::id
|
||||
ircd::m::event_id(const event::idx &event_idx,
|
||||
event::id::buf &buf,
|
||||
std::nothrow_t)
|
||||
{
|
||||
event_id(event_idx, std::nothrow, [&buf]
|
||||
(const event::id &eid)
|
||||
{
|
||||
buf = eid;
|
||||
});
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::event_id(const event::idx &event_idx,
|
||||
std::nothrow_t,
|
||||
const event::id::closure &closure)
|
||||
{
|
||||
return get(std::nothrow, event_idx, "event_id", closure);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// event/index.h
|
||||
|
|
Loading…
Add table
Reference in a new issue