Merge branch 'master' of github.com:mapnik/mapnik

This commit is contained in:
Dane Springmeyer 2013-01-15 11:01:17 -08:00
commit 4bfc9f7cca
5 changed files with 77 additions and 24 deletions

View file

@ -26,38 +26,39 @@
#include <istream>
#include <algorithm>
#include <string>
#include <iostream>
namespace mapnik
{
/** Helper for class bool */
// Helper for class bool
class boolean {
public:
boolean(): b_(false) {}
boolean(bool b) : b_(b) {}
boolean(boolean const& b) : b_(b.b_) {}
boolean()
: b_(false) {}
boolean(bool b)
: b_(b) {}
explicit boolean(boolean const& b)
: b_(b.b_) {}
operator bool() const
{
return b_;
}
boolean & operator = (boolean const& other)
boolean & operator =(boolean const& other)
{
if (this == &other)
return *this;
b_ = other.b_;
return * this;
}
boolean & operator = (bool other)
{
b_ = other;
return * this;
return *this;
}
private:
bool b_;
};
/** Special stream input operator for boolean values */
// Special stream input operator for boolean values
template <typename charT, typename traits>
std::basic_istream<charT, traits> &
operator >> ( std::basic_istream<charT, traits> & s, boolean & b )

View file

@ -135,19 +135,19 @@ protected:
* @endcode
*/
template <class ENUM, int THE_MAX>
template <typename ENUM, int THE_MAX>
class MAPNIK_DECL enumeration {
public:
typedef ENUM native_type;
enumeration()
: value_() {}
: value_() {}
enumeration( ENUM v )
: value_(v) {}
: value_(v) {}
enumeration( const enumeration & other )
: value_(other.value_) {}
enumeration( enumeration const& other )
: value_(other.value_) {}
/** Assignment operator for native enum values. */
void operator=(ENUM v)
@ -156,7 +156,7 @@ public:
}
/** Assignment operator. */
void operator=(const enumeration & other)
void operator=(enumeration const& other)
{
value_ = other.value_;
}
@ -220,7 +220,7 @@ public:
{
from_string( word );
}
catch (const illegal_enum_value &)
catch (illegal_enum_value const&)
{
is.setstate(std::ios::failbit);
}
@ -256,8 +256,8 @@ public:
if (our_strings_[i] == 0 )
{
std::cerr << "### FATAL: Not enough strings for enum "
<< our_name_ << " defined in file '" << filename
<< "' at line " << line_no;
<< our_name_ << " defined in file '" << filename
<< "' at line " << line_no;
}
}
if ( std::string("") != our_strings_[THE_MAX])

View file

@ -32,6 +32,9 @@
namespace mapnik { namespace util {
MAPNIK_DECL bool string2bool(const char * value, bool & result);
MAPNIK_DECL bool string2bool(std::string const& value, bool & result);
MAPNIK_DECL bool string2int(const char * value, int & result);
MAPNIK_DECL bool string2int(std::string const& value, int & result);

View file

@ -60,13 +60,53 @@ BOOST_SPIRIT_AUTO(qi, LONGLONG, qi::long_long)
BOOST_SPIRIT_AUTO(qi, FLOAT, qi::float_)
BOOST_SPIRIT_AUTO(qi, DOUBLE, qi::double_)
bool string2int(const char * value, int & result)
struct bool_symbols : qi::symbols<char,bool>
{
bool_symbols()
{
add("true",true)
("false",false)
("yes",true)
("no",false)
("on",true)
("off",false)
("1",true)
("0",false);
}
};
bool string2bool(const char * value, bool & result)
{
using boost::spirit::qi::no_case;
size_t length = strlen(value);
if (length < 1 || value == NULL)
return false;
const char *iter = value;
const char *end = value + length;
bool r = qi::phrase_parse(iter,end, no_case[bool_symbols()] ,ascii::space,result);
return r && (iter == end);
}
bool string2bool(std::string const& value, bool & result)
{
using boost::spirit::qi::no_case;
if (value.empty())
return false;
std::string::const_iterator str_beg = value.begin();
std::string::const_iterator str_end = value.end();
bool r = qi::phrase_parse(str_beg,str_end,no_case[bool_symbols()],ascii::space,result);
return r && (str_beg == str_end);
}
bool string2int(const char * value, int & result)
{
size_t length = strlen(value);
if (length < 1 || value == NULL)
return false;
const char *iter = value;
const char *end = value + length;
bool r = qi::phrase_parse(iter,end,INTEGER,ascii::space,result);
return r && (iter == end);
}

View file

@ -56,6 +56,15 @@ inline boost::optional<T> fast_cast(xml_tree const& tree, std::string const& val
}
}
template <>
inline boost::optional<mapnik::boolean> fast_cast(xml_tree const& tree, std::string const& value)
{
bool result;
if (mapnik::util::string2bool(value, result))
return boost::optional<mapnik::boolean>(result);
return boost::optional<mapnik::boolean>();
}
template <>
inline boost::optional<int> fast_cast(xml_tree const& tree, std::string const& value)
{
@ -393,7 +402,7 @@ boost::optional<T> xml_node::get_opt_attr(std::string const& name) const
std::map<std::string, xml_attribute>::const_iterator itr = attributes_.find(name);
if (itr == attributes_.end()) return boost::optional<T>();
itr->second.processed = true;
boost::optional<T> result = fast_cast<T>(tree_, itr->second.value);
boost::optional<T> result = fast_cast<T>(tree_, std::string(itr->second.value));
if (!result)
{
throw config_error(std::string("Failed to parse attribute '") +