VCCC  2024.05
VisualCamp Common C++ library
group_key.h
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2021/06/03.
3 # */
4 #
5 # ifndef VCCC_SIGNAL_GROUP_KEY_H_
6 # define VCCC_SIGNAL_GROUP_KEY_H_
7 #
8 # include <utility>
9 #
10 # include "vccc/optional.hpp"
11 
12 namespace vccc {
13 
15 
16 template<typename Group>
17 struct group_key {
18  using key_type = Group;
19 
20  group_key() = default;
21 
22  explicit group_key(group_category group_category_, key_type group_key)
23  : group_token(std::make_pair(group_category_, group_key)) {}
24 
25  explicit group_key(group_category group_category_)
26  : group_token(std::make_pair(group_category_, vccc::nullopt)) {}
27 
28 // explicit group_key(key_type group_key)
29 // : group_token(std::make_pair(ungrouped_front, )) {}
30 
31  std::pair<group_category, vccc::optional<key_type>> group_token{ungrouped_front, vccc::nullopt};
32 };
33 
34 template<typename Group>
35 bool operator==(const group_key<Group>& lhs, const group_key<Group>& rhs) {
36  if (lhs.group_token.first != rhs.group_token.first)
37  return false;
38  if (lhs.group_token.first != grouped)
39  return true;
40  return lhs.group_token.second == rhs.group_token.second;
41 }
42 
43 template<typename Group>
44 bool operator!=(const group_key<Group>& lhs, const group_key<Group>& rhs) {
45  return !(lhs == rhs);
46 }
47 
48 template<typename Group>
50  using group_type = Group;
52  inline bool operator()(const group_key_type& lhs, const group_key_type& rhs) const {
53  if (lhs.group_token.first != rhs.group_token.first) {
54  return lhs.group_token.first < rhs.group_token.first;
55  }
56  // group_category is same by now
57  if (lhs.group_token.first == grouped) {
58  return lhs.group_token.second < rhs.group_token.second;
59  }
60  return false;
61  }
62 };
63 
64 } // namespace vccc
65 
66 # endif // VCCC_SIGNAL_GROUP_KEY_H_
constexpr nullopt_t nullopt
Definition: nullopt_t.h:23
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr bool operator!=(const MatrixBase< E1 > &lhs, const MatrixBase< E2 > &rhs)
Definition: mat_expr_operations.hpp:23
group_category
Definition: group_key.h:14
@ ungrouped_back
Definition: group_key.h:14
@ grouped
Definition: group_key.h:14
@ ungrouped_front
Definition: group_key.h:14
constexpr bool operator==(const MatrixBase< E1 > &lhs, const MatrixBase< E2 > &rhs)
Definition: mat_expr_operations.hpp:15
Definition: group_key.h:49
bool operator()(const group_key_type &lhs, const group_key_type &rhs) const
Definition: group_key.h:52
Group group_type
Definition: group_key.h:50
Definition: group_key.h:17
Group key_type
Definition: group_key.h:18
group_key()=default
group_key(group_category group_category_, key_type group_key)
Definition: group_key.h:22
group_key(group_category group_category_)
Definition: group_key.h:25
std::pair< group_category, vccc::optional< key_type > > group_token
Definition: group_key.h:31