OpenWalnut  1.4.0
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 }
DatasetSharedContainerType::WriteTicket getDatasetsForWriting() const
Returns write-access to the dataset list.
Definition: WSubject.cpp:106
boost::shared_ptr< WSharedObjectTicketWrite< DatasetContainerType > > WriteTicket
Type for write tickets.
Definition: WSharedObject.h:69
WPersonalInformation getPersonalInformation() const
Gives the personal information of a subject.
Definition: WSubject.cpp:62
void push_back(const typename S::value_type &x)
Adds a new element at the end of the container.
WPersonalInformation m_personalInfo
Information on the person represented by this WSubject.
Definition: WSubject.h:178
DatasetSharedContainerType m_datasets
A container for all WDataSet.
Definition: WSubject.h:165
std::string getName() const
Returns the name of the subject.
Definition: WSubject.cpp:57
boost::shared_ptr< WCondition > getChangeCondition() const
This condition fires whenever the list of datasets changes, or one dataset got marked as "dirty" (thr...
Definition: WSubject.cpp:111
DatasetContainerType::iterator DatasetIterator
The dataset iterator.
Definition: WSubject.h:76
virtual ~WSubject()
Destructs the subject.
Definition: WSubject.cpp:52
void addDataSet(boost::shared_ptr< WDataSet > dataset)
Insert a new dataset referenced by a pointer.
Definition: WSubject.cpp:67
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
DatasetSharedContainerType::ReadTicket getDatasets() const
Returns read-access to the dataset list.
Definition: WSubject.cpp:101
std::string getCompleteName() const
Returns the name of the subject.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
Class allowing multiple conditions to be used for one waiting cycle.
Definition: WConditionSet.h:46
boost::shared_ptr< WConditionSet > m_listChangeCondition
This condition set fires whenever the list of datasets changes.
Definition: WSubject.h:175
WSubject()
Constructs a dummy subject.
Definition: WSubject.cpp:36
void removeDataSet(boost::shared_ptr< WDataSet > dataset)
Removes the specified dataset if it is in the set.
Definition: WSubject.cpp:75
boost::shared_ptr< WConditionSet > m_changeCondition
This condition set fires whenever one dataset gets dirty or the list of datasets changes.
Definition: WSubject.h:170
A structure that holds all relevant information about the subject.
boost::shared_ptr< WCondition > getListChangeCondition() const
This condition fires whenever the list of datasets changes.
Definition: WSubject.cpp:116
boost::shared_ptr< WSharedObjectTicketRead< DatasetContainerType > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:64
void clear()
Remove all datasets from the subjects.
Definition: WSubject.cpp:90