~singpolyma/biboumi

ref: f653906f9de8cbcecf5717e18c696d1029fc2c8f biboumi/src/irc/iid.hpp -rw-r--r-- 2.4 KiB
f653906f — louiz’ Add a None type for the Iid class (when the iid is completely empty) 5 years ago
                                                                                
81f8f45b louiz’
bf7b05ef Florent Le Coz
0d2dd71d louiz’
bf7b05ef Florent Le Coz
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0d2dd71d louiz’
bf7b05ef Florent Le Coz
0d2dd71d louiz’
f653906f louiz’
0d2dd71d louiz’
b2922560 louiz’
0d2dd71d louiz’
07e22095 louiz’
0d2dd71d louiz’
af420738 louiz’
bf7b05ef Florent Le Coz
7c1a3899 Florent Le Coz
0d2dd71d louiz’
7c1a3899 Florent Le Coz
0391f17f Emmanuel Gil Peyrot
7c1a3899 Florent Le Coz
2d11a5f4 louiz’
0d2dd71d louiz’
bf7b05ef Florent Le Coz
2df0ebf2 Florent Le Coz
0d2dd71d louiz’
2df0ebf2 Florent Le Coz
7c1a3899 Florent Le Coz
bf7b05ef Florent Le Coz
7c1a3899 Florent Le Coz
81f8f45b louiz’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once


#include <string>
#include <set>

class Bridge;

/**
 * A name representing an IRC channel on an IRC server, or an IRC user on an
 * IRC server, or just an IRC server.
 *
 * The separator is '%' between the local part (nickname or channel) and the
 * server part. If no separator is present, it's just an irc server.
 * If it is present, the first character of the local part determines if it’s
 * a channel or a user: ff the local part is empty or if its first character
 * is part of the chantypes characters, then it’s a channel, otherwise it’s
 * a user.
 *
 * It’s possible to have an empty-string server, but it makes no sense in
 * biboumi’s context.
 *
 * Assuming the chantypes are '#' and '&':
 *
 * #test%irc.example.org has :
 * - local: "#test" (the # is part of the name, it could very well be absent, or & (for example) instead)
 * - server: "irc.example.org"
 * - type: channel
 *
 * %irc.example.org:
 * - local: ""
 * - server: "irc.example.org"
 * - type: channel
 * Note: this is the special empty-string channel, used internally in biboumi
 * but has no meaning on IRC.
 *
 * foo%irc.example.org
 * - local: "foo"
 * - server: "irc.example.org"
 * - type: user
 * Note: the empty-string user (!irc.example.org) makes no sense for biboumi
 *
 * irc.example.org:
 * - local: ""
 * - server: "irc.example.org"
 * - type: server
 */
class Iid
{
public:
  enum class Type
  {
      Channel,
      User,
      Server,
      None,
  };
  static constexpr char separator[]{"%"};
  Iid(const std::string& iid, const std::set<char>& chantypes);
  Iid(const std::string& iid, const std::initializer_list<char>& chantypes);
  Iid(const std::string& iid, const Bridge* bridge);
  Iid(const std::string& local, const std::string& server, Type type);
  Iid() = default;
  Iid(const Iid&) = default;

  Iid(Iid&&) = delete;
  Iid& operator=(const Iid&) = delete;
  Iid& operator=(Iid&&) = delete;

  void set_local(const std::string& loc);
  void set_server(const std::string& serv);

  const std::string& get_local() const;
  const std::string get_encoded_local() const;
  const std::string& get_server() const;

  std::tuple<std::string, std::string> to_tuple() const;

  Type type { Type::Server };

private:

  void init(const std::string& iid);
  void set_type(const std::set<char>& chantypes);

  std::string local;
  std::string server;
};

namespace std {
  const std::string to_string(const Iid& iid);
}