Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/external/wiicpp/log/dataset.h @ 9780

Last change on this file since 9780 was 9780, checked in by georgr, 10 years ago

WiiCpp library successfully (?) added - won't work without libbluetooth-dev

File size: 3.0 KB
Line 
1/** \file dataset.h
2 * Header file of the class Dataset.
3 */
4#ifndef DATASET_H
5#define DATASET_H
6
7#include "training.h"
8
9/**
10 * \class Dataset
11 *
12 * A Dataset is a collection of trainings, which can represent multiple gestures
13 * acquired over time, with different lenghts, and with different approaches.
14 */
15class Dataset
16{
17public:
18        /**
19         * Default constructor.
20         */
21        Dataset() : loaded(false) { }
22       
23        /**
24         * Creates a Dataset object from a log file.
25         *
26         * @param filename Pathname of the dataset to load
27         */
28        Dataset(const string& filename) : loaded(false) { loadDataset(filename); }
29        ~Dataset();
30
31        /**
32         * Retrieves the dataset's size.
33         *
34         * \return the number of trainings collected in the current dataset
35         */
36        inline unsigned int size() const { return trainings.size(); }
37
38        /**
39         * Returns a training in the dataset as a constant pointer.
40         *
41         * @param[in] i The training index in the dataset
42         *
43         * \return A constant pointer to the Training object corresponding to the i-th element in the dataset
44         */
45        inline const Training* trainingAt(const unsigned int i) const { 
46                if(i < trainings.size())
47                        return trainings[i]; 
48                else {
49                        cout << "[Error]: requested out of array bound index in dataset." << endl;
50                        return 0;
51                }
52        }
53
54        /**
55         * Returns a training in the dataset as a pointer.
56         *
57         * @param[in] i The training index in the dataset
58         *
59         * \return A pointer to the Training object corresponding to the i-th element in the dataset
60         */
61        inline Training* trainingAt(const unsigned int i) { 
62                if(i < trainings.size())
63                        return trainings[i]; 
64                else {
65                        cout << "[Error]: requested out of array bound index in dataset." << endl;
66                        return 0;
67                }
68        }
69
70        /**
71         * Adds a training to the dataset. The new element will be indexed as the last element and
72         * will not be copied. It will be responsability of the destructor of the class
73         * Dataset to deallocate this element.
74         *
75         * @param[in] training The training to add
76         */
77        void addTraining(Training* training);
78
79        /**
80         * Loads a new dataset from file, erasing the current one (if not saved on file).
81         *
82         * @param[in] filename Filename of the dataset to load
83         */
84        bool loadDataset(const string& filename);
85       
86        /**
87         * Saves the current dataset in a file.
88         *
89         * @param[in] filename Desired filename of the saved dataset
90         * @param[in] addr MAC address of the source device for the dataset
91         */
92        bool save(const char* filename, const char* addr) const;
93       
94        /**
95         * Deallocates and deletes all the current trainings in the dataset.
96         */
97        void clear() ;
98
99        /**
100         * Checks if the instance has a valid dataset loaded.
101         *
102         * \return TRUE if a dataset is correctly loaded, FALSE otherwise
103         */
104        inline bool isValid() const { return loaded; }
105
106protected:
107        /**
108         * Saves the initial header of WiiC's log files.
109         *
110         * @param[in] out The output stream of the log file
111         * @param[in] addr MAC address of the source device for the dataset
112         */
113        void saveHeader(ofstream& out, const char* addr) const;
114
115private:
116        vector<Training*> trainings;
117        bool loaded;
118};
119
120#endif
Note: See TracBrowser for help on using the repository browser.