OpenWalnut  1.4.0
WDataHandler.h
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 #ifndef WDATAHANDLER_H
26 #define WDATAHANDLER_H
27 
28 #include <string>
29 #include <vector>
30 
31 #ifndef Q_MOC_RUN
32 #include <boost/thread.hpp>
33 #endif
34 #ifndef Q_MOC_RUN
35 #include <boost/shared_ptr.hpp>
36 #endif
37 #ifndef Q_MOC_RUN
38 #include <boost/enable_shared_from_this.hpp>
39 #endif
40 
41 #include "../common/WSharedObject.h"
42 #include "../common/WSharedSequenceContainer.h"
43 
44 #include "WDataSet.h"
45 
46 
47 class WSubject;
48 
49 /**
50  * Provides the environment for storing and accessing different subjects.
51  * As all measured data belongs to one subject, this is the main access point
52  * to our data.
53  *
54  * \ingroup dataHandler
55  */
56 class WDataHandler // NOLINT
57 {
58 /**
59  * Only UnitTests may be friends.
60  */
61 friend class WDataHandlerTest;
62 
63 public:
64  /**
65  * For shortening: a type defining a shared vector of WSubject pointers.
66  */
67  typedef std::vector< boost::shared_ptr< WSubject > > SubjectContainerType;
68 
69  /**
70  * The alias for a shared container.
71  */
73 
74  /**
75  * Iterator for subjects.
76  */
77  typedef SubjectContainerType::const_iterator SubjectConstIterator;
78 
79  /**
80  * Iterator for subjects.
81  */
82  typedef SubjectContainerType::iterator SubjectIterator;
83 
84  /**
85  * Empty standard constructor.
86  */
87  WDataHandler();
88 
89  /**
90  * Destructor.
91  */
92  virtual ~WDataHandler();
93 
94  /**
95  * As WDataHandler is a singleton -> return instance.
96  *
97  * \return the instance.
98  */
99  static boost::shared_ptr< WDataHandler > getDataHandler();
100 
101  /**
102  * Insert a new subject referenced by a pointer.
103  *
104  * \param subject a pointer to the subject that will be added
105  */
106  void addSubject( boost::shared_ptr< WSubject > subject );
107 
108  /**
109  * Removes the specified subject if it is in the set.
110  *
111  * \param subject the subject to remove.
112  */
113  void removeSubject( boost::shared_ptr< WSubject > subject );
114 
115  /**
116  * Remove all subjects.
117  */
118  void clear();
119 
120  /**
121  * Returns the subject which corresponds to the specified ID. It throws an exception, if the subject does not exists anymore.
122  *
123  * \note the ID might be not equal to the ID in the subjects personal information. This will (maybe) be changed later.
124  *
125  * \param subjectID the ID to search the subject for
126  *
127  * \return the subject.
128  *
129  * \throw WNoSuchSubject in case the subject can't be found.
130  */
131  boost::shared_ptr< WSubject > getSubjectByID( size_t subjectID );
132 
133  /**
134  * Gets the subject with the ID SUBJECT_UNKNOWN.
135  *
136  * \note this may be removed whenever we have a proper multi subject handling.
137  *
138  * \return the subject.
139  */
140  static boost::shared_ptr< WSubject > getDefaultSubject();
141 
142  /**
143  * Returns read-access to the list of subjects.
144  * \note as long as you own the read ticket, the list is not changed by others.
145  *
146  * \return the list of subjects.
147  */
149 
150 protected:
151  /**
152  * A container for all WSubjects.
153  */
154  SubjectSharedContainerType m_subjects;
155 
156 private:
157  /**
158  * Singleton instance of WDataHandler.
159  */
160  static boost::shared_ptr< WDataHandler > m_instance;
161 };
162 
163 /**
164  * \defgroup dataHandler Data Handler
165  *
166  * \brief
167  * This library implements the data storage facility of OpenWalnut.
168  */
169 
170 #endif // WDATAHANDLER_H
Container for all WDataSets belonging to one subject or patient.
Definition: WSubject.h:47
virtual ~WDataHandler()
Destructor.
Test important functionality of WDataHandler class.
SubjectSharedContainerType::ReadTicket getSubjects() const
Returns read-access to the list of subjects.
std::vector< boost::shared_ptr< WSubject > > SubjectContainerType
For shortening: a type defining a shared vector of WSubject pointers.
Definition: WDataHandler.h:67
void removeSubject(boost::shared_ptr< WSubject > subject)
Removes the specified subject if it is in the set.
SubjectSharedContainerType m_subjects
A container for all WSubjects.
Definition: WDataHandler.h:154
WDataHandler()
Empty standard constructor.
static boost::shared_ptr< WSubject > getDefaultSubject()
Gets the subject with the ID SUBJECT_UNKNOWN.
void clear()
Remove all subjects.
void addSubject(boost::shared_ptr< WSubject > subject)
Insert a new subject referenced by a pointer.
static boost::shared_ptr< WDataHandler > getDataHandler()
As WDataHandler is a singleton -> return instance.
Provides the environment for storing and accessing different subjects.
Definition: WDataHandler.h:56
SubjectContainerType::iterator SubjectIterator
Iterator for subjects.
Definition: WDataHandler.h:82
SubjectContainerType::const_iterator SubjectConstIterator
Iterator for subjects.
Definition: WDataHandler.h:77
WSharedSequenceContainer< SubjectContainerType > SubjectSharedContainerType
The alias for a shared container.
Definition: WDataHandler.h:72
boost::shared_ptr< WSubject > getSubjectByID(size_t subjectID)
Returns the subject which corresponds to the specified ID.
boost::shared_ptr< WSharedObjectTicketRead< SubjectContainerType > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:64
static boost::shared_ptr< WDataHandler > m_instance
Singleton instance of WDataHandler.
Definition: WDataHandler.h:160