13 #include <immer/map.hpp>
14 #include <zug/transducer/filter.hpp>
15 #include <zug/transducer/eager.hpp>
16 #include <lager/deps.hpp>
17 #include <boost/container_hash/hash.hpp>
18 #include <boost/serialization/string.hpp>
29 template<
class K,
class V,
class List,
class Func>
30 immer::map<K, V>
merge(immer::map<K, V> map, List list, Func keyOf)
34 map = std::move(map).set(key, v);
61 template<
class Archive>
71 template<
class Context>
74 return lager::get<JobInterface &>(std::forward<Context>(ctx));
77 template<
class Context>
80 return lager::get<EventInterface &>(std::forward<Context>(ctx));
85 template<
class ImmerT>
88 using value_type =
typename ImmerT::value_type;
89 using reference =
typename ImmerT::reference;
90 using pointer =
const value_type *;
91 using difference_type =
long int;
92 using iterator_category = std::random_access_iterator_tag;
94 ImmerIterator(
const ImmerT &container, std::size_t index)
95 : m_container(
std::ref(container))
99 ImmerIterator &operator+=(difference_type d) {
104 ImmerIterator &operator-=(difference_type d) {
109 difference_type operator-(ImmerIterator b)
const {
110 return index() - b.index();
113 ImmerIterator &operator++() {
117 ImmerIterator operator++(
int) {
123 ImmerIterator &operator--() {
127 ImmerIterator operator--(
int) {
134 reference &operator*()
const {
135 return m_container.get().at(m_index);
138 reference operator[](difference_type d)
const;
140 std::size_t index()
const {
return m_index; }
144 std::reference_wrapper<const ImmerT> m_container;
148 template<
class ImmerT>
149 auto ImmerIterator<ImmerT>::operator[](difference_type d)
const -> reference
154 template<
class ImmerT>
155 auto operator+(ImmerIterator<ImmerT> a,
long int d)
160 template<
class ImmerT>
161 auto operator+(
long int d, ImmerIterator<ImmerT> a)
166 template<
class ImmerT>
167 auto operator-(ImmerIterator<ImmerT> a,
long int d)
172 template<
class ImmerT>
173 auto immerBegin(
const ImmerT &c)
175 return ImmerIterator<ImmerT>(c, 0);
178 template<
class ImmerT>
179 auto immerEnd(
const ImmerT &c)
181 return ImmerIterator<ImmerT>(c, c.size());
185 template<
class ImmerT1,
class RangeT2,
class Pred,
class Func>
189 zug::filter([=](
auto a) {
194 auto cmp = [=](
auto a,
auto b) {
195 return keyOf(a) < keyOf(b);
198 for (
auto item : needToAdd) {
199 auto it = std::upper_bound(immerBegin(base), immerEnd(base), item, cmp);
200 auto index = it.index();
201 base = std::move(base).insert(index, item);
209 std::string
getTxnId(Event event, ClientModel &m);
214 template<>
struct hash<
Kazv::KeyOfState>
217 std::size_t seed = 0;
218 boost::hash_combine(seed, k.type);
219 boost::hash_combine(seed, k.stateKey);
225 #define KAZV_WRAP_ATTR(_type, _d, _attr) \
226 inline auto _attr() const { \
227 KAZV_VERIFY_THREAD_ID(); \
228 return (_d)[&_type::_attr]; \
Definition: context.hpp:130
Definition: eventinterface.hpp:15
std::string stateKey() const
Definition: event.cpp:74
std::string type() const
Definition: event.cpp:62
std::string id() const
returns the id of this event
Definition: event.cpp:42
std::string sender() const
Definition: event.cpp:49
auto operator+(Cursor &&c)
Definition: cursorutil.hpp:122
Definition: location.hpp:10
std::string increaseTxnId(std::string cur)
Definition: clientutil.cpp:14
std::string keyOfAccountData(Event e)
Definition: clientutil.hpp:43
immer::map< K, V > merge(immer::map< K, V > map, List list, Func keyOf)
Definition: clientutil.hpp:30
detail::IntoImmerT intoImmer
Definition: cursorutil.hpp:88
ImmerT1 sortedUniqueMerge(ImmerT1 base, RangeT2 addon, Pred exists, Func keyOf)
Definition: clientutil.hpp:186
std::string getTxnId(Event, ClientModel &m)
Definition: clientutil.cpp:19
KeyOfState keyOfState(Event e)
Definition: clientutil.hpp:67
std::string keyOfEphemeral(Event e)
Definition: clientutil.hpp:51
std::string keyOfPresence(Event e)
Definition: clientutil.hpp:39
std::string keyOfTimeline(Event e)
Definition: clientutil.hpp:47
void serialize(Archive &ar, ClientModel &m, std::uint32_t const version)
Definition: client-model.hpp:584
JobInterface & getJobHandler(Context &&ctx)
Definition: clientutil.hpp:72
EventInterface & getEventEmitter(Context &&ctx)
Definition: clientutil.hpp:78
Definition: clientutil.hpp:213
Definition: jobinterface.hpp:21
Definition: clientutil.hpp:56
std::string type
Definition: clientutil.hpp:57
std::string stateKey
Definition: clientutil.hpp:58
friend bool operator==(const KeyOfState &a, const KeyOfState &b)=default
std::size_t operator()(const Kazv::KeyOfState &k) const noexcept
Definition: clientutil.hpp:216