This file is indexed.

/usr/include/mapnik/symbolizer.hpp is in libmapnik-dev 3.0.9+ds-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 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
 *
 *****************************************************************************/

#ifndef MAPNIK_SYMBOLIZER_HPP
#define MAPNIK_SYMBOLIZER_HPP

// mapnik
#include <mapnik/config.hpp>
#include <mapnik/image_scaling.hpp>
#include <mapnik/image_compositing.hpp>
#include <mapnik/simplify.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/path_expression.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/color.hpp>
#include <mapnik/symbolizer_keys.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/symbolizer_base.hpp>
#include <mapnik/symbolizer_enumerations.hpp>
#include <mapnik/text/font_feature_settings.hpp>
#include <mapnik/util/dasharray_parser.hpp>
#include <mapnik/util/variant.hpp>
#include <mapnik/symbolizer_default_values.hpp>
// stl
#include <type_traits>
#include <memory>
#include <vector>
#include <string>
#include <functional>
#include <map>
#include <tuple>

// boost
#include <boost/optional.hpp>

namespace mapnik
{

// symbolizer properties target types
enum class property_types : std::uint8_t
{
    target_bool = 1,
    target_double,
    target_integer,
    target_color,
    target_comp_op,
    target_line_cap,
    target_line_join,
    target_line_rasterizer,
    target_halo_rasterizer,
    target_point_placement,
    target_pattern_alignment,
    target_debug_symbolizer_mode,
    target_marker_placement,
    target_marker_multi_policy,
    target_string,
    target_transform,
    target_placement,
    target_dash_array,
    target_colorizer,
    target_repeat_key,
    target_group_symbolizer_properties,
    target_halo_comp_op,
    target_simplify_algorithm,
    target_markers_placement,
    target_markers_multipolicy,
    target_gamma_method,
    target_text_transform,
    target_horizontal_alignment,
    target_justify_alignment,
    target_vertical_alignment,
    target_upright,
    target_direction,
    target_font_feature_settings
};

template <typename T>
struct evaluate_path_wrapper
{
    using result_type = T;
    template <typename T1, typename T2>
    result_type operator() (T1 const&, T2 const&) const
    {
        return result_type();
    }

};

template <>
struct evaluate_path_wrapper<std::string>
{
    template <typename T1, typename T2>
    std::string operator() (T1 const& expr, T2 const& feature) const
    {
        return mapnik::path_processor_type::evaluate(expr, feature);
    }
};

namespace detail {

template <typename T>
struct enum_traits {};

template <>
struct enum_traits<composite_mode_e>
{
    using result_type = boost::optional<composite_mode_e>;
    static result_type from_string(std::string const& str)
    {
        return comp_op_from_string(str);
    }
};

template <>
struct enum_traits<scaling_method_e>
{
    using result_type = boost::optional<scaling_method_e>;
    static result_type from_string(std::string const& str)
    {
        return scaling_method_from_string(str);
    }
};

template <>
struct enum_traits<simplify_algorithm_e>
{
    using result_type = boost::optional<simplify_algorithm_e>;
    static result_type from_string(std::string const& str)
    {
        return simplify_algorithm_from_string(str);
    }
};

#define ENUM_FROM_STRING( e ) \
template <> struct enum_traits<e> { \
    using result_type = boost::optional<e>; \
    static result_type from_string(std::string const& str) \
    { \
        enumeration<e, e ## _MAX> enum_; \
        try \
        { \
            enum_.from_string(str); \
            return result_type(e(enum_)); \
        } \
        catch (...) \
        { \
            return result_type(); \
        } \
    } \
};\

ENUM_FROM_STRING( line_cap_enum )
ENUM_FROM_STRING( line_join_enum )
ENUM_FROM_STRING( point_placement_enum )
ENUM_FROM_STRING( line_rasterizer_enum )
ENUM_FROM_STRING( marker_placement_enum )
ENUM_FROM_STRING( marker_multi_policy_enum )
ENUM_FROM_STRING( debug_symbolizer_mode_enum )
ENUM_FROM_STRING( pattern_alignment_enum )
ENUM_FROM_STRING( halo_rasterizer_enum )
ENUM_FROM_STRING( label_placement_enum )
ENUM_FROM_STRING( vertical_alignment_enum )
ENUM_FROM_STRING( horizontal_alignment_enum )
ENUM_FROM_STRING( justify_alignment_enum )
ENUM_FROM_STRING( text_transform_enum )
ENUM_FROM_STRING( text_upright_enum )
ENUM_FROM_STRING( direction_enum )
ENUM_FROM_STRING( gamma_method_enum )

// enum
template <typename T, bool is_enum = true>
struct expression_result
{
    using result_type = T;
    static result_type convert(value_type const& val)
    {
        auto result = enum_traits<T>::from_string(val.to_string());
        if (result) return static_cast<result_type>(*result);
        return result_type(0);
    }
};

template <typename T>
struct expression_result<T,false>
{
    using result_type = T;
    static result_type convert(value_type const& val)
    {
        return val.convert<T>();
    }
};


// enum
template <typename T, bool is_enum = true>
struct enumeration_result
{
    using result_type = T;
    static result_type convert(enumeration_wrapper const& e)
    {
        return static_cast<result_type>(e.value);
    }
};

template <typename T>
struct enumeration_result<T,false>
{
    using result_type = T;
    static result_type convert(enumeration_wrapper const&)
    {
        return result_type();// FAIL
    }
};

// enum
template <typename T, bool is_enum = true >
struct put_impl
{
    static void apply(symbolizer_base & sym, keys key, T const& val)
    {
        auto itr = sym.properties.find(key);
        if (itr != sym.properties.end())
        {
            sym.properties[key] = enumeration_wrapper(val);
        }
        else
        {
            sym.properties.emplace(key, enumeration_wrapper(val));
        }
    }
};

template <typename T>
struct put_impl<T, false>
{
    static void apply(symbolizer_base & sym, keys key, T const& val)
    {
        auto itr = sym.properties.find(key);
        if (itr != sym.properties.end())
        {
            sym.properties[key] = val;
        }
        else
        {
            sym.properties.emplace(key, val);
        }
    }
};

}

template <typename T>
struct evaluate_expression_wrapper
{
    using result_type = T;

    template <typename T1, typename T2, typename T3>
    result_type operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
    {
        mapnik::value_type result = util::apply_visitor(mapnik::evaluate<T2,mapnik::value_type,T3>(feature,vars), expr);
        return detail::expression_result<result_type, std::is_enum<result_type>::value>::convert(result);
    }
};

// mapnik::color
template <>
struct evaluate_expression_wrapper<mapnik::color>
{
    template <typename T1, typename T2, typename T3>
    mapnik::color operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
    {
        mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2,mapnik::value_type,T3>(feature,vars), expr);
        if (val.is_null()) return mapnik::color(0,0,0,0); // transparent
        return mapnik::color(val.to_string());
    }
};

// enumeration wrapper
template <>
struct evaluate_expression_wrapper<mapnik::enumeration_wrapper>
{
    template <typename T1, typename T2, typename T3>
    mapnik::enumeration_wrapper operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
    {
        mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2,mapnik::value_type,T3>(feature,vars), expr);
        return mapnik::enumeration_wrapper(val.to_int());
    }
};

template <>
struct evaluate_expression_wrapper<mapnik::dash_array>
{
    template <typename T1, typename T2, typename T3>
    mapnik::dash_array operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
    {
        mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2,mapnik::value_type,T3>(feature,vars), expr);
        if (val.is_null()) return dash_array();
        dash_array dash;
        std::vector<double> buf;
        std::string str = val.to_string();
        if (util::parse_dasharray(str,buf))
        {
            util::add_dashes(buf,dash);
        }
        return dash;
    }
};

// mapnik::font_feature_settings
template <>
struct evaluate_expression_wrapper<mapnik::font_feature_settings>
{
    template <typename T1, typename T2, typename T3>
    mapnik::font_feature_settings operator() (T1 const& expr, T2 const& feature, T3 const& vars) const
    {
        mapnik::value_type val = util::apply_visitor(mapnik::evaluate<T2, mapnik::value_type, T3>(feature, vars), expr);
        if (val.is_null()) return mapnik::font_feature_settings();
        return mapnik::font_feature_settings(val.to_string());
    }
};

template <typename T>
struct extract_value
{
    using result_type = T;

    extract_value(mapnik::feature_impl const& feature,
                  mapnik::attributes const& v)
        : feature_(feature),
          vars_(v) {}

    auto operator() (mapnik::expression_ptr const& expr) const -> result_type
    {
        return evaluate_expression_wrapper<result_type>()(*expr,feature_,vars_);
    }

    auto operator() (mapnik::path_expression_ptr const& expr) const -> result_type
    {
        return evaluate_path_wrapper<result_type>()(*expr, feature_);
    }

    auto operator() (result_type const& val) const -> result_type
    {
        return val;
    }

    auto operator() (mapnik::enumeration_wrapper const& e) const -> result_type
    {
        return detail::enumeration_result<result_type, std::is_enum<result_type>::value>::convert(e);
    }

    template <typename T1>
    auto operator() (T1 const&) const -> result_type
    {
        return result_type();
    }

    mapnik::feature_impl const& feature_;
    mapnik::attributes const& vars_;
};

template <typename T1>
struct extract_raw_value
{
    using result_type = T1;

    auto operator() (result_type const& val) const -> result_type const&
    {
        return val;
    }

    auto operator() (mapnik::enumeration_wrapper const& e) const -> result_type
    {
        return detail::enumeration_result<result_type, std::is_enum<result_type>::value>::convert(e);
    }

    template <typename T2>
    auto operator() (T2 const&) const -> result_type
    {
        return result_type();
    }
};

using property_meta_type = std::tuple<const char*, std::function<std::string(enumeration_wrapper)>, property_types>;
MAPNIK_DECL property_meta_type const& get_meta(mapnik::keys key);
MAPNIK_DECL mapnik::keys get_key(std::string const& name);

template <typename T>
void put(symbolizer_base & sym, keys key, T const& val)
{
    constexpr bool enum_ = std::is_enum<T>::value;
    detail::put_impl<T, enum_ >::apply(sym, key, val);
}

inline bool has_key(symbolizer_base const& sym, keys key)
{
    return (sym.properties.count(key) == 1);
}

template <typename T, keys key>
T get(symbolizer_base const& sym, mapnik::feature_impl const& feature, attributes const& vars)
{
    using const_iterator = symbolizer_base::cont_type::const_iterator;
    const_iterator itr = sym.properties.find(key);
    if (itr != sym.properties.end())
    {
        return util::apply_visitor(extract_value<T>(feature,vars), itr->second);
    }
    return mapnik::symbolizer_default<T,key>::value();
}

template <typename T>
T get(symbolizer_base const& sym, keys key, mapnik::feature_impl const& feature, attributes const& vars, T const& default_value)
{
    using const_iterator = symbolizer_base::cont_type::const_iterator;
    const_iterator itr = sym.properties.find(key);
    if (itr != sym.properties.end())
    {
        return util::apply_visitor(extract_value<T>(feature,vars), itr->second);
    }
    return default_value;
}


template <typename T>
boost::optional<T> get_optional(symbolizer_base const& sym, keys key, mapnik::feature_impl const& feature, attributes const& vars)
{
    using const_iterator = symbolizer_base::cont_type::const_iterator;
    const_iterator itr = sym.properties.find(key);
    if (itr != sym.properties.end())
    {
        return util::apply_visitor(extract_value<T>(feature,vars), itr->second);
    }
    return boost::optional<T>();
}

template <typename T>
T get(symbolizer_base const& sym, keys key)
{
    using const_iterator = symbolizer_base::cont_type::const_iterator;
    const_iterator itr = sym.properties.find(key);
    if (itr != sym.properties.end())
    {
        return util::apply_visitor(extract_raw_value<T>(), itr->second);
    }
    return T();
}


template <typename T>
T get(symbolizer_base const& sym, keys key, T const& default_value)
{
    using const_iterator = symbolizer_base::cont_type::const_iterator;
    const_iterator itr = sym.properties.find(key);
    if (itr != sym.properties.end())
    {
        return util::apply_visitor(extract_raw_value<T>(), itr->second);
    }
    return default_value;
}

template <typename T>
boost::optional<T> get_optional(symbolizer_base const& sym, keys key)
{
    using const_iterator = symbolizer_base::cont_type::const_iterator;
    const_iterator itr = sym.properties.find(key);
    if (itr != sym.properties.end())
    {
        return util::apply_visitor(extract_raw_value<T>(), itr->second);
    }
    return boost::optional<T>();
}

}

#endif // MAPNIK_SYMBOLIZER_HPP