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