1 #pragma once 2 3 4 #include <string> 5 #include <set> 6 7 class Bridge; 8 9 /** 10 * A name representing an IRC channel on an IRC server, or an IRC user on an 11 * IRC server, or just an IRC server. 12 * 13 * The separator is '%' between the local part (nickname or channel) and the 14 * server part. If no separator is present, it's just an irc server. 15 * If it is present, the first character of the local part determines if it’s 16 * a channel or a user: ff the local part is empty or if its first character 17 * is part of the chantypes characters, then it’s a channel, otherwise it’s 18 * a user. 19 * 20 * It’s possible to have an empty-string server, but it makes no sense in 21 * biboumi’s context. 22 * 23 * Assuming the chantypes are '#' and '&': 24 * 25 * #test%irc.example.org has : 26 * - local: "#test" (the # is part of the name, it could very well be absent, or & (for example) instead) 27 * - server: "irc.example.org" 28 * - type: channel 29 * 30 * %irc.example.org: 31 * - local: "" 32 * - server: "irc.example.org" 33 * - type: channel 34 * Note: this is the special empty-string channel, used internally in biboumi 35 * but has no meaning on IRC. 36 * 37 * foo%irc.example.org 38 * - local: "foo" 39 * - server: "irc.example.org" 40 * - type: user 41 * Note: the empty-string user (!irc.example.org) makes no sense for biboumi 42 * 43 * irc.example.org: 44 * - local: "" 45 * - server: "irc.example.org" 46 * - type: server 47 */ 48 class Iid 49 { 50 public: 51 enum class Type 52 { 53 Channel, 54 User, 55 Server, 56 None, 57 }; 58 static constexpr char separator[]{"%"}; 59 Iid(const std::string& iid, const std::set<char>& chantypes); 60 Iid(const std::string& iid, const std::initializer_list<char>& chantypes); 61 Iid(const std::string& iid, const Bridge* bridge); 62 Iid(std::string local, std::string server, Type type); 63 Iid() = default; 64 Iid(const Iid&) = default; 65 66 Iid(Iid&&) = delete; 67 Iid& operator=(const Iid&) = delete; 68 Iid& operator=(Iid&&) = delete; 69 70 void set_local(const std::string& loc); 71 void set_server(const std::string& serv); 72 73 const std::string& get_local() const; 74 const std::string get_encoded_local() const; 75 const std::string& get_server() const; 76 77 std::tuple<std::string, std::string> to_tuple() const; 78 79 Type type { Type::Server }; 80 81 private: 82 83 void init(const std::string& iid); 84 void set_type(const std::set<char>& chantypes); 85 86 std::string local; 87 std::string server; 88 }; 89 90 namespace std { 91 const std::string to_string(const Iid& iid); 92 } 93 94 95