OpenWalnut  1.4.0
WSubject.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 
00029 #include "../common/WLogger.h"
00030 
00031 #include "WDataSet.h"
00032 #include "exceptions/WDHNoSuchDataSet.h"
00033 
00034 #include "WSubject.h"
00035 
00036 WSubject::WSubject():
00037     m_datasets(),
00038     m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00039     m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00040     m_personalInfo( WPersonalInformation::createDummyInformation() )
00041 {
00042 }
00043 
00044 WSubject::WSubject( WPersonalInformation personInfo ):
00045     m_datasets(),
00046     m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00047     m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00048     m_personalInfo( personInfo )
00049 {
00050 }
00051 
00052 WSubject::~WSubject()
00053 {
00054     clear();
00055 }
00056 
00057 std::string WSubject::getName() const
00058 {
00059     return m_personalInfo.getCompleteName();
00060 }
00061 
00062 WPersonalInformation WSubject::getPersonalInformation() const
00063 {
00064     return m_personalInfo;
00065 }
00066 
00067 void WSubject::addDataSet( boost::shared_ptr< WDataSet > dataset )
00068 {
00069     // simply add the new dataset
00070     m_datasets.push_back( dataset );
00071     m_changeCondition->notify();
00072     m_listChangeCondition->notify();
00073 }
00074 
00075 void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
00076 {
00077     DatasetSharedContainerType::WriteTicket l = m_datasets.getWriteTicket();
00078 
00079     // iterate and find, remove
00080     DatasetIterator fIt = std::find( l->get().begin(), l->get().end(), dataset );
00081     l->get().erase( fIt );
00082 
00083     // unlock if some callback notified below wants to access the list
00084     l.reset();
00085 
00086     m_changeCondition->notify();
00087     m_listChangeCondition->notify();
00088 }
00089 
00090 void WSubject::clear()
00091 {
00092     DatasetSharedContainerType::WriteTicket l = m_datasets.getWriteTicket();
00093     l->get().clear();
00094 
00095     // unlock if some callback notified below wants to access the list
00096     l.reset();
00097 
00098     m_listChangeCondition->notify();
00099 }
00100 
00101 WSubject::DatasetSharedContainerType::ReadTicket WSubject::getDatasets() const
00102 {
00103     return m_datasets.getReadTicket();
00104 }
00105 
00106 WSubject::DatasetSharedContainerType::WriteTicket WSubject::getDatasetsForWriting() const
00107 {
00108     return m_datasets.getWriteTicket();
00109 }
00110 
00111 boost::shared_ptr< WCondition > WSubject::getChangeCondition() const
00112 {
00113     return m_changeCondition;
00114 }
00115 
00116 boost::shared_ptr< WCondition > WSubject::getListChangeCondition() const
00117 {
00118     return m_listChangeCondition;
00119 }