YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Map2DStorage.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include <sstream>
7#include <limits>
8#include "Map2DStorage.h"
9#include <yarp/dev/IMap2D.h>
12#include <yarp/math/Math.h>
13#include <yarp/os/Log.h>
15#include <yarp/os/LogStream.h>
16#include <mutex>
17#include <cstdlib>
18#include <fstream>
19#include <filesystem>
20
21using namespace yarp::sig;
22using namespace yarp::dev;
23using namespace yarp::dev::Nav2D;
24using namespace yarp::os;
25
26namespace {
27YARP_LOG_COMPONENT(MAP2DSTORAGE, "yarp.device.map2DStorage")
28}
29
30static std::string extractPathFromFile(std::string full_filename)
31{
32 std::filesystem::path p(full_filename);
33 std::string path = p.parent_path().string();
34 if (path.empty()) return path;
35
36 path.push_back (std::filesystem::path::preferred_separator);
37 return path;
38}
39
47
49
51{
52 //check if the storage is not empty
53 if (m_maps_storage.size() == 0)
54 {
55 yCError(MAP2DSTORAGE) << "Map storage is empty";
56 return ReturnValue::return_code::return_value_error_method_failed;
57 }
58
60
61 //open the map collection file
62 std::ofstream file;
63 file.open(mapsfile.c_str());
64 if (!file.is_open())
65 {
66 yCError(MAP2DSTORAGE) << "Sorry unable to open" << mapsfile;
67 return ReturnValue::return_code::return_value_error_method_failed;
68 }
69
70 bool ret = true;
71 //for each map...
72 for (auto& it : m_maps_storage)
73 {
74 //add an entry to the map collection file
75 std::string map_filename = it.first + ".map";
76 file << "mapfile: ";
77 file << map_filename;
78 file << '\n';
79
80 //save each individual map to a file
81 ret &= it.second.saveToFile(mapsCollectionDir+map_filename);
82 }
83 file.close();
84
85 if (!ret)
86 {
87 return ReturnValue::return_code::return_value_error_method_failed;
88 }
89
90 return ReturnValue_ok;
91}
92
94{
95 bool ret = true;
96 std::ifstream file;
97 file.open(mapsfile.c_str());
98 if (!file.is_open())
99 {
100 yCError(MAP2DSTORAGE) << "loadMaps() Unable to open:" << mapsfile;
101 return ReturnValue::return_code::return_value_error_method_failed;
102 }
103 while (!file.eof())
104 {
105 std::string dummy;
106 std::string buffer;
107 std::getline(file, buffer);
108 std::istringstream iss(buffer);
109 iss >> dummy;
110 if (dummy == "") {
111 break;
112 }
113 if (dummy == "mapfile:")
114 {
115 std::string mapfilename;
116 iss >> mapfilename;
117 std::string option;
118 iss >> option;
119 std::string mapfilenameWithPath = m_rf_mapCollection.findFile(mapfilename);
120
121 //open the individual map file
122 MapGrid2D map;
123 bool r = map.loadFromFile(mapfilenameWithPath);
124 if (r)
125 {
126 std::string map_name= map.getMapName();
127 auto p = m_maps_storage.find(map_name);
128 if (p == m_maps_storage.end())
129 {
130 if (option == "crop") {
131 map.crop(-1, -1, -1, -1);
132 }
133 m_maps_storage[map_name] = map;
134 }
135 else
136 {
137 yCError(MAP2DSTORAGE) << "A map with the same name '" << map_name << "'was found, skipping...";
138 ret = false;
139 }
140 }
141 else
142 {
143 yCError(MAP2DSTORAGE) << "Problems opening map file" << mapfilenameWithPath;
144 ret = false;
145 }
146 }
147 else
148 {
149 yCError(MAP2DSTORAGE) << "Invalid syntax, missing mapfile tag";
150 ret = false;
151 }
152 }
153 file.close();
154
155 if (!ret)
156 {
157 return ReturnValue::return_code::return_value_error_method_failed;
158 }
159
160 return ReturnValue_ok;
161}
162
164{
165 if (!parseParams(config)) { return false; }
166
167 if (m_mapCollectionContext.empty())
168 {
169 yCInfo(MAP2DSTORAGE) << "Parameter mapCollectionContext not given. No maps/locations will be loaded.";
170 }
171 else
172 {
173 m_rf_mapCollection.setDefaultContext(m_mapCollectionContext.c_str());
174
175 std::string m_collection_startup_file_with_path = m_rf_mapCollection.findFile(m_mapCollectionFile);
176 std::string m_locations_startup_file_with_path = m_rf_mapCollection.findFile(m_mapLocationsFile);
177
178 if (m_locations_startup_file_with_path=="")
179 {
180 yCInfo(MAP2DSTORAGE) << "No locations loaded";
181 }
182 else
183 {
184 bool ret = loadLocationsAndExtras(m_locations_startup_file_with_path);
185 if (ret) { yCInfo(MAP2DSTORAGE) << "Location file" << m_locations_startup_file_with_path << "successfully loaded."; }
186 else { yCError(MAP2DSTORAGE) << "Problems opening file" << m_locations_startup_file_with_path; }
187 }
188
189 if (m_collection_startup_file_with_path=="")
190 {
191 yCError(MAP2DSTORAGE) << "Unable to find file" << m_mapCollectionFile << "within the specified context:" << m_mapCollectionContext;
192 return false;
193 }
194 if (loadMapsCollection(m_collection_startup_file_with_path))
195 {
196 yCInfo(MAP2DSTORAGE) << "Map collection file:" << m_collection_startup_file_with_path << "successfully loaded.";
197
198 //print maps
199 if (m_maps_storage.size() > 0)
200 {
201 yCInfo(MAP2DSTORAGE) << "Available maps are:";
202 for (auto& it : m_maps_storage)
203 {
204 yCInfo(MAP2DSTORAGE) << it.first;
205 }
206 }
207 else
208 {
209 yCInfo(MAP2DSTORAGE) << "No maps available";
210 }
211
212 //print locations
213 if (m_locations_storage.size() > 0)
214 {
215 yCInfo(MAP2DSTORAGE) << "Available Locations are:";
216 for (auto& it : m_locations_storage)
217 {
218 yCInfo(MAP2DSTORAGE) << it.first;
219 }
220 }
221 else
222 {
223 yCInfo(MAP2DSTORAGE) << "No locations available";
224 }
225
226 //print objects
227 if (m_objects_storage.size() > 0)
228 {
229 yCInfo(MAP2DSTORAGE) << "Available object locations are:";
230 for (auto& it : m_objects_storage)
231 {
232 yCInfo(MAP2DSTORAGE) << it.first;
233 }
234 }
235 else
236 {
237 yCInfo(MAP2DSTORAGE) << "No object locations available";
238 }
239
240 //print areas
241 if (m_areas_storage.size() > 0)
242 {
243 yCInfo(MAP2DSTORAGE) << "Available areas are:";
244 for (auto& it : m_areas_storage)
245 {
246 yCInfo(MAP2DSTORAGE) << it.first;
247 }
248 }
249 else
250 {
251 yCInfo(MAP2DSTORAGE) << "No areas available";
252 }
253
254 //print paths
255 if (m_paths_storage.size() > 0)
256 {
257 yCInfo(MAP2DSTORAGE) << "Available paths are:";
258 for (auto& it : m_paths_storage)
259 {
260 yCInfo(MAP2DSTORAGE) << it.first;
261 }
262 }
263 else
264 {
265 yCInfo(MAP2DSTORAGE) << "No paths available";
266 }
267 }
268 else
269 {
270 yCError(MAP2DSTORAGE) << "Unable to load map collection file:" << m_collection_startup_file_with_path;
271 return false;
272 }
273 }
274
275 //open rpc port
276 if (!m_rpcPort.open(m_name))
277 {
278 yCError(MAP2DSTORAGE, "Failed to open port %s", m_name.c_str());
279 return false;
280 }
281 m_rpcPort.setReader(*this);
282
283 return true;
284}
285
287{
288 yCTrace(MAP2DSTORAGE, "Close");
289 return true;
290}
291
292bool Map2DStorage::priv_load_locations_and_areas_v1(std::ifstream& file)
293{
294 std::string buffer;
295 std::getline(file, buffer);
296 if (buffer != "Locations:")
297 {
298 yCError(MAP2DSTORAGE) << "Unable to parse Locations section!";
299 return false;
300 }
301
302 while (1)
303 {
304 std::getline(file, buffer);
305 if (buffer == "Areas:") {
306 break;
307 }
308 if (file.eof())
309 {
310 yCError(MAP2DSTORAGE) << "Unexpected End Of File";
311 return false;
312 }
313 Bottle b;
315 size_t bot_size = b.size();
316 if (bot_size != 5)
317 {
318 yCError(MAP2DSTORAGE) << "Unable to parse contents of Areas section!";
319 return false;
320 }
322 std::string name = b.get(0).asString();
323 location.map_id = b.get(1).asString();
324 location.x = b.get(2).asFloat64();
325 location.y = b.get(3).asFloat64();
326 location.theta = b.get(4).asFloat64();
327 m_locations_storage[name] = location;
328 }
329
330 if (buffer != "Areas:")
331 {
332 yCError(MAP2DSTORAGE) << "Unable to parse Areas section!";
333 return false;
334 }
335
336 while (1)
337 {
338 Map2DArea area;
339 std::getline(file, buffer);
340 if (file.eof()) {
341 break;
342 }
343
344 Bottle b;
346 size_t bot_size = b.size();
347 std::string name = b.get(0).asString();
348 area.map_id = b.get(1).asString();
349 size_t area_size = b.get(2).asInt32();
350 if (area_size <= 0 || bot_size != area_size * 2 + 3)
351 {
352 yCError(MAP2DSTORAGE) << "Unable to parse contents of Areas section!";
353 return false;
354 }
355 for (size_t ai = 3; ai < bot_size; ai += 2)
356 {
357 double xpos = b.get(ai).asFloat64();
358 double ypos = b.get(ai + 1).asFloat64();
359 area.points.push_back(yarp::math::Vec2D<double>(xpos, ypos));
360 }
361 m_areas_storage[name] = area;
362 }
363 return true;
364}
365
366bool Map2DStorage::priv_load_locations_and_areas_v2(std::ifstream& file)
367{
368 std::string buffer;
369 std::getline(file, buffer);
370 if (buffer != "Locations:")
371 {
372 yCError(MAP2DSTORAGE) << "Unable to parse Locations section!";
373 return false;
374 }
375
376 while (1)
377 {
378 std::getline(file, buffer);
379 if (buffer == "Areas:") {
380 break; // Go the next section
381 }
382 if (file.eof())
383 {
384 yCError(MAP2DSTORAGE) << "Unexpected End Of File";
385 return false;
386 }
387 Bottle b;
389 size_t bot_size = b.size();
390 if (bot_size != 5)
391 {
392 yCError(MAP2DSTORAGE) << "Unable to parse contents of Areas section!";
393 return false;
394 }
396 std::string name = b.get(0).asString();
397 location.map_id = b.get(1).asString();
398 location.x = b.get(2).asFloat64();
399 location.y = b.get(3).asFloat64();
400 location.theta = b.get(4).asFloat64();
401 m_locations_storage[name] = location;
402 }
403
404 if (buffer != "Areas:")
405 {
406 yCError(MAP2DSTORAGE) << "Unable to parse Areas section!";
407 return false;
408 }
409
410 while (1)
411 {
412 Map2DArea area;
413 std::getline(file, buffer);
414 if (buffer == "Paths:") {
415 break; // Go the next section
416 }
417 if (file.eof()) {
418 break;
419 }
420
421 Bottle b;
423 size_t bot_size = b.size();
424 std::string name = b.get(0).asString();
425 area.map_id = b.get(1).asString();
426 size_t area_size = b.get(2).asInt32();
427 if (area_size <= 0 || bot_size != area_size * 2 + 3)
428 {
429 yCError(MAP2DSTORAGE) << "Unable to parse contents of Areas section!";
430 return false;
431 }
432 for (size_t ai = 3; ai < bot_size; ai += 2)
433 {
434 double xpos = b.get(ai).asFloat64();
435 double ypos = b.get(ai + 1).asFloat64();
436 area.points.push_back(yarp::math::Vec2D<double>(xpos, ypos));
437 }
438 m_areas_storage[name] = area;
439 }
440
441 if (buffer != "Paths:")
442 {
443 yCError(MAP2DSTORAGE) << "Unable to parse Paths section!";
444 return false;
445 }
446
447 while (1)
448 {
449 Map2DPath path;
450 std::getline(file, buffer);
451 if (file.eof()) {
452 break;
453 }
454
455 Bottle b;
457 size_t bot_size = b.size();
459 std::string name = b.get(0).asString();
460 size_t i = 1;
461 do
462 {
463 if (b.get(i).isList())
464 {
465 Bottle* ll = b.get(i).asList();
466 if (ll && ll->size() == 4)
467 {
468 Map2DLocation loc;
469 loc.map_id = ll->get(0).asString();
470 loc.x = ll->get(1).asFloat64();
471 loc.y = ll->get(2).asFloat64();
472 loc.theta = ll->get(3).asFloat64();
473 path.push_back(loc);
474 }
475 else
476 {
477 yCError(MAP2DSTORAGE) << "Unable to parse contents of Paths section!";
478 return false;
479 }
480 }
481 else
482 {
483 break;
484 }
485 i++;
486 } while (1);
487 m_paths_storage[name] = path;
488 }
489
490 return true;
491}
492
493bool Map2DStorage::priv_load_locations_and_areas_v3(std::ifstream& file)
494{
495 std::string buffer;
496 std::getline(file, buffer);
497
498 //LOCATIONS
499 {
500 if (buffer != "Locations:")
501 {
502 yCError(MAP2DSTORAGE) << "Unable to parse Locations section!";
503 return false;
504 }
505
506 while (1)
507 {
508 std::getline(file, buffer);
509 if (buffer == "Areas:") {
510 break; // Go the next section
511 }
512 if (file.eof())
513 {
514 yCError(MAP2DSTORAGE) << "Unexpected End Of File";
515 return false;
516 }
517 Bottle b;
519 size_t bot_size = b.size();
520 if (bot_size != 6)
521 {
522 yCError(MAP2DSTORAGE) << "Unable to parse contents of Locations section!";
523 return false;
524 }
526 std::string name = b.get(0).asString();
527 location.map_id = b.get(1).asString();
528 location.x = b.get(2).asFloat64();
529 location.y = b.get(3).asFloat64();
530 location.theta = b.get(4).asFloat64();
531 location.description = b.get(5).asString();
532 m_locations_storage[name] = location;
533 }
534 }
535
536 //AREAS
537 {
538 if (buffer != "Areas:")
539 {
540 yCError(MAP2DSTORAGE) << "Unable to parse Areas section!";
541 return false; // Go the next section
542 }
543
544 while (1)
545 {
546 Map2DArea area;
547 std::getline(file, buffer);
548 if (buffer == "Paths:") {
549 break; // Go the next section
550 }
551 if (file.eof()) {
552 break;
553 }
554
555 Bottle b;
557 size_t bot_size = b.size();
558 std::string name = b.get(0).asString();
559 area.map_id = b.get(1).asString();
560 size_t area_size = b.get(2).asInt32();
561 if (area_size <= 0 || bot_size != 3 + area_size * 2 + 1)
562 {
563 yCError(MAP2DSTORAGE) << "Unable to parse contents of Areas section!";
564 return false;
565 }
566 for (size_t ai = 3; ai < bot_size-1; ai += 2)
567 {
568 double xpos = b.get(ai).asFloat64();
569 double ypos = b.get(ai + 1).asFloat64();
570 area.points.push_back(yarp::math::Vec2D<double>(xpos, ypos));
571 }
572 area.description = b.get(bot_size-1).asString();
573 m_areas_storage[name] = area;
574 }
575 }
576
577 //PATHS
578 {
579 if (buffer != "Paths:")
580 {
581 yCError(MAP2DSTORAGE) << "Unable to parse Paths section!";
582 return false;
583 }
584
585 while (1)
586 {
587 Map2DPath path;
588 std::getline(file, buffer);
589 if (file.eof()) {
590 break;
591 }
592
593 Bottle b;
595 size_t bot_size = b.size();
597 std::string name = b.get(0).asString();
598 size_t i = 1;
599 do
600 {
601 if (b.get(i).isList())
602 {
603 Bottle* ll = b.get(i).asList();
604 if (ll && ll->size() == 4)
605 {
606 Map2DLocation loc;
607 loc.map_id = ll->get(0).asString();
608 loc.x = ll->get(1).asFloat64();
609 loc.y = ll->get(2).asFloat64();
610 loc.theta = ll->get(3).asFloat64();
611 path.push_back(loc);
612 }
613 else
614 {
615 yCError(MAP2DSTORAGE) << "Unable to parse contents of Paths section!";
616 return false;
617 }
618 }
619 else
620 {
621 break;
622 }
623 i++;
624 } while (1);
625 path.description = b.get(bot_size - 1).asString();
626 m_paths_storage[name] = path;
627 }
628 }
629
630 return true;
631}
632
633bool Map2DStorage::priv_load_locations_and_areas_v4(std::ifstream& file)
634{
635 std::string buffer;
636 std::getline(file, buffer);
637
638 //LOCATIONS
639 {
640 if (buffer != "Locations:")
641 {
642 yCError(MAP2DSTORAGE) << "Unable to parse Locations section!";
643 return false;
644 }
645
646 while (1)
647 {
648 std::getline(file, buffer);
649 if (buffer == "Objects:") {
650 break; // Go the next section
651 }
652 if (file.eof())
653 {
654 yCError(MAP2DSTORAGE) << "Unexpected End Of File";
655 return false;
656 }
657 Bottle b;
659 size_t bot_size = b.size();
660 if (bot_size != 6)
661 {
662 yCError(MAP2DSTORAGE) << "Unable to parse contents of Locations section!";
663 return false;
664 }
666 std::string name = b.get(0).asString();
667 maplocation.map_id = b.get(1).asString();
668 maplocation.x = b.get(2).asFloat64();
669 maplocation.y = b.get(3).asFloat64();
670 maplocation.theta = b.get(4).asFloat64();
671 maplocation.description = b.get(5).asString();
672
673 // check if location already exists
674 auto it = m_locations_storage.find(name);
675 if (it != m_locations_storage.end())
676 {
677 yCError(MAP2DSTORAGE) << "The file contains multiple locations with the same name: " << name;
678 return false;
679 }
680 else
681 {
682 m_locations_storage[name] = maplocation;
683 }
684 }
685 }
686
687 //OBJECTS
688 {
689 if (buffer != "Objects:")
690 {
691 yCError(MAP2DSTORAGE) << "Unable to parse Objects section!";
692 return false; // Go the next section
693 }
694
695 while (1)
696 {
697 std::getline(file, buffer);
698 if (buffer == "Areas:") {
699 break;
700 }
701 if (file.eof())
702 {
703 yCError(MAP2DSTORAGE) << "Unexpected End Of File";
704 return false;
705 }
706 Bottle b;
708 size_t bot_size = b.size();
709 if (bot_size != 9)
710 {
711 yCError(MAP2DSTORAGE) << "Unable to parse contents of Objects section!";
712 return false;
713 }
715 std::string name = b.get(0).asString();
716 objlocation.map_id = b.get(1).asString();
717 objlocation.x = b.get(2).asFloat64();
718 objlocation.y = b.get(3).asFloat64();
719 objlocation.z = b.get(4).asFloat64();
720 objlocation.roll = b.get(5).asFloat64();
721 objlocation.pitch = b.get(6).asFloat64();
722 objlocation.yaw = b.get(7).asFloat64();
723 objlocation.description = b.get(8).asString();
724
725 // check if object already exists
726 auto it = m_objects_storage.find(name);
727 if (it != m_objects_storage.end())
728 {
729 yCError(MAP2DSTORAGE) << "The file contains multiple objects with the same name: " << name;
730 return false;
731 }
732 else
733 {
734 m_objects_storage[name] = objlocation;
735 }
736 }
737 }
738
739 //AREAS
740 {
741 if (buffer != "Areas:")
742 {
743 yCError(MAP2DSTORAGE) << "Unable to parse Areas section!";
744 return false;
745 }
746
747 while (1)
748 {
749 Map2DArea area;
750 std::getline(file, buffer);
751 if (buffer == "Paths:") {
752 break; // Go the next section
753 }
754 if (file.eof()) {
755 break;
756 }
757
758 Bottle b;
760 size_t bot_size = b.size();
761 std::string name = b.get(0).asString();
762 area.map_id = b.get(1).asString();
763 size_t area_size = b.get(2).asInt32();
764 if (area_size <= 0 || bot_size != 3 + area_size * 2 + 1)
765 {
766 yCError(MAP2DSTORAGE) << "Unable to parse contents of Areas section!";
767 return false;
768 }
769 for (size_t ai = 3; ai < bot_size-1; ai += 2)
770 {
771 double xpos = b.get(ai).asFloat64();
772 double ypos = b.get(ai + 1).asFloat64();
773 area.points.push_back(yarp::math::Vec2D<double>(xpos, ypos));
774 }
775 area.description = b.get(bot_size-1).asString();
776
777 // check if area already exists
778 auto it = m_areas_storage.find(name);
779 if (it != m_areas_storage.end())
780 {
781 yCError(MAP2DSTORAGE) << "The file contains multiple areas with the same name: " << name;
782 return false;
783 }
784 else
785 {
786 m_areas_storage[name] = area;
787 }
788 }
789 }
790
791 //PATHS
792 {
793 if (buffer != "Paths:")
794 {
795 yCError(MAP2DSTORAGE) << "Unable to parse Paths section!";
796 return false;
797 }
798
799 while (1)
800 {
801 Map2DPath path;
802 std::getline(file, buffer);
803 if (file.eof()) {
804 break;
805 }
806
807 Bottle b;
809 size_t bot_size = b.size();
811 std::string name = b.get(0).asString();
812 size_t i = 1;
813 do
814 {
815 if (b.get(i).isList())
816 {
817 Bottle* ll = b.get(i).asList();
818 if (ll && ll->size() == 4)
819 {
820 Map2DLocation loc;
821 loc.map_id = ll->get(0).asString();
822 loc.x = ll->get(1).asFloat64();
823 loc.y = ll->get(2).asFloat64();
824 loc.theta = ll->get(3).asFloat64();
825 path.push_back(loc);
826 }
827 else
828 {
829 yCError(MAP2DSTORAGE) << "Unable to parse contents of Paths section!";
830 return false;
831 }
832 }
833 else
834 {
835 break;
836 }
837 i++;
838 } while (1);
839 path.description = b.get(bot_size - 1).asString();
840
841 // check if path already exists
842 auto it = m_paths_storage.find(name);
843 if (it != m_paths_storage.end())
844 {
845 yCError(MAP2DSTORAGE) << "The file contains multiple paths with the same name: " << name;
846 return false;
847 }
848 else
849 {
850 m_paths_storage[name] = path;
851 }
852 }
853 }
854
855 return true;
856}
857
859{
860 std::ifstream file;
861 file.open (locations_file.c_str());
862
863 if(!file.is_open())
864 {
865 yCError(MAP2DSTORAGE) << "Unable to open" << locations_file << "locations file.";
866 return ReturnValue::return_code::return_value_error_method_failed;
867 }
868
869 std::string buffer;
870
871 std::getline(file, buffer);
872 if (buffer != "Version:")
873 {
874 yCError(MAP2DSTORAGE) << "Unable to parse Version section!";
875 file.close();
876 return ReturnValue::return_code::return_value_error_method_failed;
877 }
878 std::getline(file, buffer);
879 int version = atoi(buffer.c_str());
880
881 if (version == 1)
882 {
883 if (!priv_load_locations_and_areas_v1(file))
884 {
885 yCError(MAP2DSTORAGE) << "Call to load_locations_and_areas_v1 failed";
886 file.close();
887 return ReturnValue::return_code::return_value_error_method_failed;
888 }
889 }
890 else if (version == 2)
891 {
892 if (!priv_load_locations_and_areas_v2(file))
893 {
894 yCError(MAP2DSTORAGE) << "Call to load_locations_and_areas_v2 failed";
895 file.close();
896 return ReturnValue::return_code::return_value_error_method_failed;
897 }
898 }
899 else if (version == 3)
900 {
901 if (!priv_load_locations_and_areas_v3(file))
902 {
903 yCError(MAP2DSTORAGE) << "Call to load_locations_and_areas_v3 failed";
904 file.close();
905 return ReturnValue::return_code::return_value_error_method_failed;
906 }
907 }
908 else if (version == 4)
909 {
910 if (!priv_load_locations_and_areas_v4(file))
911 {
912 yCError(MAP2DSTORAGE) << "Call to load_locations_and_areas_v4 failed";
913 file.close();
914 return ReturnValue::return_code::return_value_error_method_failed;
915 }
916 }
917 else
918 {
919 yCError(MAP2DSTORAGE) << "Only versions 1-4 supported!";
920 file.close();
921 return ReturnValue::return_code::return_value_error_method_failed;
922 }
923
924 //on success
925 file.close();
926 yCDebug(MAP2DSTORAGE) << "Locations file" << locations_file << "loaded, "
927 << m_locations_storage.size() << "locations and "
928 << m_areas_storage.size() << " areas and "
929 << m_paths_storage.size() << " paths available";
930 return ReturnValue_ok;
931}
932
934{
935 std::ofstream file;
936 file.open (locations_file.c_str());
937
938 if(!file.is_open())
939 {
940 yCError(MAP2DSTORAGE) << "Unable to open" << locations_file << "locations file.";
941 return ReturnValue::return_code::return_value_error_method_failed;
942 }
943
944 std::string s = " ";
945 std::string q = "\"";
946
947 file << "Version:\n";
948 file << "4\n";
949
950 {
952 file << "Locations:\n";
953 std::map<std::string, Map2DLocation>::iterator it;
954 for (it = m_locations_storage.begin(); it != m_locations_storage.end(); ++it)
955 {
956 tmp_loc = it->second;
957 file << it->first << s << tmp_loc.map_id << s << tmp_loc.x << s << tmp_loc.y << s << tmp_loc.theta << s;
958 file << q << tmp_loc.description << q << "\n";
959 }
960 }
961
962 {
964 file << "Objects:\n";
965 std::map<std::string, Map2DObject>::iterator it;
966 for (it = m_objects_storage.begin(); it != m_objects_storage.end(); ++it)
967 {
968 tmp_loc = it->second;
969 file << it->first << s << tmp_loc.map_id << s << tmp_loc.x << s << tmp_loc.y << s << tmp_loc.z << s;
970 file << tmp_loc.roll << s << tmp_loc.pitch << s << tmp_loc.yaw << s;
971 file << q << tmp_loc.description << q << "\n";
972 }
973 }
974
975 {
977 file << "Areas:\n";
978 std::map<std::string, Map2DArea>::iterator it2;
979 for (it2 = m_areas_storage.begin(); it2 != m_areas_storage.end(); ++it2)
980 {
981 tmp_area = it2->second;
982 file << it2->first << s << tmp_area.map_id << s << tmp_area.points.size() << s;
983 for (size_t i = 0; i < tmp_area.points.size(); i++)
984 {
985 file << tmp_area.points[i].x << s;
986 file << tmp_area.points[i].y << s;
987 }
988 file << q << tmp_area.description << q;
989 file << "\n";
990 }
991 }
992
993 {
994
996 file << "Paths:\n";
997 std::map<std::string, Map2DPath>::iterator it3;
998 for (it3 = m_paths_storage.begin(); it3 != m_paths_storage.end(); ++it3)
999 {
1000 tmp_path = it3->second;
1001 file << it3->first << " "; // the name of the path
1002 for (size_t i=0; i<it3->second.size(); i++)
1003 {
1005 file << "( " << tmp_loc.map_id << s << tmp_loc.x << s << tmp_loc.y << s << tmp_loc.theta << ") ";
1006 }
1007 file << q << tmp_path.description << q;
1008 file << "\n";
1009 }
1010 }
1011
1012 file.close();
1013 yCDebug(MAP2DSTORAGE) << "Locations file" << locations_file << "saved.";
1014 return ReturnValue_ok;
1015}
1016
1017
1019{
1020 m_maps_storage.clear();
1021 return ReturnValue_ok;
1022}
1023
1025{
1026 std::string map_name = map.getMapName();
1027 auto it = m_maps_storage.find(map_name);
1028 if (it == m_maps_storage.end())
1029 {
1030 //add a new map
1031 m_maps_storage[map_name] = map;
1032 }
1033 else
1034 {
1035 //the map already exists
1036 m_maps_storage[map_name] = map;
1037 }
1038 return ReturnValue_ok;
1039}
1040
1042{
1043 auto it = m_maps_storage.find(map_name);
1044 if (it != m_maps_storage.end())
1045 {
1046 map=it->second;
1047 return ReturnValue_ok;
1048 }
1049 return ReturnValue::return_code::return_value_error_method_failed;
1050}
1051
1052ReturnValue Map2DStorage::get_map_names(std::vector<std::string>& map_names)
1053{
1054 map_names.clear();
1055 for (auto& it : m_maps_storage)
1056 {
1057 map_names.push_back(it.first);
1058 }
1059 return ReturnValue_ok;
1060}
1061
1063{
1064 size_t rem = m_maps_storage.erase(map_name);
1065 if (rem == 0)
1066 {
1067 return ReturnValue::return_code::return_value_error_method_failed;
1068 }
1069 else
1070 {
1071 return ReturnValue_ok;
1072 }
1073}
1074
1076{
1077 m_locations_storage.insert(std::pair<std::string, Map2DLocation>(location_name, loc));
1078 return ReturnValue_ok;
1079}
1080
1082{
1083 m_areas_storage.insert(std::pair<std::string, Map2DArea>(area_name, area));
1084 return ReturnValue_ok;
1085}
1086
1088{
1089 m_paths_storage.insert(std::pair<std::string, Map2DPath>(path_name, path));
1090 return ReturnValue_ok;
1091}
1092
1094{
1095 auto it = m_locations_storage.find(location_name);
1096 if (it != m_locations_storage.end())
1097 {
1098 loc = it->second;
1099 return ReturnValue_ok;
1100 }
1101 return ReturnValue::return_code::return_value_error_method_failed;
1102}
1103
1105{
1106 auto it = m_areas_storage.find(area_name);
1107 if (it != m_areas_storage.end())
1108 {
1109 area = it->second;
1110 return ReturnValue_ok;
1111 }
1112 return ReturnValue::return_code::return_value_error_method_failed;
1113}
1114
1116{
1117 auto it = m_paths_storage.find(path_name);
1118 if (it != m_paths_storage.end())
1119 {
1120 path = it->second;
1121 return ReturnValue_ok;
1122 }
1123 return ReturnValue::return_code::return_value_error_method_failed;
1124}
1125
1126ReturnValue Map2DStorage::getLocationsList(std::vector<std::string>& locations)
1127{
1128 locations.clear();
1129 for (auto& it : m_locations_storage)
1130 {
1131 locations.push_back(it.first);
1132 }
1133 return ReturnValue_ok;
1134}
1135
1136ReturnValue Map2DStorage::getAreasList(std::vector<std::string>& areas)
1137{
1138 areas.clear();
1139 for (auto& it : m_areas_storage)
1140 {
1141 areas.push_back(it.first);
1142 }
1143 return ReturnValue_ok;
1144}
1145
1146ReturnValue Map2DStorage::getPathsList(std::vector<std::string>& paths)
1147{
1148 paths.clear();
1149 for (auto& it : m_paths_storage)
1150 {
1151 paths.push_back(it.first);
1152 }
1153 return ReturnValue_ok;
1154}
1155
1156ReturnValue Map2DStorage::getAllLocations (std::vector<yarp::dev::Nav2D::Map2DLocation>& locations)
1157{
1158 locations.clear();
1159 for (auto& it : m_locations_storage)
1160 {
1161 locations.push_back(it.second);
1162 }
1163 return ReturnValue_ok;
1164}
1165
1166ReturnValue Map2DStorage::getAllAreas (std::vector<yarp::dev::Nav2D::Map2DArea>& areas)
1167{
1168 for (auto& it : m_areas_storage)
1169 {
1170 areas.push_back(it.second);
1171 }
1172 return ReturnValue_ok;
1173}
1174
1175ReturnValue Map2DStorage::getAllPaths (std::vector<yarp::dev::Nav2D::Map2DPath>& paths)
1176{
1177 paths.clear();
1178 for (auto& it : m_paths_storage)
1179 {
1180 paths.push_back(it.second);
1181 }
1182 return ReturnValue_ok;
1183}
1184
1185ReturnValue Map2DStorage::renameLocation(std::string original_name, std::string new_name)
1186{
1187 std::map<std::string, Map2DLocation>::iterator orig_it;
1188 orig_it = m_locations_storage.find(original_name);
1189 std::map<std::string, Map2DLocation>::iterator new_it;
1190 new_it = m_locations_storage.find(new_name);
1191
1192 if (orig_it != m_locations_storage.end() &&
1193 new_it == m_locations_storage.end())
1194 {
1195 auto loc = orig_it->second;
1196 m_locations_storage.erase(orig_it);
1197 m_locations_storage.insert(std::pair<std::string, Map2DLocation>(new_name, loc));
1198 return ReturnValue_ok;
1199 }
1200 return ReturnValue::return_code::return_value_error_method_failed;
1201}
1202
1204{
1205 std::map<std::string, Map2DLocation>::iterator it;
1206 it = m_locations_storage.find(location_name);
1207 if (it != m_locations_storage.end())
1208 {
1209 m_locations_storage.erase(it);
1210 return ReturnValue_ok;
1211 }
1212 return ReturnValue::return_code::return_value_error_method_failed;
1213}
1214
1216{
1217 std::map<std::string, Map2DArea>::iterator it;
1218 it = m_areas_storage.find(area_name);
1219 if (it != m_areas_storage.end())
1220 {
1221 m_areas_storage.erase(it);
1222 return ReturnValue_ok;
1223 }
1224 return ReturnValue::return_code::return_value_error_method_failed;
1225}
1226
1228{
1229 std::map<std::string, Map2DPath>::iterator it;
1230 it = m_paths_storage.find(path_name);
1231 if (it != m_paths_storage.end())
1232 {
1233 m_paths_storage.erase(it);
1234 return ReturnValue_ok;
1235 }
1236 return ReturnValue::return_code::return_value_error_method_failed;
1237}
1238
1239ReturnValue Map2DStorage::renameArea(std::string original_name, std::string new_name)
1240{
1241
1242 std::map<std::string, Map2DArea>::iterator orig_it;
1243 orig_it = m_areas_storage.find(original_name);
1244 std::map<std::string, Map2DArea>::iterator new_it;
1245 new_it = m_areas_storage.find(new_name);
1246
1247 if (orig_it != m_areas_storage.end() &&
1248 new_it == m_areas_storage.end())
1249 {
1250 auto area = orig_it->second;
1251 m_areas_storage.erase(orig_it);
1252 m_areas_storage.insert(std::pair<std::string, Map2DArea>(new_name, area));
1253 return ReturnValue_ok;
1254 }
1255 return ReturnValue::return_code::return_value_error_method_failed;
1256}
1257
1258ReturnValue Map2DStorage::renamePath(std::string original_name, std::string new_name)
1259{
1260
1261 std::map<std::string, Map2DPath>::iterator orig_it;
1262 orig_it = m_paths_storage.find(original_name);
1263 std::map<std::string, Map2DPath>::iterator new_it;
1264 new_it = m_paths_storage.find(new_name);
1265
1266 if (orig_it != m_paths_storage.end() &&
1267 new_it == m_paths_storage.end())
1268 {
1269 auto area = orig_it->second;
1270 m_paths_storage.erase(orig_it);
1271 m_paths_storage.insert(std::pair<std::string, Map2DPath>(new_name, area));
1272 return ReturnValue_ok;
1273 }
1274 return ReturnValue::return_code::return_value_error_method_failed;
1275}
1276
1277
1278
1280{
1281 m_locations_storage.clear();
1282 return ReturnValue_ok;
1283}
1284
1286{
1287 m_areas_storage.clear();
1288 return ReturnValue_ok;
1289}
1290
1292{
1293 m_paths_storage.clear();
1294 return ReturnValue_ok;
1295}
1296
1298{
1299 for (auto it = m_maps_storage.begin(); it != m_maps_storage.end(); it++)
1300 {
1301 it->second.clearMapTemporaryFlags();
1302 }
1303 return ReturnValue_ok;
1304}
1305
1307{
1308 auto it = m_maps_storage.find(map_name);
1309 if (it != m_maps_storage.end())
1310 {
1311 it->second.clearMapTemporaryFlags();
1312 return ReturnValue_ok;
1313 }
1314 else
1315 {
1316 return ReturnValue::return_code::return_value_error_method_failed;
1317 }
1318}
1319
1320bool Map2DStorage::read(yarp::os::ConnectionReader& connection)
1321{
1322 yCWarning(MAP2DSTORAGE) << "Map2DStorage::read() not yet implemented";
1323
1324 std::lock_guard<std::mutex> lock(m_mutex);
1326 yarp::os::Bottle out;
1327 bool ok = in.read(connection);
1328 if (!ok) {
1329 return false;
1330 }
1331
1333 if (returnToSender != nullptr)
1334 {
1335 out.write(*returnToSender);
1336 }
1337 else
1338 {
1339 yCError(MAP2DSTORAGE) << "Invalid return to sender";
1340 }
1341 return true;
1342}
1343
1344ReturnValue Map2DStorage::saveMapToDisk(std::string map_name, std::string file_name)
1345{
1346 auto p = m_maps_storage.find(map_name);
1347 if (p == m_maps_storage.end())
1348 {
1349 yCError(MAP2DSTORAGE) << "saveMapToDisk failed: map " << map_name << " not found";
1350 return ReturnValue::return_code::return_value_error_method_failed;
1351 }
1352 else
1353 {
1354 bool b = p->second.saveToFile(file_name);
1355 if (b)
1356 {
1357 yCInfo(MAP2DSTORAGE) << "file" << file_name << " successfully saved";
1358 return ReturnValue_ok;
1359 }
1360 else
1361 {
1362 yCError(MAP2DSTORAGE) << "save_map failed: unable to save " << map_name << " to " << file_name;
1363 return ReturnValue::return_code::return_value_error_method_failed;
1364 }
1365 }
1366 return ReturnValue_ok;
1367}
1368
1370{
1371 MapGrid2D map;
1372 bool r = map.loadFromFile(file_name);
1373 if (r)
1374 {
1375 std::string map_name = map.getMapName();
1376 auto p = m_maps_storage.find(map_name);
1377 if (p == m_maps_storage.end())
1378 {
1379 m_maps_storage[map_name] = map;
1380 yCInfo (MAP2DSTORAGE) << "file" << file_name << "successfully loaded.";
1381 return ReturnValue_ok;
1382 }
1383 else
1384 {
1385 yCError(MAP2DSTORAGE) << map_name << " already exists, skipping.";
1386 return ReturnValue::return_code::return_value_error_method_failed;
1387 }
1388 }
1389 else
1390 {
1391 yCError(MAP2DSTORAGE) << "load_map failed. Unable to load " + file_name;
1392 return ReturnValue::return_code::return_value_error_method_failed;
1393 }
1394 return ReturnValue_ok;
1395}
1396
1398{
1399 bool b = true;
1400 for (auto it = m_maps_storage.begin(); it != m_maps_storage.end(); it++)
1401 {
1402 b &= it->second.enable_map_compression_over_network(enable);
1403 }
1404 if (b)
1405 {
1406 if (enable) {yCInfo(MAP2DSTORAGE) << "compression mode of all maps enabled";}
1407 else {yCInfo(MAP2DSTORAGE) << "compression mode of all maps disabled";}
1408 return ReturnValue_ok;
1409 }
1410
1411 yCError(MAP2DSTORAGE) << "failed to set compression mode";
1412 return ReturnValue::return_code::return_value_error_method_failed;
1413}
1414
1416{
1417 std::lock_guard<std::mutex> lock(m_mutex);
1418 m_objects_storage[object_name] = obj;
1419 return yarp::dev::ReturnValue_ok;
1420}
1421
1423{
1424 std::lock_guard<std::mutex> lock(m_mutex);
1425 auto it = m_objects_storage.find(object_name);
1426 if (it != m_objects_storage.end())
1427 {
1428 obj = it->second;
1429 return yarp::dev::ReturnValue_ok;
1430 }
1432}
1433
1435{
1436 std::lock_guard<std::mutex> lock(m_mutex);
1437 objects.clear();
1438 for (auto& it : m_objects_storage)
1439 {
1440 objects.push_back(it.first);
1441 }
1442 return yarp::dev::ReturnValue_ok;
1443}
1444
1445yarp::dev::ReturnValue Map2DStorage::getAllObjects(std::vector<yarp::dev::Nav2D::Map2DObject>& objects)
1446{
1447 std::lock_guard<std::mutex> lock(m_mutex);
1448 objects.clear();
1449 for (auto& it : m_objects_storage)
1450 {
1451 objects.push_back(it.second);
1452 }
1453 return yarp::dev::ReturnValue_ok;
1454}
1455
1456yarp::dev::ReturnValue Map2DStorage::renameObject(std::string original_name, std::string new_name)
1457{
1458 std::lock_guard<std::mutex> lock(m_mutex);
1459 auto it = m_objects_storage.find(original_name);
1460 if (it != m_objects_storage.end())
1461 {
1462 auto obj = it->second;
1463 m_objects_storage.erase(it);
1464 m_objects_storage[new_name] = obj;
1465 return yarp::dev::ReturnValue_ok;
1466 }
1468}
1469
1471{
1472 std::lock_guard<std::mutex> lock(m_mutex);
1473 auto it = m_objects_storage.find(object_name);
1474 if (it != m_objects_storage.end())
1475 {
1476 m_objects_storage.erase(it);
1477 return yarp::dev::ReturnValue_ok;
1478 }
1480}
1481
1483{
1484 std::lock_guard<std::mutex> lock(m_mutex);
1485 m_objects_storage.clear();
1486 return yarp::dev::ReturnValue_ok;
1487}
1488
1490{
1491 return loadMapsCollection(m_collection_startup_file_with_path);
1492}
1493
1495{
1496 return loadLocationsAndExtras(m_locations_startup_file_with_path);
1497}
static std::string extractPathFromFile(std::string full_filename)
static std::string extractPathFromFile(std::string full_filename)
Definition MapGrid2D.cpp:40
#define ReturnValue_ok
Definition ReturnValue.h:82
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue store_map(const yarp::dev::Nav2D::MapGrid2D &map) override
Stores a map into the map server.
yarp::dev::ReturnValue getObjectsList(std::vector< std::string > &locations) override
Get a list of the names of all stored objects.
yarp::dev::ReturnValue saveMapsCollection(std::string maps_collection_file) override
Save a collection of maps to disk.
yarp::dev::ReturnValue deleteLocation(std::string location_name) override
Delete a location.
yarp::dev::ReturnValue getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area.
yarp::dev::ReturnValue getAllObjects(std::vector< yarp::dev::Nav2D::Map2DObject > &obj) override
Get a list of all stored objects.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getAllPaths(std::vector< yarp::dev::Nav2D::Map2DPath > &paths) override
Get a list of all stored paths.
yarp::dev::ReturnValue storeObject(std::string object_name, yarp::dev::Nav2D::Map2DObject obj) override
Store a object specified by the user in the world reference frame.
yarp::dev::ReturnValue getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location specified by the user in the world reference frame.
yarp::dev::ReturnValue renameObject(std::string original_name, std::string new_name) override
Searches for a object and renames it.
yarp::dev::ReturnValue getObject(std::string object_name, yarp::dev::Nav2D::Map2DObject &obj) override
Retrieves a object specified by the user in the world reference frame.
yarp::dev::ReturnValue reloadMapsCollection() override
Reloads the last opened file containing the maps from disk.
yarp::dev::ReturnValue enableMapsCompression(bool enable) override
Enable/disables maps compression over the network.
yarp::dev::ReturnValue storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override
Store a location specified by the user in the world reference frame.
yarp::dev::ReturnValue storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override
Store an area.
yarp::dev::ReturnValue getAreasList(std::vector< std::string > &areas) override
Get a list of the names of all stored areas.
yarp::dev::ReturnValue clearAllPaths() override
Delete all stored paths.
yarp::dev::ReturnValue storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override
Store a path.
yarp::dev::ReturnValue clearMapTemporaryFlags(std::string map_name) override
Clear all temporary flags from a specific map.
Map2DStorage()
Map2DStorage.
yarp::dev::ReturnValue get_map_names(std::vector< std::string > &map_names) override
Gets a list containing the names of all registered maps.
yarp::dev::ReturnValue getPathsList(std::vector< std::string > &paths) override
Get a list of the names of all stored paths.
yarp::dev::ReturnValue saveLocationsAndExtras(std::string locations_file) override
Save a collection of locations/area/paths etc to disk.
yarp::dev::ReturnValue loadMapsCollection(std::string maps_collection_file) override
Load a collection of maps from disk.
yarp::dev::ReturnValue deletePath(std::string path_name) override
Delete a path.
yarp::dev::ReturnValue clearAllLocations() override
Delete all stored locations.
yarp::dev::ReturnValue getAllAreas(std::vector< yarp::dev::Nav2D::Map2DArea > &areas) override
Get a list of all stored areas.
yarp::dev::ReturnValue remove_map(std::string map_name) override
Removes a map from the map server.
yarp::dev::ReturnValue renameArea(std::string original_name, std::string new_name) override
Searches for an area and renames it.
yarp::dev::ReturnValue loadMapFromDisk(std::string file_name) override
Load a map from disk.
yarp::dev::ReturnValue clearAllMapsTemporaryFlags() override
Clear all temporary flags from all stored maps.
yarp::dev::ReturnValue deleteArea(std::string area_name) override
Delete an area.
yarp::dev::ReturnValue getAllLocations(std::vector< yarp::dev::Nav2D::Map2DLocation > &locations) override
Get a list of all stored locations.
yarp::dev::ReturnValue renamePath(std::string original_name, std::string new_name) override
Searches for a path and renames it.
yarp::dev::ReturnValue get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map) override
Gets a map from the map server.
yarp::dev::ReturnValue saveMapToDisk(std::string map_name, std::string file_name) override
Save a map to disk.
yarp::dev::ReturnValue clearAllAreas() override
Delete all stored areas.
yarp::dev::ReturnValue getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path) override
Retrieves a path.
yarp::dev::ReturnValue deleteObject(std::string object_name) override
Delete an object.
yarp::dev::ReturnValue renameLocation(std::string original_name, std::string new_name) override
Searches for a location and renames it.
yarp::dev::ReturnValue reloadLocationsAndExtras() override
Reloads the last opened file containing the collection of locations/areas/paths etc from disk.
yarp::dev::ReturnValue loadLocationsAndExtras(std::string locations_file) override
Load a collection of locations/areas/paths etc from disk.
yarp::dev::ReturnValue clearAllObjects() override
Delete all stored objects.
yarp::dev::ReturnValue getLocationsList(std::vector< std::string > &locations) override
Get a list of the names of all stored locations.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
yarp::dev::ReturnValue clearAllMaps() override
Removes all the registered maps from the server.
std::string description
user defined string
std::string map_id
name of the map
std::vector< yarp::math::Vec2D< double > > points
list of points which define the vertices of the area
std::string map_id
name of the map
double theta
orientation [deg] in the map reference frame
double y
y position of the location [m], expressed in the map reference frame
double x
x position of the location [m], expressed in the map reference frame
std::string description
user defined string
void push_back(yarp::dev::Nav2D::Map2DLocation loc)
Inserts a new location into the path @loc the location to be inserted.
std::string getMapName() const
Retrieves the map name.
bool crop(int left, int top, int right, int bottom)
Modifies the map, cropping pixels at the boundaries.
bool loadFromFile(std::string map_filename)
Loads a yarp map file from disk.
@ return_value_error_method_failed
Method is deprecated.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void setReader(PortReader &reader) override
Set an external reader for port data.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void fromString(const std::string &text)
Initializes bottle from a string.
Definition Bottle.cpp:205
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:252
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:241
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:247
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition Bottle.cpp:231
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
std::string findFile(const std::string &name)
Find the full path to a file.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition Value.cpp:222
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
virtual bool isList() const
Checks if value is a list.
Definition Value.cpp:162
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:246
virtual std::string asString() const
Get string value.
Definition Value.cpp:240
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
typename vec2D_selector< T >::type Vec2D
Definition Vec2D.h:104
An interface to the operating system, including Port based communication.
#define YARP_UNUSED(var)
Definition api.h:162