blob: 36a2efcd0971126a167e1a9e3799d24e638300c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OBJECT_H
#define OBJECT_H
#include <vector>
#include <string>
class Object
{
/*
* abstract class that all usable objects should subclass
*/
public:
Object() { id = object_id_counter++; }; // default constructor for all objects
Object(int id_) { id = id_; }; // overloaded constructor for passing id - used when loading
/*
* this enum is an internal reference to every object, each cobject needs an entry here
*/
enum OBJECT_TYPE
{
NONE = 0,
GATE,
BINARYDISPLAY,
};
virtual ~Object() = default;
int get_id() { return this->id; };
int get_x() { return this->x; };
int get_y() { return this->y; };
int get_width() { return this->w; };
int get_height() { return this->h; };
void set_x(int x) { this->x = x; };
void set_y(int y) { this->y = y; };
void add_output_object_id(int id) { this->output_object_ids.push_back(id); };
virtual void update_state() {}; // subclasses must implement
static void set_object_id_counter(int id) { object_id_counter = id; };
static int get_object_id_counter() { return object_id_counter; };
OBJECT_TYPE get_object_type() { return object_type; };
virtual std::string get_object_name() { return "NOT IMPLEMENTED"; };
std::vector<int> *get_output_objects() { return &this->output_object_ids; };
void remove_output_object_id(int id)
{
int pos = 0;
for(auto o = output_object_ids.begin(); o != output_object_ids.end(); ++o)
{
if (id == (*o))
{
output_object_ids.erase(output_object_ids.begin() + pos);
break;
}
pos++;
}
}
bool get_output_state() { return this->output_state; };
void set_state(bool state) { this->output_state = state; };
protected:
int id;
int x;
int y;
int w;
int h;
std::vector<int> output_object_ids;
void set_object_type(OBJECT_TYPE type) { object_type = type; }; // every object must set this, none by default
static int object_id_counter; // used as the id of a new objecct - this is NOT a count of the number of objects
/* states */
bool output_state = false;
private:
enum OBJECT_TYPE object_type = NONE;
};
#endif
|