ViSP  2.9.0
vpRequest.h
1 /****************************************************************************
2  *
3  * $Id: vpRequest.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Network Request.
36  *
37  * Authors:
38  * Aurelien Yol
39  *
40  *****************************************************************************/
41 
42 #ifndef vpRequest_H
43 #define vpRequest_H
44 
45 #include <visp/vpConfig.h>
46 #include <visp/vpDebug.h>
47 #include <visp/vpException.h>
48 #include <visp/vpImageException.h>
49 
50 #include <string.h>
51 #include <vector>
52 
134 class VISP_EXPORT vpRequest
135 {
136 protected:
137  std::string request_id;
138  std::vector<std::string> listOfParams;
139 
140 public:
141  vpRequest();
142  virtual ~vpRequest();
143 
144  void addParameter(char *params);
145  void addParameter(std::string &params);
146  void addParameter(std::vector<std::string> &listOfparams);
147  template<typename T>
148  void addParameterObject(T * params, const int &sizeOfObject = sizeof(T));
149 
155  virtual void decode() = 0;
156 
160  void clear(){ listOfParams.clear(); }
161 
167  virtual void encode() = 0;
168 
174  inline std::string& operator[](const unsigned int &i) { return listOfParams[i];}
175 
181  inline const std::string& operator[](const unsigned int &i) const { return listOfParams[i];}
182 
190  std::string getId(){ return request_id; }
191 
199  void setId(const char *id){ request_id = id; }
200 
206  unsigned int size(){ return (unsigned int)listOfParams.size(); }
207 };
208 
209 
210 //######## Definition of Template Functions ########
211 //# #
212 //##################################################
213 
214 
227 template<typename T>
228 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, sizeOfObject);
234 
235  listOfParams.push_back(returnVal);
236 
237  delete [] tempS;
238  }
239 }
240 
241 #endif
This the request that will transit on the network.
Definition: vpRequest.h:134
std::string & operator[](const unsigned int &i)
Definition: vpRequest.h:174
const std::string & operator[](const unsigned int &i) const
Definition: vpRequest.h:181
void addParameterObject(T *params, const int &sizeOfObject=sizeof(T))
Definition: vpRequest.h:228
std::string request_id
Definition: vpRequest.h:137
unsigned int size()
Definition: vpRequest.h:206
std::vector< std::string > listOfParams
Definition: vpRequest.h:138
std::string getId()
Definition: vpRequest.h:190
void clear()
Definition: vpRequest.h:160
void setId(const char *id)
Definition: vpRequest.h:199