OpenWalnut  1.3.1
WSubject.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 #include <vector>
27 
28 
29 #include "../common/WLogger.h"
30 
31 #include "WDataSet.h"
32 #include "exceptions/WDHNoSuchDataSet.h"
33 
34 #include "WSubject.h"
35 
37  m_datasets(),
38  m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
39  m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
40  m_personalInfo( WPersonalInformation::createDummyInformation() )
41 {
42 }
43 
45  m_datasets(),
46  m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
47  m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
48  m_personalInfo( personInfo )
49 {
50 }
51 
53 {
54  clear();
55 }
56 
57 std::string WSubject::getName() const
58 {
60 }
61 
63 {
64  return m_personalInfo;
65 }
66 
67 void WSubject::addDataSet( boost::shared_ptr< WDataSet > dataset )
68 {
69  // simply add the new dataset
70  m_datasets.push_back( dataset );
71  m_changeCondition->notify();
72  m_listChangeCondition->notify();
73 }
74 
75 void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
76 {
78 
79  // iterate and find, remove
80  DatasetIterator fIt = std::find( l->get().begin(), l->get().end(), dataset );
81  l->get().erase( fIt );
82 
83  // unlock if some callback notified below wants to access the list
84  l.reset();
85 
86  m_changeCondition->notify();
87  m_listChangeCondition->notify();
88 }
89 
91 {
93  l->get().clear();
94 
95  // unlock if some callback notified below wants to access the list
96  l.reset();
97 
98  m_listChangeCondition->notify();
99 }
100 
102 {
103  return m_datasets.getReadTicket();
104 }
105 
107 {
108  return m_datasets.getWriteTicket();
109 }
110 
111 boost::shared_ptr< WCondition > WSubject::getChangeCondition() const
112 {
113  return m_changeCondition;
114 }
115 
116 boost::shared_ptr< WCondition > WSubject::getListChangeCondition() const
117 {
118  return m_listChangeCondition;
119 }