comparison BEDTools-Version-2.14.3/src/utils/lineFileUtilities/lineFileUtilities.h @ 0:dfcd8b6c1bda

Uploaded
author aaronquinlan
date Thu, 03 Nov 2011 10:25:04 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dfcd8b6c1bda
1 #ifndef LINEFILEUTILITIES_H
2 #define LINEFILEUTILITIES_H
3
4 #include <vector>
5 #include <string>
6 #include <cstring>
7 #include <cstdlib>
8 #include <sstream>
9
10 using namespace std;
11
12 // templated function to convert objects to strings
13 template <typename T>
14 inline
15 std::string ToString(const T & value) {
16 std::stringstream ss;
17 ss << value;
18 return ss.str();
19 }
20
21 // tokenize into a list of strings.
22 inline
23 void Tokenize(const string &str, vector<string> &elems, const string &delimiter = "\t")
24 {
25 char* tok;
26 char cchars [str.size()+1];
27 char* cstr = &cchars[0];
28 strcpy(cstr, str.c_str());
29 tok = strtok(cstr, delimiter.c_str());
30 while (tok != NULL) {
31 elems.push_back(tok);
32 tok = strtok(NULL, delimiter.c_str());
33 }
34 }
35
36 // tokenize into a list of integers
37 inline
38 void Tokenize(const string &str, vector<int> &elems, const string &delimiter = "\t")
39 {
40 char* tok;
41 char cchars [str.size()+1];
42 char* cstr = &cchars[0];
43 strcpy(cstr, str.c_str());
44 tok = strtok(cstr, delimiter.c_str());
45 while (tok != NULL) {
46 elems.push_back(atoi(tok));
47 tok = strtok(NULL, delimiter.c_str());
48 }
49 }
50
51 #endif /* LINEFILEUTILITIES_H */
52