-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinput.hpp
32 lines (27 loc) · 954 Bytes
/
tinput.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef TINPUT_HEADER
#define TINPUT_HEADER
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
namespace rcl{
template <typename T> inline void readfrombuffer(const std::vector<unsigned char>& buffer,std::string& name,T& value){
std::vector<unsigned char>::const_iterator cursor;
cursor = search (buffer.begin(),buffer.end(),name.begin(),name.end());
cursor = cursor + name.length();
std::string data;
while(*cursor!='\n') { if (*cursor!=':') data.push_back(*cursor); cursor++; }
std::stringstream mystream(data);
mystream >> value;
return;
}
template <typename T> inline void readfrombuffer(const std::vector<unsigned char>& buffer,const char *name,T& value){
std::string namestring(name);
readfrombuffer(buffer,namestring,value);
return;
}
template <typename T> inline void stringtovalue(T& value,const std::string& str){
std::stringstream(str) >> value; return;
}
} // end namespace rcl
#endif