ircresponseparseresult.cpp
1 //------------------------------------------------------------------------------
2 // ircresponseparseresult.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2011 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "ircresponseparseresult.h"
24 
25 #include "irc/constants/ircresponsetype.h"
26 
27 // This is returned by IRCResponseParseResult::type() if the result is invalid.
28 // Do not modify contents of this var!
29 const IRCResponseType invalidResponseType;
30 
32 {
33  d.pResponseType = nullptr;
34  d.bWasParsed = false;
35 }
36 
38 {
39  d.bWasParsed = bWasParsed;
40  d.pResponseType = new IRCResponseType(responseType);
41 }
42 
44 {
45  d.pResponseType = nullptr;
46  copyIn(other);
47 }
48 
49 IRCResponseParseResult::~IRCResponseParseResult()
50 {
51  if (d.pResponseType != nullptr)
52  delete d.pResponseType;
53 }
54 
55 void IRCResponseParseResult::copyIn(const IRCResponseParseResult &other)
56 {
57  d.bWasParsed = other.d.bWasParsed;
58  if (d.pResponseType != nullptr)
59  {
60  delete d.pResponseType;
61  d.pResponseType = nullptr;
62  }
63 
64  if (other.d.pResponseType != nullptr)
65  d.pResponseType = new IRCResponseType(*other.d.pResponseType);
66 }
67 
68 IRCResponseParseResult &IRCResponseParseResult::operator=(const IRCResponseParseResult &other)
69 {
70  if (this != &other)
71  copyIn(other);
72 
73  return *this;
74 }
75 
77 {
78  if (d.pResponseType == nullptr)
79  return invalidResponseType;
80 
81  return *d.pResponseType;
82 }