mr_types.h
1 // Copyright 2019, Beeri 15. All rights reserved.
2 // Author: Roman Gershman (romange@gmail.com)
3 //
4 #pragma once
5 
6 #include <functional>
7 #include <string>
8 
9 #include "absl/strings/string_view.h"
10 #include "absl/types/variant.h"
11 
12 namespace mr3 {
13 
14 template <typename T> class DoContext;
15 
16 template <typename FromType, typename Class, typename O>
17 using EmitMemberFn = void (Class::*)(FromType, DoContext<O>*);
18 
19 using RawRecord = ::std::string;
20 
21 typedef std::function<void(RawRecord&& record)> RawSinkCb;
22 
23 template <typename Handler, typename ToType>
24 using RawSinkMethodFactory = std::function<RawSinkCb(Handler* handler, DoContext<ToType>* context)>;
25 
26 struct ShardId : public absl::variant<absl::monostate, uint32_t, std::string> {
27  using Parent = absl::variant<absl::monostate, uint32_t, std::string>;
28 
29  using Parent::Parent;
30 
31  ShardId() = default;
32 
33  std::string ToString(absl::string_view basename) const;
34 
35  bool is_defined() const { return !absl::holds_alternative<absl::monostate>(*this); }
36 };
37 
38 using MetricMap = std::map<std::string, long>;
39 
40 } // namespace mr3
41 
42 std::ostream& operator<<(std::ostream& os, const mr3::ShardId& sid);
43 
44 namespace std {
45 
46 template <> struct hash<mr3::ShardId> {
47  size_t operator()(const mr3::ShardId& sid) const { return hash<mr3::ShardId::Parent>{}(sid); }
48 };
49 
50 } // namespace std