xref: /AOO41X/main/vcl/inc/vcl/impdel.hxx (revision 0d63794c5b3715d9f8da2f4b7b451b7426ee7897)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24  #ifndef _VCL_IMPDEL_HXX
25  #define _VCL_IMPDEL_HXX
26 
27  #include <list>
28 
29  namespace vcl
30  {
31 
32  class DeletionListener;
33 
34  class DeletionNotifier
35  {
36      std::list< DeletionListener* > m_aListeners;
37      protected:
DeletionNotifier()38      DeletionNotifier() {}
39 
~DeletionNotifier()40      ~DeletionNotifier()
41      { notifyDelete(); }
42 
43      inline void notifyDelete();
44 
45      public:
addDel(DeletionListener * pListener)46      void addDel( DeletionListener* pListener )
47      { m_aListeners.push_back( pListener ); }
48 
removeDel(DeletionListener * pListener)49      void removeDel( DeletionListener* pListener )
50      { m_aListeners.remove( pListener ); }
51  };
52 
53  class DeletionListener
54  {
55      DeletionNotifier*  m_pNotifier;
56      public:
DeletionListener(DeletionNotifier * pNotifier)57      DeletionListener( DeletionNotifier* pNotifier )
58      :  m_pNotifier( pNotifier )
59         {
60             if( m_pNotifier )
61                 m_pNotifier->addDel( this );
62         }
~DeletionListener()63     ~DeletionListener()
64     {
65         if( m_pNotifier )
66             m_pNotifier->removeDel( this );
67     }
deleted()68     void deleted() { m_pNotifier = NULL; }
isDeleted() const69     bool isDeleted() const { return (m_pNotifier == NULL); }
70  };
71 
notifyDelete()72  inline void DeletionNotifier::notifyDelete()
73  {
74      for( std::list< DeletionListener* >::const_iterator it =
75             m_aListeners.begin(); it != m_aListeners.end(); ++it )
76         (*it)->deleted();
77 
78      m_aListeners.clear();
79  }
80 
81  } // namespace vcl
82 
83  #endif // _VCL_IMPDEL_HXX
84