Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRequest.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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 VP_REQUEST_H
35#define VP_REQUEST_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
127class VISP_EXPORT vpRequest
128{
129protected:
130 std::string request_id;
131 std::vector<std::string> listOfParams;
132
133public:
134 vpRequest();
136 {
137 *this = req;
138 }
139 virtual ~vpRequest() { }
140
142 {
145 return *this;
146 }
147
148 void addParameter(const char *params);
149 void addParameter(const std::string &params);
150 void addParameter(const std::vector<std::string> &listOfparams);
151 template <typename T> void addParameterObject(T *params, const int &sizeOfObject = sizeof(T));
152
158 virtual void decode() = 0;
159
163 void clear() { listOfParams.clear(); }
164
170 virtual void encode() = 0;
171
177 inline std::string &operator[](const unsigned int &i) { return listOfParams[i]; }
178
184 inline const std::string &operator[](const unsigned int &i) const { return listOfParams[i]; }
185
193 std::string getId() const { return request_id; }
194
202 void setId(const char *id) { request_id = id; }
203
209 unsigned int size() const { return static_cast<unsigned int>(listOfParams.size()); }
210};
211
212//######## Definition of Template Functions ########
213//# #
214//##################################################
215
228template <typename T> void vpRequest::addParameterObject(T *params, const int &sizeOfObject)
229{
230 if (sizeOfObject != 0) {
231 char *tempS = new char[sizeOfObject];
232 memcpy((void *)tempS, (void *)params, sizeOfObject);
233 std::string returnVal(tempS, static_cast<size_t>(sizeOfObject));
234
235 listOfParams.push_back(returnVal);
236
237 delete[] tempS;
238 }
239}
240END_VISP_NAMESPACE
241#endif
void clear()
Definition vpRequest.h:163
std::string & operator[](const unsigned int &i)
Definition vpRequest.h:177
void setId(const char *id)
Definition vpRequest.h:202
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
virtual ~vpRequest()
Definition vpRequest.h:139
vpRequest & operator=(const vpRequest &req)
Definition vpRequest.h:141
vpRequest(const vpRequest &req)
Definition vpRequest.h:135
std::string getId() const
Definition vpRequest.h:193
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition vpRequest.h:228
const std::string & operator[](const unsigned int &i) const
Definition vpRequest.h:184
unsigned int size() const
Definition vpRequest.h:209