grasp
All Data Structures Namespaces Functions Modules
Polygon.h
1 // This is an automatically-generated file.
2 // It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
3 
4 #ifndef YARP_THRIFT_GENERATOR_STRUCT_Polygon
5 #define YARP_THRIFT_GENERATOR_STRUCT_Polygon
6 
7 #include <yarp/os/Wire.h>
8 #include <yarp/os/idl/WireTypes.h>
9 
10 namespace iCub {
11  namespace data3D {
12  class Polygon;
13  }
14 }
15 
16 
17 class iCub::data3D::Polygon : public yarp::os::idl::WirePortable {
18 public:
19  // Fields
20  std::vector<int32_t> vertices;
21 
22  // Default constructor
23  Polygon() {
24  }
25 
26  // Constructor with field values
27  Polygon(const std::vector<int32_t> & vertices) : vertices(vertices) {
28  }
29 
30  // Copy constructor
31  Polygon(const Polygon& __alt) : WirePortable(__alt) {
32  this->vertices = __alt.vertices;
33  }
34 
35  // Assignment operator
36  const Polygon& operator = (const Polygon& __alt) {
37  this->vertices = __alt.vertices;
38  return *this;
39  }
40 
41  // read and write structure on a connection
42  bool read(yarp::os::idl::WireReader& reader);
43  bool read(yarp::os::ConnectionReader& connection);
44  bool write(yarp::os::idl::WireWriter& writer);
45  bool write(yarp::os::ConnectionWriter& connection);
46 
47 private:
48  bool write_vertices(yarp::os::idl::WireWriter& writer);
49  bool nested_write_vertices(yarp::os::idl::WireWriter& writer);
50  bool read_vertices(yarp::os::idl::WireReader& reader);
51  bool nested_read_vertices(yarp::os::idl::WireReader& reader);
52 
53 public:
54 
55  yarp::os::ConstString toString();
56 
57  // if you want to serialize this class without nesting, use this helper
58  typedef yarp::os::idl::Unwrapped<iCub::data3D::Polygon > unwrapped;
59 
60  class Editor : public yarp::os::Wire, public yarp::os::PortWriter {
61  public:
62 
63  Editor() {
64  group = 0;
65  obj_owned = true;
66  obj = new Polygon;
67  dirty_flags(false);
68  yarp().setOwner(*this);
69  }
70 
71  Editor(Polygon& obj) {
72  group = 0;
73  obj_owned = false;
74  edit(obj,false);
75  yarp().setOwner(*this);
76  }
77 
78  bool edit(Polygon& obj, bool dirty = true) {
79  if (obj_owned) delete this->obj;
80  this->obj = &obj;
81  obj_owned = false;
82  dirty_flags(dirty);
83  return true;
84  }
85 
86  virtual ~Editor() {
87  if (obj_owned) delete obj;
88  }
89 
90  bool isValid() const {
91  return obj!=0/*NULL*/;
92  }
93 
94  Polygon& state() { return *obj; }
95 
96  void begin() { group++; }
97 
98  void end() {
99  group--;
100  if (group==0&&is_dirty) communicate();
101  }
102  void set_vertices(const std::vector<int32_t> & vertices) {
103  will_set_vertices();
104  obj->vertices = vertices;
105  mark_dirty_vertices();
106  communicate();
107  did_set_vertices();
108  }
109  void set_vertices(int index, const int32_t elem) {
110  will_set_vertices();
111  obj->vertices[index] = elem;
112  mark_dirty_vertices();
113  communicate();
114  did_set_vertices();
115  }
116  const std::vector<int32_t> & get_vertices() {
117  return obj->vertices;
118  }
119  virtual bool will_set_vertices() { return true; }
120  virtual bool did_set_vertices() { return true; }
121  void clean() {
122  dirty_flags(false);
123  }
124  bool read(yarp::os::ConnectionReader& connection);
125  bool write(yarp::os::ConnectionWriter& connection);
126  private:
127 
128  Polygon *obj;
129 
130  bool obj_owned;
131  int group;
132 
133  void communicate() {
134  if (group!=0) return;
135  if (yarp().canWrite()) {
136  yarp().write(*this);
137  clean();
138  }
139  }
140  void mark_dirty() {
141  is_dirty = true;
142  }
143  void mark_dirty_vertices() {
144  if (is_dirty_vertices) return;
145  dirty_count++;
146  is_dirty_vertices = true;
147  mark_dirty();
148  }
149  void dirty_flags(bool flag) {
150  is_dirty = flag;
151  is_dirty_vertices = flag;
152  dirty_count = flag ? 1 : 0;
153  }
154  bool is_dirty;
155  int dirty_count;
156  bool is_dirty_vertices;
157  };
158 };
159 
160 #endif
161