iCub-main
Loading...
Searching...
No Matches
dynContactList.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2011 RobotCub Consortium
3 * Author: Andrea Del Prete
4 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
5 *
6 */
7
8#include <iostream>
9#include <sstream>
10#include <iomanip>
11#include <string>
12
13#include <yarp/os/ConnectionReader.h>
14#include <yarp/os/ConnectionWriter.h>
16#include <iCub/ctrl/math.h>
17
18using namespace std;
19using namespace yarp::os;
20using namespace iCub::skinDynLib;
21
22
25
26dynContactList::dynContactList(const size_type &n, const dynContact& value)
27:vector<dynContact>(n, value){}
28
29
30//~~~~~~~~~~~~~~~~~~~~~~~~~~
31// SERIALIZATION methods
32//~~~~~~~~~~~~~~~~~~~~~~~~~~
33bool dynContactList::read(ConnectionReader& connection)
34{
35 // A dynContactList is represented as a list of list
36 // where each list is a skinContact
37 if(connection.expectInt32()!=BOTTLE_TAG_LIST)
38 return false;
39
40 int listLength = connection.expectInt32();
41 if(listLength<0)
42 return false;
43 if(listLength!=size())
44 resize(listLength);
45
46 for(iterator it=begin(); it!=end(); it++)
47 if(!it->read(connection))
48 return false;
49
50 return !connection.isError();
51}
52//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53bool dynContactList::write(ConnectionWriter& connection) const
54{
55 // A dynContactList is represented as a list of list
56 // where each list is a skinContact
57 connection.appendInt32(BOTTLE_TAG_LIST);
58 connection.appendInt32(size());
59
60 for(auto it=begin(); it!=end(); it++)
61 if(!it->write(connection))
62 return false;
63
64 return !connection.isError();
65}
66//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67string dynContactList::toString(const int &precision) const{
68 stringstream ss;
69 for(const_iterator it=begin();it!=end();it++)
70 ss<<"- "<<it->toString(precision)<<";\n";
71 return ss.str();
72}
73
virtual std::string toString(const int &precision=-1) const
Useful to print some information.
virtual bool write(yarp::os::ConnectionWriter &connection) const
Write dynContactList to a connection.
virtual bool read(yarp::os::ConnectionReader &connection)
Class representing an external contact acting on a link of the robot body.
Definition dynContact.h:52
int n