split conversions.cpp into separate compilation units to avoid boost::spirit::qi and boost::spirit::x3 clashes
This commit is contained in:
parent
200b9a75b0
commit
df1a95eeef
3 changed files with 168 additions and 132 deletions
|
@ -161,7 +161,8 @@ source = Split(
|
|||
generate_image_filters.cpp
|
||||
image_filter_grammar_x3.cpp
|
||||
color.cpp
|
||||
conversions.cpp
|
||||
conversions_numeric.cpp
|
||||
conversions_string.cpp
|
||||
image_copy.cpp
|
||||
image_compositing.cpp
|
||||
image_scaling.cpp
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
* Copyright (C) 2016 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -25,26 +25,13 @@
|
|||
#include <mapnik/value_types.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
// karma is used by default
|
||||
//#define MAPNIK_KARMA_TO_STRING
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#ifdef MAPNIK_KARMA_TO_STRING
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#endif
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#if _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
namespace util {
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
using namespace boost::spirit;
|
||||
|
||||
|
@ -155,119 +142,5 @@ bool string2float(const char* iter, const char* end, float& result)
|
|||
bool r = x3::phrase_parse(iter, end, FLOAT, space, result);
|
||||
return r && (iter == end);
|
||||
}
|
||||
|
||||
// double conversion - here we use sprintf over karma to work
|
||||
// around https://github.com/mapnik/mapnik/issues/1741
|
||||
bool to_string(std::string& s, double val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%g", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef MAPNIK_KARMA_TO_STRING
|
||||
|
||||
bool to_string(std::string& str, int value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
|
||||
#ifdef BIGINT
|
||||
bool to_string(std::string& str, mapnik::value_integer value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool to_string(std::string& str, unsigned value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
|
||||
bool to_string(std::string& str, bool value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool to_string(std::string& s, int val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%d", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef BIGINT
|
||||
bool to_string(std::string& s, mapnik::value_integer val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%lld", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool to_string(std::string& s, unsigned val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%u", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool to_string(std::string& s, bool val)
|
||||
{
|
||||
if (val)
|
||||
s = "true";
|
||||
else
|
||||
s = "false";
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace util
|
||||
}
|
||||
} // util
|
||||
} // mapnik
|
162
src/conversions_string.cpp
Normal file
162
src/conversions_string.cpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2016 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/util/conversions.hpp>
|
||||
#include <mapnik/value_types.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
// karma is used by default
|
||||
#define MAPNIK_KARMA_TO_STRING
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#ifdef MAPNIK_KARMA_TO_STRING
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#endif
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#if _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
using namespace boost::spirit;
|
||||
|
||||
// double conversion - here we use sprintf over karma to work
|
||||
// around https://github.com/mapnik/mapnik/issues/1741
|
||||
bool to_string(std::string& s, double val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%g", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef MAPNIK_KARMA_TO_STRING
|
||||
|
||||
bool to_string(std::string& str, int value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
|
||||
#ifdef BIGINT
|
||||
bool to_string(std::string& str, mapnik::value_integer value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool to_string(std::string& str, unsigned value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
|
||||
bool to_string(std::string& str, bool value)
|
||||
{
|
||||
namespace karma = boost::spirit::karma;
|
||||
std::back_insert_iterator<std::string> sink(str);
|
||||
return karma::generate(sink, value);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool to_string(std::string& s, int val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%d", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef BIGINT
|
||||
bool to_string(std::string& s, mapnik::value_integer val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%lld", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool to_string(std::string& s, unsigned val)
|
||||
{
|
||||
s.resize(s.capacity());
|
||||
while (true)
|
||||
{
|
||||
size_t n2 = static_cast<size_t>(snprintf(&s[0], s.size() + 1, "%u", val));
|
||||
if (n2 <= s.size())
|
||||
{
|
||||
s.resize(n2);
|
||||
break;
|
||||
}
|
||||
s.resize(n2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool to_string(std::string& s, bool val)
|
||||
{
|
||||
if (val)
|
||||
s = "true";
|
||||
else
|
||||
s = "false";
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace util
|
||||
}
|
Loading…
Add table
Reference in a new issue