Skip to content

Commit

Permalink
Merge branch 'master' into spirit-x3
Browse files Browse the repository at this point in the history
  • Loading branch information
artemp committed Feb 11, 2016
2 parents d5c0cfc + fa6376d commit f2c4ec8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
10 changes: 10 additions & 0 deletions include/mapnik/enumeration.hpp
Expand Up @@ -246,6 +246,16 @@ class MAPNIK_DECL enumeration {
static bool our_verified_flag_;
};

/** ostream operator for enumeration
* @relates mapnik::enumeration
*/
template <class ENUM, int THE_MAX>
std::ostream &
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
{
return os << e.as_string();
}

} // end of namespace

/** Helper macro.
Expand Down
15 changes: 4 additions & 11 deletions include/mapnik/gradient.hpp
Expand Up @@ -28,7 +28,6 @@

// mapnik
#include <mapnik/color.hpp>
#include <mapnik/enumeration.hpp>

// stl
#include <vector>
Expand All @@ -39,26 +38,20 @@ namespace mapnik
using stop_pair = std::pair<double, mapnik::color>;
using stop_array = std::vector<stop_pair >;

enum gradient_enum
enum gradient_e
{
NO_GRADIENT,
LINEAR,
RADIAL,
gradient_enum_MAX
RADIAL
};

DEFINE_ENUM( gradient_e, gradient_enum );

enum gradient_unit_enum
enum gradient_unit_e
{
USER_SPACE_ON_USE,
USER_SPACE_ON_USE_BOUNDING_BOX, // used to indicate % age values were specified. This are % of the svg image extent.
OBJECT_BOUNDING_BOX, // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding box and (1,1) is at the bottom/right of the object bounding box)
gradient_unit_enum_MAX
OBJECT_BOUNDING_BOX // (i.e., the abstract coordinate system where (0,0) is at the top/left of the object bounding box and (1,1) is at the bottom/right of the object bounding box)
};

DEFINE_ENUM( gradient_unit_e, gradient_unit_enum );

class MAPNIK_DECL gradient
{
// transform
Expand Down
18 changes: 0 additions & 18 deletions src/gradient.cpp
Expand Up @@ -26,24 +26,6 @@
namespace mapnik
{

static const char * gradient_strings[] = {
"no-gradient",
"linear",
"radial",
""
};

IMPLEMENT_ENUM( gradient_e, gradient_strings )

static const char * gradient_unit_strings[] = {
"user-space-on-use",
"user-space-on-use-bounding-box",
"object-bounding-box",
""
};

IMPLEMENT_ENUM( gradient_unit_e, gradient_unit_strings )

gradient::gradient()
: transform_(),
x1_(0),
Expand Down
4 changes: 2 additions & 2 deletions src/save_map.cpp
Expand Up @@ -104,7 +104,7 @@ void serialize_raster_colorizer(ptree & sym_node,
raster_colorizer dfl;
if (colorizer->get_default_mode() != dfl.get_default_mode() || explicit_defaults)
{
set_attr(col_node, "default-mode", colorizer->get_default_mode());
set_attr(col_node, "default-mode", colorizer->get_default_mode().as_string());
}
if (colorizer->get_default_color() != dfl.get_default_color() || explicit_defaults)
{
Expand Down Expand Up @@ -403,7 +403,7 @@ void serialize_style( ptree & map_node, std::string const& name, feature_type_st
filter_mode_e filter_mode = style.get_filter_mode();
if (filter_mode != dfl.get_filter_mode() || explicit_defaults)
{
set_attr(style_node, "filter-mode", filter_mode);
set_attr(style_node, "filter-mode", filter_mode.as_string());
}

double opacity = style.get_opacity();
Expand Down
36 changes: 36 additions & 0 deletions test/unit/numerics/enumeration.cpp
@@ -0,0 +1,36 @@
#include "catch.hpp"
#include <mapnik/enumeration.hpp>
#include <sstream>

namespace mapnik {

enum _test_enumeration_enum : std::uint8_t
{
TEST_ONE,
TEST_TWO,
_test_enumeration_enum_MAX
};

DEFINE_ENUM( _test_enumeration_e, _test_enumeration_enum );

static const char * _test_enumeration_strings[] = {
"test_one",
"test_two",
""
};

IMPLEMENT_ENUM( _test_enumeration_e, _test_enumeration_strings )

}

TEST_CASE("enumeration") {

mapnik::_test_enumeration_e e(mapnik::TEST_ONE);
CHECK( e.as_string() == "test_one" );
// test the << operator, which calls `as_string` internally
// this is not used in mapnik, but kept for back compat
std::stringstream s;
s << e;
CHECK( s.str() == "test_one" );

}

0 comments on commit f2c4ec8

Please sign in to comment.