iCub-main
Serialization.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
20 
21 namespace iCub {
22 namespace learningmachine {
23 namespace serialization {
24 
25 yarp::os::Bottle& operator<<(yarp::os::Bottle &out, int val) {
26  out.addInt32(val);
27  return out;
28 }
29 
30 yarp::os::Bottle& operator<<(yarp::os::Bottle &out, size_t val) {
31  out.addInt32(val);
32  return out;
33 }
34 
35 yarp::os::Bottle& operator<<(yarp::os::Bottle &out, double val) {
36  out.addFloat64(val);
37  return out;
38 }
39 
40 yarp::os::Bottle& operator<<(yarp::os::Bottle &out, const yarp::sig::Vector& v) {
41  for(size_t i = 0; i < v.size(); i++) {
42  out << v(i);
43  }
44  out << (int)v.size();
45  return out;
46 }
47 
48 yarp::os::Bottle& operator<<(yarp::os::Bottle &out, const yarp::sig::Matrix& M) {
49  for(int r = 0; r < M.rows(); r++) {
50  for(int c = 0; c < M.cols(); c++) {
51  out << M(r,c);
52  }
53  }
54  out << M.rows() << M.cols();
55  return out;
56 }
57 
58 yarp::os::Bottle& operator>>(yarp::os::Bottle &in, int& val) {
59  val = in.pop().asInt32();
60  return in;
61 }
62 
63 yarp::os::Bottle& operator>>(yarp::os::Bottle &in, double& val) {
64  val = in.pop().asFloat64();
65  return in;
66 }
67 
68 yarp::os::Bottle& operator>>(yarp::os::Bottle &in, yarp::sig::Vector& v) {
69  int len;
70  in >> len;
71  v.resize(len);
72  for(int i = v.size() - 1; i >= 0; i--) {
73  in >> v(i);
74  }
75  return in;
76 }
77 
78 yarp::os::Bottle& operator>>(yarp::os::Bottle &in, yarp::sig::Matrix& M) {
79  int rows, cols;
80  in >> cols >> rows;
81  M.resize(rows, cols);
82  for(int r = M.rows() - 1; r >= 0; r--) {
83  for(int c = M.cols() - 1; c >= 0; c--) {
84  in >> M(r, c);
85  }
86  }
87  return in;
88 }
89 
90 
91 
92 } // serialization
93 } // learningmachine
94 } // iCub
95 
yarp::os::Bottle & operator>>(yarp::os::Bottle &in, int &val)
Pops an integer from the end of a Bottle using the extraction operator.
yarp::os::Bottle & operator<<(yarp::os::Bottle &out, int val)
Helper functions for serialization in bottles for use in the learningMachine library.
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
out
Definition: sine.m:8