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 #include <boost/lexical_cast.hpp>
00029 
00030 #include "../common/WLogger.h"
00031 
00032 #include "WDataSet.h"
00033 #include "exceptions/WDHNoSuchDataSet.h"
00034 
00035 #include "WSubject.h"
00036 
00037 WSubject::WSubject():
00038     m_datasets(),
00039     m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00040     m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00041     m_personalInfo( WPersonalInformation::createDummyInformation() )
00042 {
00043 }
00044 
00045 WSubject::WSubject( WPersonalInformation personInfo ):
00046     m_datasets(),
00047     m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00048     m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
00049     m_personalInfo( personInfo )
00050 {
00051 }
00052 
00053 WSubject::~WSubject()
00054 {
00055     clear();
00056 }
00057 
00058 std::string WSubject::getName() const
00059 {
00060     return m_personalInfo.getCompleteName();
00061 }
00062 
00063 WPersonalInformation WSubject::getPersonalInformation() const
00064 {
00065     return m_personalInfo;
00066 }
00067 
00068 void WSubject::addDataSet( boost::shared_ptr< WDataSet > dataset )
00069 {
00070     // simply add the new dataset
00071     m_datasets.push_back( dataset );
00072     m_changeCondition->notify();
00073     m_listChangeCondition->notify();
00074 }
00075 
00076 void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
00077 {
00078     DatasetSharedContainerType::WriteTicket l = m_datasets.getWriteTicket();
00079 
00080     // iterate and find, remove
00081     DatasetIterator fIt = std::find( l->get().begin(), l->get().end(), dataset );
00082     l->get().erase( fIt );
00083 
00084     // unlock if some callback notified below wants to access the list
00085     l.reset();
00086 
00087     m_changeCondition->notify();
00088     m_listChangeCondition->notify();
00089 }
00090 
00091 void WSubject::clear()
00092 {
00093     DatasetSharedContainerType::WriteTicket l = m_datasets.getWriteTicket();
00094     l->get().clear();
00095 
00096     // unlock if some callback notified below wants to access the list
00097     l.reset();
00098 
00099     m_listChangeCondition->notify();
00100 }
00101 
00102 WSubject::DatasetSharedContainerType::ReadTicket WSubject::getDatasets() const
00103 {
00104     return m_datasets.getReadTicket();
00105 }
00106 
00107 WSubject::DatasetSharedContainerType::WriteTicket WSubject::getDatasetsForWriting() const
00108 {
00109     return m_datasets.getWriteTicket();
00110 }
00111 
00112 boost::shared_ptr< WCondition > WSubject::getChangeCondition() const
00113 {
00114     return m_changeCondition;
00115 }
00116 
00117 boost::shared_ptr< WCondition > WSubject::getListChangeCondition() const
00118 {
00119     return m_listChangeCondition;
00120 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends