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