d4c
d4c_helpers.cpp
1 /*
2  * Copyright (C) 2013 iCub Facility - Istituto Italiano di Tecnologia
3  * Authors: Ilaria Gori, Ugo Pattacini
4  * email: ilaria.gori@iit.it, ugo.pattacini@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16 */
17 
18 #include <iCub/d4c/private/d4c_helpers.h>
19 
20 using namespace std;
21 using namespace yarp::os;
22 using namespace yarp::sig;
23 
24 
25 /************************************************************************/
26 bool iCub::d4c::extractVector(const Property &prop, const string &option,
27  Vector &res)
28 {
29  if (prop.check(option.c_str()))
30  {
31  if (Bottle *v=prop.find(option.c_str()).asList())
32  {
33  res.resize(v->size());
34  for (size_t i=0; i<res.length(); i++)
35  res[i]=v->get(i).asDouble();
36 
37  return true;
38  }
39  else
40  return false;
41  }
42  else
43  return false;
44 }
45 
46 
47 /************************************************************************/
48 bool iCub::d4c::copyVectorData(const Vector &src, Vector &dest)
49 {
50  size_t offs=0;
51  if (src.length()>3)
52  offs=3;
53 
54  if (src.length()<=dest.length()-offs)
55  {
56  for (size_t i=0; i<src.length(); i++)
57  dest[offs+i]=src[i];
58 
59  return true;
60  }
61  else
62  return false;
63 }
64 
65