Qualia  0.2
Action.h
Go to the documentation of this file.
1 /*
2  * Action.h
3  *
4  * Actions in Qualia are always discrete. A specific action is represented by a multi-dimensional
5  * array of integers. Meta-informations about the actions (dimensions and number of actions per
6  * dimension) are contained withing an ActionProperties object that can be shared accross many actions.
7  *
8  * This file is part of Qualia https://github.com/sofian/qualia
9  *
10  * (c) 2011 Sofian Audry -- info(@)sofianaudry(.)com
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef ACTION_H_
27 #define ACTION_H_
28 
29 #include <qualia/core/common.h>
30 #include <qualia/core/XFile.h>
31 #include <qualia/util/random.h>
32 
33 #include <string.h>
34 
35 typedef unsigned long action_t;
36 typedef unsigned int action_dim_t;
37 
43 public:
44  // Internal use.
45  unsigned int _dim; // dimension of data
46  unsigned int* _nActions; // number of actions per dimension
47  unsigned long _nConflated; // number of conflated actions = \prod_i nActions(i)
48 
50  ActionProperties(unsigned int dim, const unsigned int* nActions);
51 
53  virtual ~ActionProperties();
54 
56  unsigned int dim() const { return _dim; }
57 
59  unsigned long nConflated() const { return _nConflated; }
60 
62  unsigned int nActions(int i) const { return _nActions[i]; }
63 
65  bool equals(const ActionProperties& p) const;
66 
68  action_t random() const { return (action_t) ::random(nConflated()); }
69 };
70 
80 class Action {
81 public:
84 
87 
89  bool _undefined;
90 
93 
95  virtual ~Action();
96 
98  action_dim_t& operator[](int i) const { return actions[i]; }
99 
101  virtual action_t conflated() const;
102 
104  virtual Action& setConflated(action_t action);
105 
107  bool undefined() const { return _undefined; }
108 
109  // Iterator methods.
110 
114  virtual Action& reset();
115 
117  virtual bool hasNext();
118 
123  virtual Action& next();
124 
126  virtual Action& copyFrom(const Action& src);
127 
129  unsigned int dim() const { return properties->dim(); }
130 
132  unsigned long nConflated() const { return properties->nConflated(); }
133 
135  unsigned int nActions(int i) const { return properties->nActions(i); }
136 
137  // TODO: remove dim / nAtions / etc from class and put it in some sort of TemplateAction class
138  // otherwise the save/load are not really what they look like. This is why I named them saveData/loadData
139  // instead of just save/load.
141  virtual void saveData(XFile* file) const;
142 
144  virtual void loadData(XFile* file);
145 };
146 
147 #endif /* ACTION_H_ */