OpenWalnut  1.4.0
WDataHandler.h
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 #ifndef WDATAHANDLER_H
00026 #define WDATAHANDLER_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <boost/thread.hpp>
00032 #include <boost/shared_ptr.hpp>
00033 #include <boost/enable_shared_from_this.hpp>
00034 
00035 #include "../common/WSharedObject.h"
00036 #include "../common/WSharedSequenceContainer.h"
00037 
00038 #include "WDataSet.h"
00039 
00040 
00041 class WSubject;
00042 
00043 /**
00044  * Provides the environment for storing and accessing different subjects.
00045  * As all measured data belongs to one subject, this is the main access point
00046  * to our data.
00047  *
00048  * \ingroup dataHandler
00049  */
00050 class WDataHandler // NOLINT
00051 {
00052 /**
00053  * Only UnitTests may be friends.
00054  */
00055 friend class WDataHandlerTest;
00056 
00057 public:
00058     /**
00059      * For shortening: a type defining a shared vector of WSubject pointers.
00060      */
00061     typedef std::vector< boost::shared_ptr< WSubject > > SubjectContainerType;
00062 
00063     /**
00064      * The alias for a shared container.
00065      */
00066     typedef WSharedSequenceContainer< SubjectContainerType > SubjectSharedContainerType;
00067 
00068     /**
00069      * Iterator for subjects.
00070      */
00071     typedef SubjectContainerType::const_iterator SubjectConstIterator;
00072 
00073     /**
00074      * Iterator for subjects.
00075      */
00076     typedef SubjectContainerType::iterator SubjectIterator;
00077 
00078     /**
00079      * Empty standard constructor.
00080      */
00081     WDataHandler();
00082 
00083     /**
00084      * Destructor.
00085      */
00086     virtual ~WDataHandler();
00087 
00088     /**
00089      * As WDataHandler is a singleton -> return instance.
00090      *
00091      * \return the instance.
00092      */
00093     static boost::shared_ptr< WDataHandler > getDataHandler();
00094 
00095     /**
00096      * Insert a new subject referenced by a pointer.
00097      *
00098      * \param subject a pointer to the subject that will be added
00099      */
00100     void addSubject( boost::shared_ptr< WSubject > subject );
00101 
00102     /**
00103      * Removes the specified subject if it is in the set.
00104      *
00105      * \param subject the subject to remove.
00106      */
00107     void removeSubject( boost::shared_ptr< WSubject > subject );
00108 
00109     /**
00110      * Remove all subjects.
00111      */
00112     void clear();
00113 
00114     /**
00115      * Returns the subject which corresponds to the specified ID. It throws an exception, if the subject does not exists anymore.
00116      *
00117      * \note the ID might be not equal to the ID in the subjects personal information. This will (maybe) be changed later.
00118      *
00119      * \param subjectID the ID to search the subject for
00120      *
00121      * \return the subject.
00122      *
00123      * \throw WNoSuchSubject in case the subject can't be found.
00124      */
00125     boost::shared_ptr< WSubject > getSubjectByID( size_t subjectID );
00126 
00127     /**
00128      * Gets the subject with the ID SUBJECT_UNKNOWN.
00129      *
00130      * \note this may be removed whenever we have a proper multi subject handling.
00131      *
00132      * \return  the subject.
00133      */
00134     static boost::shared_ptr< WSubject > getDefaultSubject();
00135 
00136     /**
00137      * Returns read-access to the list of subjects.
00138      * \note as long as you own the read ticket, the list is not changed by others.
00139      *
00140      * \return the list of subjects.
00141      */
00142     SubjectSharedContainerType::ReadTicket getSubjects() const;
00143 
00144 protected:
00145     /**
00146      * A container for all WSubjects.
00147      */
00148     SubjectSharedContainerType m_subjects;
00149 
00150 private:
00151     /**
00152      * Singleton instance of WDataHandler.
00153      */
00154     static boost::shared_ptr< WDataHandler > m_instance;
00155 };
00156 
00157 /**
00158  * \defgroup dataHandler Data Handler
00159  *
00160  * \brief
00161  * This library implements the data storage facility of OpenWalnut.
00162  */
00163 
00164 #endif  // WDATAHANDLER_H