14 #include <yarp/sig/Pixel.h>
28 Pixel::Pixel(
const std::int32_t x,
29 const std::int32_t y) :
37 bool Pixel::read(yarp::os::idl::WireReader& reader)
39 if (!read_x(reader)) {
42 if (!read_y(reader)) {
45 return !reader.isError();
49 bool Pixel::read(yarp::os::ConnectionReader& connection)
51 yarp::os::idl::WireReader reader(connection);
52 if (!reader.readListHeader(2)) {
59 bool Pixel::write(
const yarp::os::idl::WireWriter& writer)
const
61 if (!write_x(writer)) {
64 if (!write_y(writer)) {
67 return !writer.isError();
71 bool Pixel::write(yarp::os::ConnectionWriter& connection)
const
73 yarp::os::idl::WireWriter writer(connection);
74 if (!writer.writeListHeader(2)) {
81 std::string Pixel::toString()
const
89 Pixel::Editor::Editor()
95 yarp().setOwner(*
this);
99 Pixel::Editor::Editor(Pixel& obj)
104 yarp().setOwner(*
this);
108 Pixel::Editor::~Editor()
116 bool Pixel::Editor::edit(Pixel& obj,
bool dirty)
128 bool Pixel::Editor::isValid()
const
130 return obj !=
nullptr;
134 Pixel& Pixel::Editor::state()
140 void Pixel::Editor::start_editing()
146 void Pixel::Editor::stop_editing()
149 if (group == 0 && is_dirty) {
154 void Pixel::Editor::set_x(
const std::int32_t x)
164 std::int32_t Pixel::Editor::get_x()
const
170 bool Pixel::Editor::will_set_x()
176 bool Pixel::Editor::did_set_x()
182 void Pixel::Editor::set_y(
const std::int32_t y)
192 std::int32_t Pixel::Editor::get_y()
const
198 bool Pixel::Editor::will_set_y()
204 bool Pixel::Editor::did_set_y()
210 void Pixel::Editor::clean()
216 bool Pixel::Editor::read(yarp::os::ConnectionReader& connection)
221 yarp::os::idl::WireReader reader(connection);
222 reader.expectAccept();
223 if (!reader.readListHeader()) {
226 int len = reader.getLength();
228 yarp::os::idl::WireWriter writer(reader);
229 if (writer.isNull()) {
232 if (!writer.writeListHeader(1)) {
235 writer.writeString(
"send: 'help' or 'patch (param1 val1) (param2 val2)'");
239 if (!reader.readString(tag)) {
243 yarp::os::idl::WireWriter writer(reader);
244 if (writer.isNull()) {
247 if (!writer.writeListHeader(2)) {
250 if (!writer.writeTag(
"many", 1, 0)) {
253 if (reader.getLength() > 0) {
255 if (!reader.readString(field)) {
259 if (!writer.writeListHeader(2)) {
262 if (!writer.writeString(
"std::int32_t x")) {
265 if (!writer.writeString(
"Index of pixel along horizontal axis")) {
270 if (!writer.writeListHeader(2)) {
273 if (!writer.writeString(
"std::int32_t y")) {
276 if (!writer.writeString(
"Index of pixel along vertical axis")) {
281 if (!writer.writeListHeader(3)) {
284 writer.writeString(
"*** Available fields:");
285 writer.writeString(
"x");
286 writer.writeString(
"y");
290 bool have_act =
false;
291 if (tag !=
"patch") {
292 if (((len - 1) % 2) != 0) {
295 len = 1 + ((len - 1) / 2);
299 for (
int i = 1; i < len; ++i) {
300 if (nested && !reader.readListHeader(3)) {
307 }
else if (!reader.readString(act)) {
310 if (!reader.readString(key)) {
315 if (!obj->nested_read_x(reader)) {
319 }
else if (key ==
"y") {
321 if (!obj->nested_read_y(reader)) {
330 yarp::os::idl::WireWriter writer(reader);
331 if (writer.isNull()) {
334 writer.writeListHeader(1);
335 writer.writeVocab(yarp::os::createVocab32(
'o',
'k'));
340 bool Pixel::Editor::write(yarp::os::ConnectionWriter& connection)
const
345 yarp::os::idl::WireWriter writer(connection);
346 if (!writer.writeListHeader(dirty_count + 1)) {
349 if (!writer.writeString(
"patch")) {
353 if (!writer.writeListHeader(3)) {
356 if (!writer.writeString(
"set")) {
359 if (!writer.writeString(
"x")) {
362 if (!obj->nested_write_x(writer)) {
367 if (!writer.writeListHeader(3)) {
370 if (!writer.writeString(
"set")) {
373 if (!writer.writeString(
"y")) {
376 if (!obj->nested_write_y(writer)) {
380 return !writer.isError();
384 void Pixel::Editor::communicate()
389 if (yarp().canWrite()) {
396 void Pixel::Editor::mark_dirty()
402 void Pixel::Editor::mark_dirty_x()
413 void Pixel::Editor::mark_dirty_y()
424 void Pixel::Editor::dirty_flags(
bool flag)
429 dirty_count = flag ? 2 : 0;
433 bool Pixel::read_x(yarp::os::idl::WireReader& reader)
435 if (!reader.readI32(x)) {
443 bool Pixel::write_x(
const yarp::os::idl::WireWriter& writer)
const
445 if (!writer.writeI32(x)) {
452 bool Pixel::nested_read_x(yarp::os::idl::WireReader& reader)
454 if (!reader.readI32(x)) {
462 bool Pixel::nested_write_x(
const yarp::os::idl::WireWriter& writer)
const
464 if (!writer.writeI32(x)) {
471 bool Pixel::read_y(yarp::os::idl::WireReader& reader)
473 if (!reader.readI32(y)) {
481 bool Pixel::write_y(
const yarp::os::idl::WireWriter& writer)
const
483 if (!writer.writeI32(y)) {
490 bool Pixel::nested_read_y(yarp::os::idl::WireReader& reader)
492 if (!reader.readI32(y)) {
500 bool Pixel::nested_write_y(
const yarp::os::idl::WireWriter& writer)
const
502 if (!writer.writeI32(y)) {