From 82375eed65975ceca8f9f52b8be4fe1f4dbde809 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 16 Aug 2015 23:25:15 +0200 Subject: [PATCH] Add CMessage::Clone() Due to (intentional) lack of CFooMessage::operator=(CMessage), it was a bit clumsy to do such copy-conversions: CMessage Copy = Message; CJoinMessage& JoinMsg = static_cast(Copy); // ... vs. CJoinMessge JoinMsg; JoinMsg.Clone(Message); // ... Alternatively, copy ctor(CMessage) and assignment operator=(CMessage) could have been added to all CMessage subclasses. I've been trying to avoid that, to make these operations very explicit. It has helped a lot so far by preventing accidental copies. --- include/znc/Message.h | 2 ++ src/Message.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/znc/Message.h b/include/znc/Message.h index de676f3a..2270c9a9 100644 --- a/include/znc/Message.h +++ b/include/znc/Message.h @@ -31,6 +31,8 @@ public: explicit CMessage(const CString& sMessage = ""); CMessage(const CNick& Nick, const CString& sCommand, const VCString& vsParams = VCString(), const MCString& mssTags = MCString::EmptyMap); + void Clone(const CMessage& Other); + // ZNC <-> IRC CIRCNetwork* GetNetwork() const { return m_pNetwork; } void SetNetwork(CIRCNetwork* pNetwork) { m_pNetwork = pNetwork; } diff --git a/src/Message.cpp b/src/Message.cpp index fee78e39..56a616fe 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -29,6 +29,13 @@ CMessage::CMessage(const CNick& Nick, const CString& sCommand, const VCString& v InitTime(); } +void CMessage::Clone(const CMessage& Message) +{ + if (&Message != this) { + *this = Message; + } +} + CString CMessage::GetParams(unsigned int uIdx, unsigned int uLen) const { VCString vsParams;