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