g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
stuff
string_tools.h
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#ifndef G2O_STRING_TOOLS_H
28
#define G2O_STRING_TOOLS_H
29
30
#include <cstdlib>
31
#include <sstream>
32
#include <string>
33
#include <vector>
34
35
#include "
g2o_stuff_api.h
"
36
#include "
macros.h
"
37
38
namespace
g2o
{
39
41
// @{
42
46
50
G2O_STUFF_API
std::string
trim
(
const
std::string& s);
51
55
G2O_STUFF_API
std::string
trimLeft
(
const
std::string& s);
56
60
G2O_STUFF_API
std::string
trimRight
(
const
std::string& s);
61
65
G2O_STUFF_API
std::string
strToLower
(
const
std::string& s);
66
70
G2O_STUFF_API
std::string
strToUpper
(
const
std::string& s);
71
76
template
<
typename
OutputIterator>
77
OutputIterator
readInts
(
const
char
* str, OutputIterator
out
) {
78
char
* cl = (
char
*)str;
79
char
* cle = cl;
80
while
(1) {
81
long
int
id
= strtol(cl, &cle, 10);
82
if
(cl == cle)
break
;
83
*
out
++ = id;
84
cl = cle;
85
}
86
return
out
;
87
}
88
93
template
<
typename
OutputIterator>
94
OutputIterator
readFloats
(
const
char
* str, OutputIterator
out
) {
95
char
* cl = (
char
*)str;
96
char
* cle = cl;
97
while
(1) {
98
double
val = strtod(cl, &cle);
99
if
(cl == cle)
break
;
100
*
out
++ = val;
101
cl = cle;
102
}
103
return
out
;
104
}
105
110
G2O_STUFF_API
std::string
formatString
(
const
char
* fmt,
111
...)
G2O_ATTRIBUTE_FORMAT12
;
112
116
G2O_STUFF_API
int
strPrintf
(
std
::
string
& str, const
char
* fmt,
117
...)
G2O_ATTRIBUTE_FORMAT23
;
118
122
template <typename T>
123
bool
convertString
(const
std
::
string
& s, T& x,
124
bool
failIfLeftoverChars = true) {
125
std::istringstream i(s);
126
char
c;
127
if
(!(i >> x) || (failIfLeftoverChars && i.get(c)))
return
false
;
128
return
true
;
129
}
130
135
template
<
typename
T>
136
T
stringToType
(
const
std::string& s,
bool
failIfLeftoverChars =
true
) {
137
T x;
138
convertString
(s, x, failIfLeftoverChars);
139
return
x;
140
}
141
145
G2O_STUFF_API
bool
strStartsWith
(
const
std::string& str,
146
const
std::string& substr);
147
151
G2O_STUFF_API
bool
strEndsWith
(
const
std::string& str,
152
const
std::string& substr);
153
159
G2O_STUFF_API
std::string
strExpandFilename
(
const
std::string& filename);
160
164
G2O_STUFF_API
std::vector<std::string>
strSplit
(
const
std::string& s,
165
const
std::string& delim);
166
172
G2O_STUFF_API
int
readLine
(std::istream& is, std::stringstream& currentLine);
173
177
G2O_STUFF_API
void
skipLine
(std::istream& is);
178
179
// @}
180
181
}
// namespace g2o
182
183
#endif
g2o_stuff_api.h
G2O_STUFF_API
#define G2O_STUFF_API
Definition
g2o_stuff_api.h:56
macros.h
G2O_ATTRIBUTE_FORMAT12
#define G2O_ATTRIBUTE_FORMAT12
Definition
macros.h:94
G2O_ATTRIBUTE_FORMAT23
#define G2O_ATTRIBUTE_FORMAT23
Definition
macros.h:95
g2o
Definition
dl_wrapper.cpp:55
g2o::readLine
int readLine(std::istream &is, std::stringstream ¤tLine)
Definition
string_tools.cpp:161
g2o::strExpandFilename
std::string strExpandFilename(const std::string &filename)
Definition
string_tools.cpp:117
g2o::trimLeft
std::string trimLeft(const std::string &s)
Definition
string_tools.cpp:58
g2o::trimRight
std::string trimRight(const std::string &s)
Definition
string_tools.cpp:66
g2o::strEndsWith
bool strEndsWith(const std::string &s, const std::string &end)
Definition
string_tools.cpp:156
g2o::convertString
bool convertString(const std::string &s, T &x, bool failIfLeftoverChars=true)
Definition
string_tools.h:123
g2o::trim
std::string trim(const std::string &s)
Definition
string_tools.cpp:50
g2o::readFloats
OutputIterator readFloats(const char *str, OutputIterator out)
Definition
string_tools.h:94
g2o::strSplit
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)
Definition
string_tools.cpp:135
g2o::formatString
std::string formatString(const char *fmt,...)
Definition
string_tools.cpp:90
g2o::strToLower
std::string strToLower(const std::string &s)
Definition
string_tools.cpp:74
g2o::stringToType
T stringToType(const std::string &s, bool failIfLeftoverChars=true)
Definition
string_tools.h:136
g2o::strToUpper
std::string strToUpper(const std::string &s)
Definition
string_tools.cpp:82
g2o::strStartsWith
bool strStartsWith(const std::string &s, const std::string &start)
Definition
string_tools.cpp:151
g2o::strPrintf
int strPrintf(std::string &str, const char *fmt,...)
Definition
string_tools.cpp:106
g2o::readInts
OutputIterator readInts(const char *str, OutputIterator out)
Definition
string_tools.h:77
g2o::skipLine
void skipLine(std::istream &is)
Definition
string_tools.cpp:175
std
Definition
jet.h:876
out
std::ostream * out
Definition
scanner.l:138
Generated on
for g2o by
1.17.0