grasp
All Data Structures Namespaces Functions Modules
Box3D.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_Box3D
5 #define YARP_THRIFT_GENERATOR_STRUCT_Box3D
6 
7 #include <yarp/os/Wire.h>
8 #include <yarp/os/idl/WireTypes.h>
9 #include <iCub/data3D/PointXYZ.h>
10 #include <yarp/sig/Matrix.h>
11 
12 namespace iCub {
13  namespace data3D {
14  class Box3D;
15  }
16 }
17 
18 
19 class iCub::data3D::Box3D : public yarp::os::idl::WirePortable {
20 public:
21  // Fields
22  std::vector<PointXYZ> corners;
23  yarp::sig::Matrix orientation;
24 
25  // Default constructor
26  Box3D() {
27  }
28 
29  // Constructor with field values
30  Box3D(const std::vector<PointXYZ> & corners,const yarp::sig::Matrix& orientation) : corners(corners), orientation(orientation) {
31  }
32 
33  // Copy constructor
34  Box3D(const Box3D& __alt) : WirePortable(__alt) {
35  this->corners = __alt.corners;
36  this->orientation = __alt.orientation;
37  }
38 
39  // Assignment operator
40  const Box3D& operator = (const Box3D& __alt) {
41  this->corners = __alt.corners;
42  this->orientation = __alt.orientation;
43  return *this;
44  }
45 
46  // read and write structure on a connection
47  bool read(yarp::os::idl::WireReader& reader);
48  bool read(yarp::os::ConnectionReader& connection);
49  bool write(yarp::os::idl::WireWriter& writer);
50  bool write(yarp::os::ConnectionWriter& connection);
51 
52 private:
53  bool write_corners(yarp::os::idl::WireWriter& writer);
54  bool nested_write_corners(yarp::os::idl::WireWriter& writer);
55  bool write_orientation(yarp::os::idl::WireWriter& writer);
56  bool nested_write_orientation(yarp::os::idl::WireWriter& writer);
57  bool read_corners(yarp::os::idl::WireReader& reader);
58  bool nested_read_corners(yarp::os::idl::WireReader& reader);
59  bool read_orientation(yarp::os::idl::WireReader& reader);
60  bool nested_read_orientation(yarp::os::idl::WireReader& reader);
61 
62 public:
63 
64  yarp::os::ConstString toString();
65 
66  // if you want to serialize this class without nesting, use this helper
67  typedef yarp::os::idl::Unwrapped<iCub::data3D::Box3D > unwrapped;
68 
69  class Editor : public yarp::os::Wire, public yarp::os::PortWriter {
70  public:
71 
72  Editor() {
73  group = 0;
74  obj_owned = true;
75  obj = new Box3D;
76  dirty_flags(false);
77  yarp().setOwner(*this);
78  }
79 
80  Editor(Box3D& obj) {
81  group = 0;
82  obj_owned = false;
83  edit(obj,false);
84  yarp().setOwner(*this);
85  }
86 
87  bool edit(Box3D& obj, bool dirty = true) {
88  if (obj_owned) delete this->obj;
89  this->obj = &obj;
90  obj_owned = false;
91  dirty_flags(dirty);
92  return true;
93  }
94 
95  virtual ~Editor() {
96  if (obj_owned) delete obj;
97  }
98 
99  bool isValid() const {
100  return obj!=0/*NULL*/;
101  }
102 
103  Box3D& state() { return *obj; }
104 
105  void begin() { group++; }
106 
107  void end() {
108  group--;
109  if (group==0&&is_dirty) communicate();
110  }
111  void set_corners(const std::vector<PointXYZ> & corners) {
112  will_set_corners();
113  obj->corners = corners;
114  mark_dirty_corners();
115  communicate();
116  did_set_corners();
117  }
118  void set_corners(int index, const PointXYZ& elem) {
119  will_set_corners();
120  obj->corners[index] = elem;
121  mark_dirty_corners();
122  communicate();
123  did_set_corners();
124  }
125  void set_orientation(const yarp::sig::Matrix& orientation) {
126  will_set_orientation();
127  obj->orientation = orientation;
128  mark_dirty_orientation();
129  communicate();
130  did_set_orientation();
131  }
132  const std::vector<PointXYZ> & get_corners() {
133  return obj->corners;
134  }
135  const yarp::sig::Matrix& get_orientation() {
136  return obj->orientation;
137  }
138  virtual bool will_set_corners() { return true; }
139  virtual bool will_set_orientation() { return true; }
140  virtual bool did_set_corners() { return true; }
141  virtual bool did_set_orientation() { return true; }
142  void clean() {
143  dirty_flags(false);
144  }
145  bool read(yarp::os::ConnectionReader& connection);
146  bool write(yarp::os::ConnectionWriter& connection);
147  private:
148 
149  Box3D *obj;
150 
151  bool obj_owned;
152  int group;
153 
154  void communicate() {
155  if (group!=0) return;
156  if (yarp().canWrite()) {
157  yarp().write(*this);
158  clean();
159  }
160  }
161  void mark_dirty() {
162  is_dirty = true;
163  }
164  void mark_dirty_corners() {
165  if (is_dirty_corners) return;
166  dirty_count++;
167  is_dirty_corners = true;
168  mark_dirty();
169  }
170  void mark_dirty_orientation() {
171  if (is_dirty_orientation) return;
172  dirty_count++;
173  is_dirty_orientation = true;
174  mark_dirty();
175  }
176  void dirty_flags(bool flag) {
177  is_dirty = flag;
178  is_dirty_corners = flag;
179  is_dirty_orientation = flag;
180  dirty_count = flag ? 2 : 0;
181  }
182  bool is_dirty;
183  int dirty_count;
184  bool is_dirty_corners;
185  bool is_dirty_orientation;
186  };
187 };
188 
189 #endif
190