Replacing atoi by boost::spirit::qi

This commit is contained in:
DennisOSRM
2012-11-20 12:15:40 +01:00
parent aed5848f5a
commit 870ed96c24
4 changed files with 34 additions and 23 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../typedefs.h"
// Check if file exists and if it can be opened for reading with ifstream an object
inline bool testDataFile(const char *filename){
inline bool testDataFile(const std::string & filename){
boost::filesystem::path fileToTest(filename);
if(!boost::filesystem::exists(fileToTest)) {
WARN("Failed to open file " << filename << " for reading.");
+12
View File
@@ -27,8 +27,10 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <sstream>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/qi.hpp>
#include "../DataStructures/Coordinate.h"
#include "../typedefs.h"
// precision: position after decimal point
// length: maximum number of digits including comma and decimals
@@ -68,6 +70,16 @@ static inline void intToString(const int value, std::string & output) {
boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value);
}
static inline int stringToInt(const std::string& input) {
std::string::const_iterator realBeginOfNumber = input.begin();
//Delete any trailing white-spaces
while(realBeginOfNumber != input.end() && std::isspace(*realBeginOfNumber))
++realBeginOfNumber;
int value = 0; // 2
boost::spirit::qi::parse(realBeginOfNumber, input.end(), boost::spirit::int_, value); // 3
return value;
}
static inline void convertInternalLatLonToString(const int value, std::string & output) {
char buffer[100];
buffer[10] = 0; // Nullterminierung