icub-client
functions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 WYSIWYD Consortium, European Commission FP7 Project ICT-612139
3  * Authors: Stéphane Lallée
4  * email: stephane.lallee@gmail.com
5  * website: https://github.com/robotology/icub-client/
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  * icub-client/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 
19 #include <fstream>
20 #include <yarp/os/Value.h>
21 #include <yarp/os/LogStream.h>
22 #include <yarp/os/Vocab.h>
23 #include "icubclient/functions.h"
24 
25 using namespace yarp::os;
26 using namespace icubclient;
27 
28 /************************************************************************/
29 yarp::os::Bottle icubclient::opcGetIdsFromAsk(const yarp::os::Bottle &reply)
30 {
31  Bottle ids;
32  if (reply.size()>0)
33  if (reply.get(0).asVocab()==Vocab::encode("ack"))
34  if (Bottle *idProp=reply.get(1).asList())
35  if (Bottle *idList=idProp->get(1).asList())
36  ids=*idList;
37 
38  return ids;
39 }
40 
41 /************************************************************************/
42 void icubclient::replace_all(std::string & in, const std::string & plain, const std::string & tok)
43 {
44  std::string::size_type n = 0;
45  const std::string::size_type l = plain.length();
46  while(1){
47  n = in.find(plain, n);
48  if(n != std::string::npos){
49  in.replace(n, l, tok);
50  }
51  else{
52  break;
53  }
54  }
55 }
56 
57 /************************************************************************/
58 std::string icubclient::grammarToString(const std::string &sPath)
59 {
60  std::string sOutput = "";
61  std::ifstream isGrammar(sPath.c_str());
62 
63  yDebug() << "Path is:" << sPath;
64 
65  if (!isGrammar)
66  {
67  yError() << "grammarToString. Couldn't open file :" << sPath;
68  return "Error in grammarToString. Couldn't open file";
69  }
70 
71  std::string sLine;
72  while (getline(isGrammar, sLine))
73  {
74  sOutput += sLine;
75  sOutput += "\n";
76  }
77 
78  return sOutput;
79 }
void replace_all(std::string &in, const std::string &plain, const std::string &tok)
Simple search and replace function for strings;.
Definition: functions.cpp:42
std::string grammarToString(const std::string &sPath)
Get the context path of a .grxml grammar, and return it as a string.
Definition: functions.cpp:58
yarp::os::Bottle opcGetIdsFromAsk(const yarp::os::Bottle &reply)
Allow retrieving the list of unique identifiers of those items verifying the set of conditions querie...
Definition: functions.cpp:29