Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpRequest.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Network Request.
32  */
33 
34 #ifndef vpRequest_H
35 #define vpRequest_H
36 
37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpDebug.h>
39 #include <visp3/core/vpException.h>
40 #include <visp3/core/vpImageException.h>
41 
42 #include <string.h>
43 #include <vector>
44 
127 class VISP_EXPORT vpRequest
128 {
129 protected:
130  std::string request_id;
131  std::vector<std::string> listOfParams;
132 
133 public:
134  vpRequest();
135  virtual ~vpRequest();
136 
137  void addParameter(const char *params);
138  void addParameter(const std::string &params);
139  void addParameter(const std::vector<std::string> &listOfparams);
140  template <typename T> void addParameterObject(T *params, const int &sizeOfObject = sizeof(T));
141 
147  virtual void decode() = 0;
148 
152  void clear() { listOfParams.clear(); }
153 
159  virtual void encode() = 0;
160 
166  inline std::string &operator[](const unsigned int &i) { return listOfParams[i]; }
167 
173  inline const std::string &operator[](const unsigned int &i) const { return listOfParams[i]; }
174 
182  std::string getId() const { return request_id; }
183 
191  void setId(const char *id) { request_id = id; }
192 
198  unsigned int size() const { return (unsigned int)listOfParams.size(); }
199 };
200 
201 //######## Definition of Template Functions ########
202 //# #
203 //##################################################
204 
217 template <typename T> void vpRequest::addParameterObject(T *params, const int &sizeOfObject)
218 {
219  if (sizeOfObject != 0) {
220  char *tempS = new char[sizeOfObject];
221  memcpy((void *)tempS, (void *)params, sizeOfObject);
222  std::string returnVal(tempS, (size_t)sizeOfObject);
223 
224  listOfParams.push_back(returnVal);
225 
226  delete[] tempS;
227  }
228 }
229 END_VISP_NAMESPACE
230 #endif
This the request that will transit on the network.
Definition: vpRequest.h:128
void clear()
Definition: vpRequest.h:152
void setId(const char *id)
Definition: vpRequest.h:191
std::string request_id
Definition: vpRequest.h:130
virtual void decode()=0
virtual void encode()=0
std::vector< std::string > listOfParams
Definition: vpRequest.h:131
const std::string & operator[](const unsigned int &i) const
Definition: vpRequest.h:173
std::string & operator[](const unsigned int &i)
Definition: vpRequest.h:166
std::string getId() const
Definition: vpRequest.h:182
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition: vpRequest.h:217
unsigned int size() const
Definition: vpRequest.h:198