Visual Servoing Platform  version 3.3.1 under development (2020-08-12)
vpRequest.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Network Request.
33  *
34  * Authors:
35  * Aurelien Yol
36  *
37  *****************************************************************************/
38 
39 #ifndef vpRequest_H
40 #define vpRequest_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpDebug.h>
44 #include <visp3/core/vpException.h>
45 #include <visp3/core/vpImageException.h>
46 
47 #include <string.h>
48 #include <vector>
49 
131 class VISP_EXPORT vpRequest
132 {
133 protected:
134  std::string request_id;
135  std::vector<std::string> listOfParams;
136 
137 public:
138  vpRequest();
139  virtual ~vpRequest();
140 
141  void addParameter(char *params);
142  void addParameter(std::string &params);
143  void addParameter(std::vector<std::string> &listOfparams);
144  template <typename T> void addParameterObject(T *params, const int &sizeOfObject = sizeof(T));
145 
151  virtual void decode() = 0;
152 
156  void clear() { listOfParams.clear(); }
157 
163  virtual void encode() = 0;
164 
170  inline std::string &operator[](const unsigned int &i) { return listOfParams[i]; }
171 
177  inline const std::string &operator[](const unsigned int &i) const { return listOfParams[i]; }
178 
186  std::string getId() { return request_id; }
187 
195  void setId(const char *id) { request_id = id; }
196 
202  unsigned int size() { return (unsigned int)listOfParams.size(); }
203 };
204 
205 //######## Definition of Template Functions ########
206 //# #
207 //##################################################
208 
221 template <typename T> void vpRequest::addParameterObject(T *params, const int &sizeOfObject)
222 {
223  if (sizeOfObject != 0) {
224  char *tempS = new char[sizeOfObject];
225  memcpy((void *)tempS, (void *)params, sizeOfObject);
226  std::string returnVal(tempS, (size_t)sizeOfObject);
227 
228  listOfParams.push_back(returnVal);
229 
230  delete[] tempS;
231  }
232 }
233 
234 #endif
This the request that will transit on the network.
Definition: vpRequest.h:131
std::string & operator[](const unsigned int &i)
Definition: vpRequest.h:170
const std::string & operator[](const unsigned int &i) const
Definition: vpRequest.h:177
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition: vpRequest.h:221
std::string request_id
Definition: vpRequest.h:134
unsigned int size()
Definition: vpRequest.h:202
std::vector< std::string > listOfParams
Definition: vpRequest.h:135
std::string getId()
Definition: vpRequest.h:186
void clear()
Definition: vpRequest.h:156
void setId(const char *id)
Definition: vpRequest.h:195