Skip to content

Commit

Permalink
Add CMessage::Clone()
Browse files Browse the repository at this point in the history
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<CJoinMessage&>(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.
  • Loading branch information
jpnurmi committed Aug 30, 2015
1 parent de4ffb1 commit 82375ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/znc/Message.h
Expand Up @@ -31,6 +31,8 @@ class CMessage {
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; }
Expand Down
7 changes: 7 additions & 0 deletions src/Message.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 82375ee

Please sign in to comment.