E-MailRelay
gmessagestore.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // gmessagestore.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gsmtp.h"
23 #include "gmessagestore.h"
24 #include "glog.h"
25 #include "gassert.h"
26 
28 {
29 }
30 
31 // ===
32 
33 GSmtp::MessageStore::IteratorImp::IteratorImp() :
34  m_ref_count(1UL)
35 {
36 }
37 
38 GSmtp::MessageStore::IteratorImp::~IteratorImp()
39 {
40 }
41 
42 // ===
43 
44 GSmtp::MessageStore::Iterator::Iterator() :
45  m_imp(nullptr)
46 {
47 }
48 
49 GSmtp::MessageStore::Iterator::Iterator( IteratorImp * imp ) :
50  m_imp(imp)
51 {
52  G_ASSERT( m_imp->m_ref_count == 1UL ) ;
53 }
54 
55 unique_ptr<GSmtp::StoredMessage> GSmtp::MessageStore::Iterator::next()
56 {
57  return m_imp ? m_imp->next() : unique_ptr<StoredMessage>() ;
58 }
59 
60 GSmtp::MessageStore::Iterator::~Iterator()
61 {
62  if( m_imp )
63  {
64  m_imp->m_ref_count-- ;
65  if( m_imp->m_ref_count == 0UL )
66  delete m_imp ;
67  }
68 }
69 
70 GSmtp::MessageStore::Iterator::Iterator( const Iterator & other ) :
71  m_imp(other.m_imp)
72 {
73  if( m_imp )
74  m_imp->m_ref_count++ ;
75 }
76 
77 GSmtp::MessageStore::Iterator & GSmtp::MessageStore::Iterator::operator=( const Iterator & rhs )
78 {
79  if( this != &rhs )
80  {
81  if( m_imp )
82  {
83  m_imp->m_ref_count-- ;
84  if( m_imp->m_ref_count == 0UL )
85  delete m_imp ;
86  }
87  m_imp = rhs.m_imp ;
88  if( m_imp )
89  {
90  m_imp->m_ref_count++ ;
91  }
92  }
93  return *this ;
94 }
95 
96 void GSmtp::MessageStore::Iterator::last()
97 {
98  IteratorImp * imp = m_imp ;
99  m_imp = nullptr ;
100  delete imp ;
101 }
102 
103 /// \file gmessagestore.cpp
virtual ~MessageStore()
Destructor.
Definition: gbase64.cpp:27
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:55