OpenWalnut  1.5.0dev
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 <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "../common/WLogger.h"
30 #include "WDataSet.h"
31 #include "WSubject.h"
32 #include "exceptions/WDHNoSuchDataSet.h"
33 
35  m_datasets(),
36  m_changeCondition( std::shared_ptr< WConditionSet >( new WConditionSet() ) ),
37  m_listChangeCondition( std::shared_ptr< WConditionSet >( new WConditionSet() ) ),
38  m_personalInfo( WPersonalInformation::createDummyInformation() )
39 {
40 }
41 
43  m_datasets(),
44  m_changeCondition( std::shared_ptr< WConditionSet >( new WConditionSet() ) ),
45  m_listChangeCondition( std::shared_ptr< WConditionSet >( new WConditionSet() ) ),
46  m_personalInfo( personInfo )
47 {
48 }
49 
51 {
52  clear();
53 }
54 
55 std::string WSubject::getName() const
56 {
58 }
59 
61 {
62  return m_personalInfo;
63 }
64 
65 void WSubject::addDataSet( std::shared_ptr< WDataSet > dataset )
66 {
67  // simply add the new dataset
68  m_datasets.push_back( dataset );
69  m_changeCondition->notify();
70  m_listChangeCondition->notify();
71 }
72 
73 void WSubject::removeDataSet( std::shared_ptr< WDataSet > dataset )
74 {
76 
77  // iterate and find, remove
78  DatasetIterator fIt = std::find( l->get().begin(), l->get().end(), dataset );
79  l->get().erase( fIt );
80 
81  // unlock if some callback notified below wants to access the list
82  l.reset();
83 
84  m_changeCondition->notify();
85  m_listChangeCondition->notify();
86 }
87 
89 {
91  l->get().clear();
92 
93  // unlock if some callback notified below wants to access the list
94  l.reset();
95 
96  m_listChangeCondition->notify();
97 }
98 
100 {
101  return m_datasets.getReadTicket();
102 }
103 
105 {
106  return m_datasets.getWriteTicket();
107 }
108 
109 std::shared_ptr< WCondition > WSubject::getChangeCondition() const
110 {
111  return m_changeCondition;
112 }
113 
114 std::shared_ptr< WCondition > WSubject::getListChangeCondition() const
115 {
116  return m_listChangeCondition;
117 }
Class allowing multiple conditions to be used for one waiting cycle.
Definition: WConditionSet.h:44
A structure that holds all relevant information about the subject.
std::string getCompleteName() const
Returns the name of the subject.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
Definition: WSharedObject.h:70
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
void push_back(const typename S::value_type &x)
Adds a new element at the end of the container.
DatasetContainerType::iterator DatasetIterator
The dataset iterator.
Definition: WSubject.h:74
DatasetSharedContainerType::WriteTicket getDatasetsForWriting() const
Returns write-access to the dataset list.
Definition: WSubject.cpp:104
std::shared_ptr< WConditionSet > m_listChangeCondition
This condition set fires whenever the list of datasets changes.
Definition: WSubject.h:173
void removeDataSet(std::shared_ptr< WDataSet > dataset)
Removes the specified dataset if it is in the set.
Definition: WSubject.cpp:73
DatasetSharedContainerType m_datasets
A container for all WDataSet.
Definition: WSubject.h:163
std::shared_ptr< WCondition > getListChangeCondition() const
This condition fires whenever the list of datasets changes.
Definition: WSubject.cpp:114
WSubject()
Constructs a dummy subject.
Definition: WSubject.cpp:34
DatasetSharedContainerType::ReadTicket getDatasets() const
Returns read-access to the dataset list.
Definition: WSubject.cpp:99
WPersonalInformation getPersonalInformation() const
Gives the personal information of a subject.
Definition: WSubject.cpp:60
WPersonalInformation m_personalInfo
Information on the person represented by this WSubject.
Definition: WSubject.h:176
std::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:109
void clear()
Remove all datasets from the subjects.
Definition: WSubject.cpp:88
virtual ~WSubject()
Destructs the subject.
Definition: WSubject.cpp:50
std::shared_ptr< WConditionSet > m_changeCondition
This condition set fires whenever one dataset gets dirty or the list of datasets changes.
Definition: WSubject.h:168
std::string getName() const
Returns the name of the subject.
Definition: WSubject.cpp:55
void addDataSet(std::shared_ptr< WDataSet > dataset)
Insert a new dataset referenced by a pointer.
Definition: WSubject.cpp:65