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