VinaLC: Parallel Molecular Docking Program

Biochemical and Biophysical Systems Group
VinaLC version: 1.1.2

tokenize.h
Go to the documentation of this file.
1 /*
2  * File: tokenize.h
3  * Author: zhang30
4  *
5  * Created on February 3, 2012, 2:03 PM
6  */
7 
8 #ifndef VINA_TOKENIZE_H
9 #define VINA_TOKENIZE_H
10 
11 #include <algorithm>
12 #include <cstdlib>
13 #include <string>
14 #include <iterator>
15 #include <sstream>
16 
17 
18 template < class ContainerT >
19 void tokenize(const std::string& str, ContainerT& tokens,
20  const std::string& delimiters = " ", const bool trimEmpty = true) {
21  typedef ContainerT Base;
22  typedef typename Base::value_type ValueType;
23  typedef typename ValueType::size_type SizeType;
24  SizeType pos, lastPos = 0;
25  while (true) {
26  pos = str.find_first_of(delimiters, lastPos);
27  if (pos == std::string::npos) {
28  pos = str.length();
29 
30  if (pos != lastPos || !trimEmpty)
31  tokens.push_back(ValueType(str.data() + lastPos, (SizeType)pos - lastPos));
32 
33  break;
34  } else {
35  if (pos != lastPos || !trimEmpty)
36  tokens.push_back(ValueType(str.data() + lastPos, (SizeType)pos - lastPos));
37  }
38 
39  lastPos = pos + 1;
40  }
41 };
42 
43 
44 template <typename T1, typename T2>
45 T1 Sstrm(T2 inValue){
46  std::stringstream ss;
47  ss << inValue;
48  T1 outValue;
49  ss >> outValue;
50 
51  return(outValue);
52 }
53 
54 #endif /* VINA_TOKENIZE_H */
55