OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #include <boost/lexical_cast.hpp>
29 
30 #include "../common/WLogger.h"
31 
32 #include "WDataSet.h"
33 #include "exceptions/WDHNoSuchDataSet.h"
34 
35 #include "WSubject.h"
36 
38  m_datasets(),
39  m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
40  m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
41  m_personalInfo( WPersonalInformation::createDummyInformation() )
42 {
43 }
44 
46  m_datasets(),
47  m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
48  m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
49  m_personalInfo( personInfo )
50 {
51 }
52 
54 {
55  clear();
56 }
57 
58 std::string WSubject::getName() const
59 {
61 }
62 
64 {
65  return m_personalInfo;
66 }
67 
68 void WSubject::addDataSet( boost::shared_ptr< WDataSet > dataset )
69 {
70  // simply add the new dataset
71  m_datasets.push_back( dataset );
72  m_changeCondition->notify();
73  m_listChangeCondition->notify();
74 }
75 
76 void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
77 {
79 
80  // iterate and find, remove
81  DatasetIterator fIt = std::find( l->get().begin(), l->get().end(), dataset );
82  l->get().erase( fIt );
83 
84  // unlock if some callback notified below wants to access the list
85  l.reset();
86 
87  m_changeCondition->notify();
88  m_listChangeCondition->notify();
89 }
90 
92 {
94  l->get().clear();
95 
96  // unlock if some callback notified below wants to access the list
97  l.reset();
98 
99  m_listChangeCondition->notify();
100 }
101 
103 {
104  return m_datasets.getReadTicket();
105 }
106 
108 {
109  return m_datasets.getWriteTicket();
110 }
111 
112 boost::shared_ptr< WCondition > WSubject::getChangeCondition() const
113 {
114  return m_changeCondition;
115 }
116 
117 boost::shared_ptr< WCondition > WSubject::getListChangeCondition() const
118 {
119  return m_listChangeCondition;
120 }