Merge branch 'master' of https://github.com/mapnik/mapnik into feature/cmake-static

This commit is contained in:
Mathis Logemann 2022-02-02 17:15:55 +01:00
commit 8a1f2579e9
819 changed files with 37753 additions and 37964 deletions

94
.clang-format Normal file
View file

@ -0,0 +1,94 @@
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
# AlwaysBreakAfterReturnType:
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BitFieldColonSpacing: After
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: false # see AllowShortEnumsOnASingleLine
AfterFunction: true # see AllowShortFunctionsOnASingleLine
AfterNamespace: false
AfterStruct: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: AfterComma
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: false
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DeriveLineEnding: true
EmptyLineAfterAccessModifier: Leave
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentPPDirectives: None
IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
# PackConstructorInitializers: CurrentLine # only clang-format > 14
PointerAlignment: Left
#QualifierAlignment: Left # only clang-format > 14
ReferenceAlignment: Left
ReflowComments: true
SortIncludes: Never
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeInheritanceColon: true
Standard: c++14
BinPackParameters: false
BreakBeforeInheritanceComma: false
IncludeCategories:
# Headers in <> without extension.
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
Priority: 1
# Headers in <> from specific external libraries.
- Regex: '<(boost)\/'
Priority: 2
# Headers in <> from specific external libraries.
- Regex: '<(mapnik)\/'
Priority: 3
# Headers in <> with extension.
- Regex: '<([A-Za-z0-9.\Q/-_\E])+>'
Priority: 4
# Headers in "" with extension.
- Regex: '"([A-Za-z0-9.\Q/-_\E])+"'
Priority: 5

76
.github/workflows/build_test.yml vendored Normal file
View file

@ -0,0 +1,76 @@
name: Build and Test
on:
push:
branches-ignore:
- "no-ci-*"
pull_request:
branches:
- "**"
jobs:
windows:
name: Windows memory mapped
uses: mapnik/mapnik/.github/workflows/windows.yml@master
with:
VCPKG_SHA: 2e34a79a814551424d9b1a981b3b110e0a8fbdfd
NUGET_REGISTRY: https://nuget.pkg.github.com/mapnik/index.json
NUGET_USERNAME: mapnik
USE_MEMORY_MAPPED_FILE: 'ON'
secrets:
NUGET_REGISTRY_PAT: ${{ secrets.VCPKG_CACHE_PAT }}
windows-mmf-off:
name: Windows file based
uses: mapnik/mapnik/.github/workflows/windows.yml@master
with:
VCPKG_SHA: 2e34a79a814551424d9b1a981b3b110e0a8fbdfd
NUGET_REGISTRY: https://nuget.pkg.github.com/mapnik/index.json
NUGET_USERNAME: mapnik
USE_MEMORY_MAPPED_FILE: 'OFF'
secrets:
NUGET_REGISTRY_PAT: ${{ secrets.VCPKG_CACHE_PAT }}
ubuntu:
name: Linux memory mapped
uses: mapnik/mapnik/.github/workflows/ubuntu.yml@master
with:
VCPKG_SHA: 2e34a79a814551424d9b1a981b3b110e0a8fbdfd
NUGET_REGISTRY: https://nuget.pkg.github.com/mapnik/index.json
NUGET_USERNAME: mapnik
USE_MEMORY_MAPPED_FILE: 'ON'
secrets:
NUGET_REGISTRY_PAT: ${{ secrets.VCPKG_CACHE_PAT }}
ubuntu-mmf-off:
name: Linux file based
uses: mapnik/mapnik/.github/workflows/ubuntu.yml@master
with:
VCPKG_SHA: 2e34a79a814551424d9b1a981b3b110e0a8fbdfd
NUGET_REGISTRY: https://nuget.pkg.github.com/mapnik/index.json
NUGET_USERNAME: mapnik
USE_MEMORY_MAPPED_FILE: 'OFF'
secrets:
NUGET_REGISTRY_PAT: ${{ secrets.VCPKG_CACHE_PAT }}
macos:
name: MacOS memory mapped
uses: mapnik/mapnik/.github/workflows/macos.yml@master
with:
VCPKG_SHA: 2e34a79a814551424d9b1a981b3b110e0a8fbdfd
NUGET_REGISTRY: https://nuget.pkg.github.com/mapnik/index.json
NUGET_USERNAME: mapnik
USE_MEMORY_MAPPED_FILE: 'ON'
secrets:
NUGET_REGISTRY_PAT: ${{ secrets.VCPKG_CACHE_PAT }}
macos-mmf-off:
name: MacOS file based
uses: mapnik/mapnik/.github/workflows/macos.yml@master
with:
VCPKG_SHA: 2e34a79a814551424d9b1a981b3b110e0a8fbdfd
NUGET_REGISTRY: https://nuget.pkg.github.com/mapnik/index.json
NUGET_USERNAME: mapnik
USE_MEMORY_MAPPED_FILE: 'OFF'
secrets:
NUGET_REGISTRY_PAT: ${{ secrets.VCPKG_CACHE_PAT }}

125
.github/workflows/macos.yml vendored Normal file
View file

@ -0,0 +1,125 @@
name: MacOS
on:
workflow_call:
inputs:
VCPKG_SHA:
required: true
type: string
NUGET_REGISTRY:
required: true
type: string
NUGET_USERNAME:
required: true
type: string
USE_MEMORY_MAPPED_FILE:
required: true
type: string
secrets:
NUGET_REGISTRY_PAT:
required: true
env:
VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite"
VCPKG_NUGET_REPOSITORY: https://github.com/mapnik/mapnik/vcpkg-cache.git
UPDATE: 1
preset: macos-ci
mono: mono
jobs:
build:
runs-on: macos-latest
steps:
- name: Install required system packages
run: |
brew install automake ninja lcov
- name: checkout mapnik
uses: actions/checkout@v2
with:
submodules: "recursive"
- name: checkout vcpkg
uses: actions/checkout@v2
with:
repository: "microsoft/vcpkg"
ref: ${{ inputs.VCPKG_SHA }}
path: vcpkg
- name: "Setup vcpkg"
shell: bash
run: ./vcpkg/bootstrap-vcpkg.sh
- name: "Setup NuGet Credentials"
shell: "bash"
run: >
${{ env.mono }} `./vcpkg/vcpkg fetch nuget | tail -n 1`
sources add
-source "${{ inputs.NUGET_REGISTRY }}"
-storepasswordincleartext
-name "GitHub"
-username "${{ inputs.NUGET_USERNAME }}"
-password "${{ secrets.NUGET_REGISTRY_PAT }}"
- name: "Setup NuGet apikey"
shell: "bash"
run: >
${{ env.mono }} `./vcpkg/vcpkg fetch nuget | tail -n 1`
setapikey "${{ secrets.NUGET_REGISTRY_PAT }}" -Source "${{ inputs.NUGET_REGISTRY }}"
- name: Configure CMake
run: cmake -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake -DUSE_MEMORY_MAPPED_FILE=${{ inputs.USE_MEMORY_MAPPED_FILE }} --preset=${{ env.preset }}
- name: Build
run: cmake --build --preset ${{ env.preset }}
- name: Test
run: ctest --preset ${{ env.preset }}
- name: Test visuals
continue-on-error: true
working-directory: build/${{ env.preset }}/out
env:
PROJ_LIB: ${{ github.workspace }}/build/${{ env.preset }}/vcpkg_installed/x64-osx/share/proj4
run: ./mapnik-test-visual -j $(sysctl -n hw.logicalcpu) --output-dir ./visual-test-result
- name: Pack visual test results
working-directory: build/${{ env.preset }}/out
run: tar cfvz visual-test-results.tar.gz ./visual-test-result
- name: Run Benchmark
working-directory: build/${{ env.preset }}/out
env:
PROJ_LIB: ${{ github.workspace }}/build/${{ env.preset }}/vcpkg_installed/x64-osx/share/proj4
run: ./run_benchmarks
- name: Coverage
working-directory: build/${{ env.preset }}
run: |
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' '*/vcpkg_installed/*' '/.cache/*' '*/test/*' --output-file coverage.info
lcov --list coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: build/${{ env.preset }}/coverage.info
- name: Package
if: failure()
run: cmake --build --preset ${{ env.preset }} --target package
- name: Upload mapnik build artifact
uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ env.preset }}-mmio-${{ inputs.USE_MEMORY_MAPPED_FILE }}
path: build/${{ env.preset }}/mapnik-*.tar.gz
retention-days: 2
- name: Upload visual test results
uses: actions/upload-artifact@v2
with:
name: ${{ env.preset }}-visual-tests-mmio-${{ inputs.USE_MEMORY_MAPPED_FILE }}
path: build/${{ env.preset }}/out/visual-test-results.tar.gz
retention-days: 2

141
.github/workflows/ubuntu.yml vendored Normal file
View file

@ -0,0 +1,141 @@
name: Ubuntu
on:
workflow_call:
inputs:
VCPKG_SHA:
required: true
type: string
NUGET_REGISTRY:
required: true
type: string
NUGET_USERNAME:
required: true
type: string
USE_MEMORY_MAPPED_FILE:
required: true
type: string
secrets:
NUGET_REGISTRY_PAT:
required: true
env:
VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite"
VCPKG_NUGET_REPOSITORY: https://github.com/mapnik/mapnik/vcpkg-cache.git
UPDATE: 1
preset: linux-ci
mono: mono
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis
env:
POSTGRES_PASSWORD: password
POSTGRES_DB: mapnik-tmp-postgis-test-db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Install required system packages
shell: "bash"
run: |
sudo apt-get install -y gperf libxxf86vm-dev ninja-build postgresql-client lcov
- name: checkout mapnik
uses: actions/checkout@v2
with:
submodules: "recursive"
- name: checkout vcpkg
uses: actions/checkout@v2
with:
repository: "microsoft/vcpkg"
ref: ${{ inputs.VCPKG_SHA }}
path: vcpkg
- name: "Setup vcpkg"
shell: bash
run: ./vcpkg/bootstrap-vcpkg.sh
- name: "Setup NuGet Credentials"
shell: "bash"
run: >
${{ env.mono }} `./vcpkg/vcpkg fetch nuget | tail -n 1`
sources add
-source "${{ inputs.NUGET_REGISTRY }}"
-storepasswordincleartext
-name "GitHub"
-username "${{ inputs.NUGET_USERNAME }}"
-password "${{ secrets.NUGET_REGISTRY_PAT }}"
- name: "Setup NuGet apikey"
shell: "bash"
run: >
${{ env.mono }} `./vcpkg/vcpkg fetch nuget | tail -n 1`
setapikey "${{ secrets.NUGET_REGISTRY_PAT }}" -Source "${{ inputs.NUGET_REGISTRY }}"
- name: Configure CMake
run: cmake -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake -DUSE_MEMORY_MAPPED_FILE=${{ inputs.USE_MEMORY_MAPPED_FILE }} --preset=${{ env.preset }}
- name: Build
run: cmake --build --preset ${{ env.preset }}
- name: Test
run: ctest --preset ${{ env.preset }}
- name: Test visuals
continue-on-error: true
working-directory: build/${{ env.preset }}/out
env:
PROJ_LIB: ${{ github.workspace }}/build/${{ env.preset }}/vcpkg_installed/x64-linux/share/proj4
run: ./mapnik-test-visual -j $(nproc) --output-dir ./visual-test-result
- name: Pack visual test results
working-directory: build/${{ env.preset }}/out
run: tar cfvz visual-test-results.tar.gz ./visual-test-result
- name: Run Benchmarks
working-directory: build/${{ env.preset }}/out
env:
PROJ_LIB: ${{ github.workspace }}/build/${{ env.preset }}/vcpkg_installed/x64-linux/share/proj4
run: ./run_benchmarks
- name: Coverage
working-directory: build/${{ env.preset }}
run: |
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' '*/vcpkg_installed/*' '/.cache/*' '*/test/*' --output-file coverage.info
lcov --list coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: build/${{ env.preset }}/coverage.info
- name: Package
if: failure()
run: cmake --build --preset ${{ env.preset }} --target package
- name: Upload mapnik build artifact
uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ env.preset }}-artifact-mmio-${{ inputs.USE_MEMORY_MAPPED_FILE }}
path: build/${{ env.preset }}/mapnik-*.tar.gz
retention-days: 2
- name: Upload visual test results
uses: actions/upload-artifact@v2
with:
name: ${{ env.preset }}-visual-tests-mmio-${{ inputs.USE_MEMORY_MAPPED_FILE }}
path: build/${{ env.preset }}/out/visual-test-results.tar.gz
retention-days: 2

114
.github/workflows/windows.yml vendored Normal file
View file

@ -0,0 +1,114 @@
name: Windows
on:
workflow_call:
inputs:
VCPKG_SHA:
required: true
type: string
NUGET_REGISTRY:
required: true
type: string
NUGET_USERNAME:
required: true
type: string
USE_MEMORY_MAPPED_FILE:
required: true
type: string
secrets:
NUGET_REGISTRY_PAT:
required: true
env:
VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite"
VCPKG_NUGET_REPOSITORY: https://github.com/mapnik/vcpkg-cache.git
UPDATE: 1
preset: windows-ci
jobs:
build:
runs-on: windows-latest
steps:
- name: Install required system packages
run: |
choco install ninja OpenCppCoverage
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- uses: ilammy/msvc-dev-cmd@v1
- name: checkout mapnik
uses: actions/checkout@v2
with:
submodules: "recursive"
- name: checkout vcpkg
uses: actions/checkout@v2
with:
repository: "microsoft/vcpkg"
ref: ${{ inputs.VCPKG_SHA }}
path: vcpkg
- name: "Setup vcpkg"
run: ./vcpkg/bootstrap-vcpkg.bat
- name: "Setup NuGet Credentials"
shell: "bash"
run: >
`./vcpkg/vcpkg fetch nuget | tail -n 1`
sources add
-source "${{ inputs.NUGET_REGISTRY }}"
-storepasswordincleartext
-name "GitHub"
-username "${{ inputs.NUGET_USERNAME }}"
-password "${{ secrets.NUGET_REGISTRY_PAT }}"
- name: "Setup NuGet apikey"
shell: "bash"
run: >
`./vcpkg/vcpkg fetch nuget | tail -n 1`
setapikey "${{ secrets.NUGET_REGISTRY_PAT }}" -Source "${{ inputs.NUGET_REGISTRY }}"
- name: Configure CMake
run: cmake -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DUSE_MEMORY_MAPPED_FILE=${{ inputs.USE_MEMORY_MAPPED_FILE }} --preset ${{env.preset}}
- name: Build
run: cmake --build --preset ${{env.preset}}
- name: Test
run: OpenCppCoverage --modules *libmapnik* --modules mapnik*.exe --modules *.input --sources ${{ github.workspace }} --export_type binary --cover_children -- ctest --preset ${{env.preset}}
- name: Test visuals
shell: pwsh
continue-on-error: true
working-directory: build/${{ env.preset }}/out
env:
PROJ_LIB: ${{ github.workspace }}/build/${{ env.preset }}/vcpkg_installed/x64-windows/share/proj4
run: OpenCppCoverage --modules *libmapnik* --modules mapnik*.exe --modules *.input --sources ${{ github.workspace }} --export_type binary --input_coverage=${{ github.workspace }}/ctest.cov --cover_children -- .\mapnik-test-visual.exe -j (Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfLogicalProcessors --output-dir ./visual-test-result
- name: Pack visual test results
working-directory: build/${{ env.preset }}/out
run: tar cfvz visual-test-results.tar.gz ./visual-test-result
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: build/${{ env.preset }}/out/mapnik-test-visual.cov
- name: Package
if: failure()
run: cmake --build --preset ${{env.preset}} --target package
- uses: actions/upload-artifact@v2
if: failure()
with:
name: ${{ env.preset }}-artifact-mmio-${{ inputs.USE_MEMORY_MAPPED_FILE }}
path: build/*-ci/mapnik-*.tar.gz
retention-days: 2
- name: Upload visual test results
uses: actions/upload-artifact@v2
with:
name: ${{ env.preset }}-visual-tests-mmio-${{ inputs.USE_MEMORY_MAPPED_FILE }}
path: build/${{ env.preset }}/out/visual-test-results.tar.gz
retention-days: 2

View file

@ -173,6 +173,60 @@
"windows-default", "windows-default",
"release-build" "release-build"
] ]
},
{
"name": "ci-options",
"hidden": true,
"cacheVariables": {
"BUILD_TESTING": "ON",
"BUILD_DEMO_VIEWER": "OFF"
}
},
{
"name": "windows-ci",
"description": "used by the ci pipeline",
"inherits": [
"windows-release",
"ci-options"
],
"cacheVariables": {
"INSTALL_DEPENDENCIES": "ON",
"ADDITIONAL_LIBARIES_PATHS": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-windows/bin"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-windows/share/proj4"
}
},
{
"name": "linux-ci",
"description": "used by the ci pipeline",
"inherits": [
"release-with-debug-build",
"use-gcc",
"ci-options"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "--coverage"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-linux/share/proj4"
}
},
{
"name": "macos-ci",
"description": "used by the ci pipeline",
"inherits": [
"use-ninja",
"release-with-debug-build",
"default-build-dir",
"ci-options"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-fprofile-arcs -ftest-coverage"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/${presetName}/vcpkg_installed/x64-osx/share/proj4"
}
} }
], ],
"buildPresets": [ "buildPresets": [
@ -199,6 +253,18 @@
{ {
"name": "linux-gcc-release", "name": "linux-gcc-release",
"configurePreset": "linux-gcc-release" "configurePreset": "linux-gcc-release"
},
{
"name": "windows-ci",
"configurePreset": "windows-ci"
},
{
"name": "linux-ci",
"configurePreset": "linux-ci"
},
{
"name": "macos-ci",
"configurePreset": "macos-ci"
} }
], ],
"testPresets": [ "testPresets": [
@ -212,6 +278,27 @@
"noTestsAction": "error", "noTestsAction": "error",
"stopOnFailure": false "stopOnFailure": false
} }
},
{
"name": "windows-ci",
"configurePreset": "windows-ci",
"inherits": [
"test-default"
]
},
{
"name": "linux-ci",
"configurePreset": "linux-ci",
"inherits": [
"test-default"
]
},
{
"name": "macos-ci",
"configurePreset": "macos-ci",
"inherits": [
"test-default"
]
} }
] ]
} }

View file

@ -34,24 +34,16 @@ protected:
mapnik::parameters params_; mapnik::parameters params_;
std::size_t threads_; std::size_t threads_;
std::size_t iterations_; std::size_t iterations_;
public: public:
test_case(mapnik::parameters const& params) test_case(mapnik::parameters const& params)
: params_(params), : params_(params)
threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0))), , threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0)))
iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0))) , iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0)))
{} {}
std::size_t threads() const std::size_t threads() const { return threads_; }
{ std::size_t iterations() const { return iterations_; }
return threads_; mapnik::parameters const& params() const { return params_; }
}
std::size_t iterations() const
{
return iterations_;
}
mapnik::parameters const& params() const
{
return params_;
}
virtual bool validate() const = 0; virtual bool validate() const = 0;
virtual bool operator()() const = 0; virtual bool operator()() const = 0;
}; };
@ -61,19 +53,23 @@ public:
// or negated index of an ill-formed option argument // or negated index of an ill-formed option argument
inline int parse_args(int argc, char** argv, mapnik::parameters& params) inline int parse_args(int argc, char** argv, mapnik::parameters& params)
{ {
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i)
{
const char* opt = argv[i]; const char* opt = argv[i];
if (opt[0] != '-') { if (opt[0] != '-')
{
// non-option argument, return its index // non-option argument, return its index
return i; return i;
} }
if (opt[1] != '-') { if (opt[1] != '-')
{
// we only accept --long-options, but instead of throwing, // we only accept --long-options, but instead of throwing,
// just issue a warning and let the caller decide what to do // just issue a warning and let the caller decide what to do
std::clog << argv[0] << ": invalid option '" << opt << "'\n"; std::clog << argv[0] << ": invalid option '" << opt << "'\n";
return -i; // negative means ill-formed option #i return -i; // negative means ill-formed option #i
} }
if (opt[2] == '\0') { if (opt[2] == '\0')
{
// option-list terminator '--' // option-list terminator '--'
return i + 1; return i + 1;
} }
@ -81,15 +77,18 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params)
// take option name without the leading '--' // take option name without the leading '--'
std::string key(opt + 2); std::string key(opt + 2);
size_t eq = key.find('='); size_t eq = key.find('=');
if (eq != std::string::npos) { if (eq != std::string::npos)
{
// one-argument form '--foo=bar' // one-argument form '--foo=bar'
params[key.substr(0, eq)] = key.substr(eq + 1); params[key.substr(0, eq)] = key.substr(eq + 1);
} }
else if (i + 1 < argc) { else if (i + 1 < argc)
{
// two-argument form '--foo' 'bar' // two-argument form '--foo' 'bar'
params[key] = std::string(argv[++i]); params[key] = std::string(argv[++i]);
} }
else { else
{
// missing second argument // missing second argument
std::clog << argv[0] << ": missing option '" << opt << "' value\n"; std::clog << argv[0] << ": missing option '" << opt << "' value\n";
return -i; // negative means ill-formed option #i return -i; // negative means ill-formed option #i
@ -100,7 +99,8 @@ inline int parse_args(int argc, char** argv, mapnik::parameters & params)
inline void handle_common_args(mapnik::parameters const& params) inline void handle_common_args(mapnik::parameters const& params)
{ {
if (auto severity = params.get<std::string>("log")) { if (auto severity = params.get<std::string>("log"))
{
if (*severity == "debug") if (*severity == "debug")
mapnik::logger::set_severity(mapnik::logger::debug); mapnik::logger::set_severity(mapnik::logger::debug);
else if (*severity == "warn") else if (*severity == "warn")
@ -110,8 +110,7 @@ inline void handle_common_args(mapnik::parameters const& params)
else if (*severity == "none") else if (*severity == "none")
mapnik::logger::set_severity(mapnik::logger::none); mapnik::logger::set_severity(mapnik::logger::none);
else else
std::clog << "ignoring option --log='" << *severity std::clog << "ignoring option --log='" << *severity << "' (allowed values are: debug, warn, error, none)\n";
<< "' (allowed values are: debug, warn, error, none)\n";
} }
} }
@ -133,14 +132,13 @@ inline int handle_args(int argc, char** argv, mapnik::parameters & params)
auto result = run(test_runner, name); \ auto result = run(test_runner, name); \
testing::run_cleanup(); \ testing::run_cleanup(); \
return result; \ return result; \
} \ } catch (std::exception const& ex) \
catch (std::exception const& ex) \
{ \ { \
std::clog << ex.what() << "\n"; \ std::clog << ex.what() << "\n"; \
testing::run_cleanup(); \ testing::run_cleanup(); \
return -1; \ return -1; \
} \ } \
} \ }
struct big_number_fmt struct big_number_fmt
{ {
@ -149,7 +147,9 @@ struct big_number_fmt
const char* u; const char* u;
big_number_fmt(int width, double value, int base = 1000) big_number_fmt(int width, double value, int base = 1000)
: w(width), v(value), u("") : w(width)
, v(value)
, u("")
{ {
static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0"; static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0";
u = suffixes; u = suffixes;
@ -196,8 +196,7 @@ int run(T const& test_runner, std::string const& name)
std::mutex mtx_ready; std::mutex mtx_ready;
std::unique_lock<std::mutex> lock_ready(mtx_ready); std::unique_lock<std::mutex> lock_ready(mtx_ready);
auto stub = [&](T const& test_copy) auto stub = [&](T const& test_copy) {
{
// workers will wait on this mutex until the main thread // workers will wait on this mutex until the main thread
// constructs all of them and starts measuring time // constructs all of them and starts measuring time
std::unique_lock<std::mutex> my_lock(mtx_ready); std::unique_lock<std::mutex> my_lock(mtx_ready);
@ -228,7 +227,8 @@ int run(T const& test_runner, std::string const& name)
else else
{ {
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
do { do
{
test_runner(); test_runner();
elapsed = std::chrono::high_resolution_clock::now() - start; elapsed = std::chrono::high_resolution_clock::now() - start;
total_iters += num_iters; total_iters += num_iters;
@ -243,21 +243,27 @@ int run(T const& test_runner, std::string const& name)
std::clog << std::left << std::setw(43) << name; std::clog << std::left << std::setw(43) << name;
std::clog << std::resetiosflags(std::ios::adjustfield); std::clog << std::resetiosflags(std::ios::adjustfield);
if (num_threads > 0) { if (num_threads > 0)
std::clog << ' ' << std::setw(3) << num_threads {
<< " worker" << (num_threads > 1 ? "s" : " "); std::clog << ' ' << std::setw(3) << num_threads << " worker" << (num_threads > 1 ? "s" : " ");
} }
else { else
{
std::clog << " main thread"; std::clog << " main thread";
} }
std::snprintf(msg, sizeof(msg), std::snprintf(msg,
sizeof(msg),
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n", " %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
itersf.w, itersf.v, itersf.u, dur_total, itersf.w,
ips.w, ips.v, ips.u); itersf.v,
itersf.u,
dur_total,
ips.w,
ips.v,
ips.u);
std::clog << msg; std::clog << msg;
return 0; return 0;
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::clog << "test runner did not complete: " << ex.what() << "\n"; std::clog << "test runner did not complete: " << ex.what() << "\n";
return 4; return 4;
@ -272,10 +278,7 @@ struct sequencer
benchmark::handle_args(argc, argv, params_); benchmark::handle_args(argc, argv, params_);
} }
int done() const int done() const { return exit_code_; }
{
return exit_code_;
}
template<typename Test, typename... Args> template<typename Test, typename... Args>
sequencer& run(std::string const& name, Args&&... args) sequencer& run(std::string const& name, Args&&... args)
@ -292,6 +295,6 @@ protected:
int exit_code_; int exit_code_;
}; };
} } // namespace benchmark
#endif // MAPNIK_BENCH_FRAMEWORK_HPP #endif // MAPNIK_BENCH_FRAMEWORK_HPP

View file

@ -5,7 +5,6 @@
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp> #include <mapnik/image_reader.hpp>
namespace benchmark { namespace benchmark {
bool compare_images(std::string const& src_fn, std::string const& dest_fn) bool compare_images(std::string const& src_fn, std::string const& dest_fn)
@ -31,6 +30,6 @@ namespace benchmark {
return compare(dest, src, 0, true) == 0; return compare(dest, src, 0, true) == 0;
} }
} } // namespace benchmark
#endif // MAPNIK_COMPARE_IMAGES_HPP #endif // MAPNIK_COMPARE_IMAGES_HPP

View file

@ -9,7 +9,10 @@ struct bench_func : benchmark::test_case
T const value_; T const value_;
bench_func(mapnik::parameters const& params, T (*func)(T), T value) bench_func(mapnik::parameters const& params, T (*func)(T), T value)
: test_case(params), func_(func), value_(value) {} : test_case(params)
, func_(func)
, value_(value)
{}
bool validate() const { return true; } bool validate() const { return true; }
@ -23,8 +26,7 @@ struct bench_func : benchmark::test_case
} }
}; };
#define BENCH_FUNC1(func, value) \ #define BENCH_FUNC1(func, value) run<bench_func<double>>(#func "(" #value ")", func, value)
run<bench_func<double>>(#func "(" #value ")", func, value)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {

View file

@ -14,15 +14,19 @@
#define FULL_ZERO_CHECK #define FULL_ZERO_CHECK
inline void ensure_zero(uint8_t * data, uint32_t size) { inline void ensure_zero(uint8_t* data, uint32_t size)
{
#ifdef FULL_ZERO_CHECK #ifdef FULL_ZERO_CHECK
for (std::size_t i=0;i<size;++i) { for (std::size_t i = 0; i < size; ++i)
if (data[i] != 0) { {
if (data[i] != 0)
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
} }
#else #else
if (data[0] != 0) { if (data[0] != 0)
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
#endif #endif
@ -34,16 +38,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1(mapnik::parameters const& params) test1(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
// NOTE: sizeof(uint8_t) == 1 // NOTE: sizeof(uint8_t) == 1
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_); uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
memcpy(data, &array_[0], size_); memcpy(data, &array_[0], size_);
@ -60,16 +63,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1b(mapnik::parameters const& params) test1b(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
// NOTE: sizeof(uint8_t) == 1 // NOTE: sizeof(uint8_t) == 1
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_); uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_);
memset(data, 0, sizeof(uint8_t) * size_); memset(data, 0, sizeof(uint8_t) * size_);
@ -86,16 +88,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1c(mapnik::parameters const& params) test1c(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_)); uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
std::fill(data, data + size_, 0); std::fill(data, data + size_, 0);
ensure_zero(data, size_); ensure_zero(data, size_);
@ -105,23 +106,21 @@ public:
} }
}; };
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_)); uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_));
memcpy(data, &array_[0], size_); memcpy(data, &array_[0], size_);
ensure_zero(data, size_); ensure_zero(data, size_);
@ -137,16 +136,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3(mapnik::parameters const& params) test3(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::vector<uint8_t> data(size_); std::vector<uint8_t> data(size_);
ensure_zero(&data[0], data.size()); ensure_zero(&data[0], data.size());
} }
@ -154,23 +152,21 @@ public:
} }
}; };
class test3b : public benchmark::test_case class test3b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3b(mapnik::parameters const& params) test3b(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::vector<uint8_t> data(0); std::vector<uint8_t> data(0);
data.resize(size_, 0); data.resize(size_, 0);
ensure_zero(&data[0], data.size()); ensure_zero(&data[0], data.size());
@ -179,23 +175,21 @@ public:
} }
}; };
class test3c : public benchmark::test_case class test3c : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3c(mapnik::parameters const& params) test3c(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::vector<uint8_t> data(0); std::vector<uint8_t> data(0);
data.assign(size_, 0); data.assign(size_, 0);
ensure_zero(&data[0], data.size()); ensure_zero(&data[0], data.size());
@ -210,19 +204,20 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3d(mapnik::parameters const& params) test3d(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::deque<uint8_t> data(size_); std::deque<uint8_t> data(size_);
for (std::size_t i=0;i<size_;++i) { for (std::size_t i = 0; i < size_; ++i)
if (data[i] != 0) { {
if (data[i] != 0)
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
} }
@ -237,16 +232,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test4(mapnik::parameters const& params) test4(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
uint8_t* data = (uint8_t*)calloc(size_, sizeof(uint8_t)); uint8_t* data = (uint8_t*)calloc(size_, sizeof(uint8_t));
ensure_zero(data, size_); ensure_zero(data, size_);
free(data); free(data);
@ -261,16 +255,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test5(mapnik::parameters const& params) test5(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::string data(array_.begin(), array_.end()); std::string data(array_.begin(), array_.end());
ensure_zero((uint8_t*)&data[0], size_); ensure_zero((uint8_t*)&data[0], size_);
} }
@ -284,16 +277,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<char> array_; std::vector<char> array_;
test5b(mapnik::parameters const& params) test5b(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::string data(&array_[0], array_.size()); std::string data(&array_[0], array_.size());
ensure_zero((uint8_t*)&data[0], size_); ensure_zero((uint8_t*)&data[0], size_);
} }
@ -312,16 +304,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test6(mapnik::parameters const& params) test6(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::valarray<uint8_t> data(static_cast<uint8_t>(0), static_cast<size_t>(size_)); std::valarray<uint8_t> data(static_cast<uint8_t>(0), static_cast<size_t>(size_));
ensure_zero(&data[0], size_); ensure_zero(&data[0], size_);
} }
@ -339,16 +330,15 @@ public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test7(mapnik::parameters const& params) test7(mapnik::parameters const& params)
: test_case(params), : test_case(params)
size_(*params.get<mapnik::value_integer>("size",256*256)), , size_(*params.get<mapnik::value_integer>("size", 256 * 256))
array_(size_,0) { } , array_(size_, 0)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
boost::container::static_vector<uint8_t, 256 * 256> data(size_, 0); boost::container::static_vector<uint8_t, 256 * 256> data(size_, 0);
ensure_zero(&data[0], size_); ensure_zero(&data[0], size_);
} }

View file

@ -7,10 +7,12 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string expr_; std::string expr_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {} , expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))")
{}
bool validate() const bool validate() const
{ {
mapnik::expression_ptr expr = mapnik::parse_expression(expr_); mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
@ -24,14 +26,14 @@ public:
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
mapnik::expression_ptr expr = mapnik::parse_expression(expr_); mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;

View file

@ -6,7 +6,8 @@ class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
{}
bool validate() const bool validate() const
{ {
std::size_t count = 0; std::size_t count = 0;
@ -22,7 +23,8 @@ public:
font_cache, font_cache,
mapnik::freetype_engine::get_mapping(), mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache()); mapnik::freetype_engine::get_cache());
if (f) ++count; if (f)
++count;
} }
return count == expected_count; return count == expected_count;
} }
@ -43,9 +45,11 @@ public:
font_cache, font_cache,
mapnik::freetype_engine::get_mapping(), mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache()); mapnik::freetype_engine::get_cache());
if (f) ++count; if (f)
++count;
} }
if (count != expected_count) { if (count != expected_count)
{
std::clog << "warning: face creation not working as expected\n"; std::clog << "warning: face creation not working as expected\n";
} }
} }
@ -58,7 +62,8 @@ int main(int argc, char** argv)
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc, argv, params);
bool success = mapnik::freetype_engine::register_fonts("./fonts", true); bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
if (!success) { if (!success)
{
std::clog << "warning, did not register any new fonts!\n"; std::clog << "warning, did not register any new fonts!\n";
return -1; return -1;
} }
@ -66,4 +71,3 @@ int main(int argc, char** argv)
test test_runner(params); test test_runner(params);
return run(test_runner, (boost::format("font_engine: creating %ld faces") % (face_count)).str()); return run(test_runner, (boost::format("font_engine: creating %ld faces") % (face_count)).str());
} }

View file

@ -7,11 +7,9 @@ class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
bool validate() const {}
{ bool validate() const { return mapnik::freetype_engine::register_fonts("./fonts", true); }
return mapnik::freetype_engine::register_fonts("./fonts", true);
}
bool operator()() const bool operator()() const
{ {
unsigned long count = 0; unsigned long count = 0;

View file

@ -1,15 +1,13 @@
#include "bench_framework.hpp" #include "bench_framework.hpp"
#include "../plugins/input/csv/csv_getline.hpp" #include "../plugins/input/csv/csv_getline.hpp"
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
std::string line_data_; std::string line_data_;
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
line_data_("this is one line\nand this is a second line\nand a third line") , line_data_("this is one line\nand this is a second line\nand a third line")
{ {
boost::optional<std::string> line_data = params.get<std::string>("line"); boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data) if (line_data)
@ -32,7 +30,8 @@ public:
} }
else else
{ {
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n"; std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line ("
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
} }
return true; return true;
} }
@ -50,14 +49,13 @@ public:
} }
}; };
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
public: public:
std::string line_data_; std::string line_data_;
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params), : test_case(params)
line_data_("this is one line\nand this is a second line\nand a third line") , line_data_("this is one line\nand this is a second line\nand a third line")
{ {
boost::optional<std::string> line_data = params.get<std::string>("line"); boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data) if (line_data)
@ -81,7 +79,8 @@ public:
} }
else else
{ {
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n"; std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line ("
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
} }
return true; return true;
} }
@ -115,8 +114,7 @@ int main(int argc, char** argv)
test2 test_runner2(params); test2 test_runner2(params);
return_value = return_value | run(test_runner2, "csv_utils::getline_csv"); return_value = return_value | run(test_runner2, "csv_utils::getline_csv");
} }
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::clog << ex.what() << "\n"; std::clog << ex.what() << "\n";
return -1; return -1;

View file

@ -4,11 +4,11 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::vector<std::string> images_; std::vector<std::string> images_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
images_{ , images_{"./test/data/images/dummy.jpg",
"./test/data/images/dummy.jpg",
"./test/data/images/dummy.jpeg", "./test/data/images/dummy.jpeg",
"./test/data/images/dummy.png", "./test/data/images/dummy.png",
"./test/data/images/dummy.tif", "./test/data/images/dummy.tif",
@ -19,16 +19,14 @@ public:
"./test/data/svg/place-of-worship-24.svg", "./test/data/svg/place-of-worship-24.svg",
"./test/data/svg/point_sm.svg", "./test/data/svg/point_sm.svg",
"./test/data/svg/point.svg", "./test/data/svg/point.svg",
"./test/data/svg/airfield-12.svg" "./test/data/svg/airfield-12.svg"}
} {} {}
bool validate() const bool validate() const { return true; }
{
return true;
}
bool operator()() const bool operator()() const
{ {
unsigned count = 0; unsigned count = 0;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
for (auto filename : images_) for (auto filename : images_)
{ {
auto marker = mapnik::marker_cache::instance().find(filename, true); auto marker = mapnik::marker_cache::instance().find(filename, true);

View file

@ -16,12 +16,10 @@ class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
{}
bool validate() const bool validate() const { return true; }
{
return true;
}
bool operator()() const bool operator()() const
{ {
mapnik::Map m(256, 256, "epsg:3857"); mapnik::Map m(256, 256, "epsg:3857");

View file

@ -9,23 +9,25 @@ class test_static : public benchmark::test_case
{ {
double step_; double step_;
std::uint8_t start_; std::uint8_t start_;
public: public:
test_static(mapnik::parameters const& params) test_static(mapnik::parameters const& params)
: test_case(params), : test_case(params)
step_(STEP_NUM), , step_(STEP_NUM)
start_(START_NUM) {} , start_(START_NUM)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
double value_ = 0.0; double value_ = 0.0;
std::uint8_t x; std::uint8_t x;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
double c = static_cast<double>(start_) * value_; double c = static_cast<double>(start_) * value_;
if (c >= 256.0) c = 255.0; if (c >= 256.0)
if (c < 0.0) c = 0.0; c = 255.0;
if (c < 0.0)
c = 0.0;
x = static_cast<std::uint8_t>(c); x = static_cast<std::uint8_t>(c);
value_ += step_; value_ += step_;
} }
@ -33,35 +35,34 @@ public:
} }
}; };
using boost::numeric::positive_overflow;
using boost::numeric::negative_overflow; using boost::numeric::negative_overflow;
using boost::numeric::positive_overflow;
class test_numeric : public benchmark::test_case class test_numeric : public benchmark::test_case
{ {
double step_; double step_;
std::uint8_t start_; std::uint8_t start_;
public: public:
test_numeric(mapnik::parameters const& params) test_numeric(mapnik::parameters const& params)
: test_case(params), : test_case(params)
step_(STEP_NUM), , step_(STEP_NUM)
start_(START_NUM) {} , start_(START_NUM)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
double value_ = 0.0; double value_ = 0.0;
std::uint8_t x; std::uint8_t x;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
try { {
try
{
x = boost::numeric_cast<std::uint8_t>(start_ * value_); x = boost::numeric_cast<std::uint8_t>(start_ * value_);
} } catch (negative_overflow&)
catch(negative_overflow&)
{ {
x = std::numeric_limits<std::uint8_t>::min(); x = std::numeric_limits<std::uint8_t>::min();
} } catch (positive_overflow&)
catch(positive_overflow&)
{ {
x = std::numeric_limits<std::uint8_t>::max(); x = std::numeric_limits<std::uint8_t>::max();
} }
@ -73,8 +74,5 @@ public:
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv).run<test_static>("static_cast").run<test_numeric>("numeric_cast").done();
.run<test_static>("static_cast")
.run<test_numeric>("numeric_cast")
.done();
} }

View file

@ -14,31 +14,36 @@ struct fake_path
cont_type::iterator itr_; cont_type::iterator itr_;
fake_path(std::initializer_list<double> l) fake_path(std::initializer_list<double> l)
: fake_path(l.begin(), l.size()) { : fake_path(l.begin(), l.size())
} {}
fake_path(std::vector<double> const& v) fake_path(std::vector<double> const& v)
: fake_path(v.begin(), v.size()) { : fake_path(v.begin(), v.size())
} {}
template<typename Itr> template<typename Itr>
fake_path(Itr itr, size_t sz) { fake_path(Itr itr, size_t sz)
{
size_t num_coords = sz >> 1; size_t num_coords = sz >> 1;
vertices_.reserve(num_coords); vertices_.reserve(num_coords);
for (size_t i = 0; i < num_coords; ++i) { for (size_t i = 0; i < num_coords; ++i)
{
double x = *itr++; double x = *itr++;
double y = *itr++; double y = *itr++;
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO; unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
vertices_.push_back(std::make_tuple(x, y, cmd)); vertices_.push_back(std::make_tuple(x, y, cmd));
if (i == num_coords - 1) cmd = mapnik::SEG_END; if (i == num_coords - 1)
cmd = mapnik::SEG_END;
vertices_.push_back(std::make_tuple(x, y, cmd)); vertices_.push_back(std::make_tuple(x, y, cmd));
} }
itr_ = vertices_.begin(); itr_ = vertices_.begin();
} }
unsigned vertex(double *x, double *y) { unsigned vertex(double* x, double* y)
if (itr_ == vertices_.end()) { {
if (itr_ == vertices_.end())
{
return mapnik::SEG_END; return mapnik::SEG_END;
} }
*x = std::get<0>(*itr_); *x = std::get<0>(*itr_);
@ -48,20 +53,16 @@ struct fake_path
return cmd; return cmd;
} }
void rewind(unsigned) { void rewind(unsigned) { itr_ = vertices_.begin(); }
itr_ = vertices_.begin();
}
}; };
class test_offset : public benchmark::test_case class test_offset : public benchmark::test_case
{ {
public: public:
test_offset(mapnik::parameters const& params) test_offset(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
std::vector<double> path; std::vector<double> path;
@ -74,7 +75,8 @@ public:
path.push_back(0); path.push_back(0);
} }
fake_path fpath(path); fake_path fpath(path);
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
mapnik::offset_converter<fake_path> off_path(fpath); mapnik::offset_converter<fake_path> off_path(fpath);
off_path.set_offset(10); off_path.set_offset(10);
unsigned cmd; unsigned cmd;
@ -88,7 +90,6 @@ public:
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;

View file

@ -4,18 +4,18 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
mapnik::image_rgba8 im_; mapnik::image_rgba8 im_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
im_(256,256) {} , im_(256, 256)
bool validate() const {}
{ bool validate() const { return true; }
return true;
}
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
out.clear(); out.clear();
out = mapnik::save_to_string(im_, "png8:m=h:z=1"); out = mapnik::save_to_string(im_, "png8:m=h:z=1");
} }

View file

@ -4,9 +4,11 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::shared_ptr<mapnik::image_rgba8> im_; std::shared_ptr<mapnik::image_rgba8> im_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) { : test_case(params)
{
std::string filename("./benchmark/data/multicolor.png"); std::string filename("./benchmark/data/multicolor.png");
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename, "png")); std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename, "png"));
if (!reader.get()) if (!reader.get())
@ -26,7 +28,8 @@ public:
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
out.clear(); out.clear();
out = mapnik::save_to_string(*im_, "png8:m=h:z=1"); out = mapnik::save_to_string(*im_, "png8:m=h:z=1");
} }

View file

@ -39,7 +39,8 @@ void render(mapnik::geometry::multi_polygon<double> const& geom,
mapnik::box2d<double> const& extent, mapnik::box2d<double> const& extent,
std::string const& name) std::string const& name)
{ {
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry::polygon_vertex_adapter<double>>; using path_type =
mapnik::transform_path_adapter<mapnik::view_transform, mapnik::geometry::polygon_vertex_adapter<double>>;
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>; using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
using renderer = agg::renderer_scanline_aa_solid<ren_base>; using renderer = agg::renderer_scanline_aa_solid<ren_base>;
mapnik::image_rgba8 im(256, 256); mapnik::image_rgba8 im(256, 256);
@ -70,15 +71,15 @@ class test1 : public benchmark::test_case
std::string wkt_in_; std::string wkt_in_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public: public:
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>; using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
test1(mapnik::parameters const& params, test1(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
std::string const& wkt_in, : test_case(params)
mapnik::box2d<double> const& extent) , wkt_in_(wkt_in)
: test_case(params), , extent_(extent)
wkt_in_(wkt_in), , expected_("./benchmark/data/polygon_clipping_agg")
extent_(extent), {}
expected_("./benchmark/data/polygon_clipping_agg") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
@ -99,14 +100,8 @@ public:
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box( clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
extent_.minx(),
extent_.miny(),
extent_.maxx(),
extent_.maxy());
clipped.rewind(0); clipped.rewind(0);
mapnik::geometry::polygon<double> poly2; mapnik::geometry::polygon<double> poly2;
@ -118,7 +113,8 @@ public:
{ {
if (cmd == mapnik::SEG_MOVETO) if (cmd == mapnik::SEG_MOVETO)
{ {
x0 = x; y0 = y; x0 = x;
y0 = y;
} }
if (cmd == mapnik::SEG_CLOSE) if (cmd == mapnik::SEG_CLOSE)
@ -135,7 +131,8 @@ public:
{ {
if (cmd == mapnik::SEG_MOVETO) if (cmd == mapnik::SEG_MOVETO)
{ {
x0 = x; y0 = y; x0 = x;
y0 = y;
} }
else if (cmd == mapnik::SEG_CLOSE) else if (cmd == mapnik::SEG_CLOSE)
{ {
@ -184,23 +181,22 @@ public:
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box( clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy());
extent_.minx(),
extent_.miny(),
extent_.maxx(),
extent_.maxy());
unsigned cmd; unsigned cmd;
double x, y; double x, y;
// NOTE: this rewind is critical otherwise // NOTE: this rewind is critical otherwise
// agg_conv_adapter_vpgen will give garbage // agg_conv_adapter_vpgen will give garbage
// values for the first vertex // values for the first vertex
clipped.rewind(0); clipped.rewind(0);
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) { while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END)
{
count++; count++;
} }
unsigned expected_count = 30; unsigned expected_count = 30;
if (count != expected_count) { if (count != expected_count)
std::clog << "test1: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; {
std::clog << "test1: clipping failed: processed " << count << " verticies but expected "
<< expected_count << "\n";
valid = false; valid = false;
} }
} }
@ -208,20 +204,19 @@ public:
} }
}; };
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
std::string wkt_in_; std::string wkt_in_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public: public:
test3(mapnik::parameters const& params, test3(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent)
std::string const& wkt_in, : test_case(params)
mapnik::box2d<double> const& extent) , wkt_in_(wkt_in)
: test_case(params), , extent_(extent)
wkt_in_(wkt_in), , expected_("./benchmark/data/polygon_clipping_boost")
extent_(extent), {}
expected_("./benchmark/data/polygon_clipping_boost") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
@ -308,12 +303,15 @@ public:
mapnik::geometry::polygon_vertex_adapter<double> va(_geom); mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
unsigned cmd; unsigned cmd;
double x, y; double x, y;
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) { while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END)
{
++count; ++count;
} }
unsigned expected_count = 29; unsigned expected_count = 29;
if (count != expected_count) { if (count != expected_count)
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; {
std::clog << "test3: clipping failed: processed " << count << " verticies but expected "
<< expected_count << "\n";
valid = false; valid = false;
} }
} }
@ -500,8 +498,8 @@ public:
} }
unsigned expected_count = 29; unsigned expected_count = 29;
if (count != expected_count) { if (count != expected_count) {
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n"; std::clog << "test3: clipping failed: processed " << count << " verticies but expected " <<
valid = false; expected_count << "\n"; valid = false;
} }
} }
} }
@ -516,10 +514,13 @@ int main(int argc, char** argv)
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc, argv, params);
// polygon/rect clipping // polygon/rect clipping
// IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190)) // IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134,
// RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) // 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343
// OUT (expected) // 287, 249 334, 229 191, 313 190)) RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) OUT (expected)
// POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190)) // POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631
// 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181
// 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249
// 334, 229 191, 313 190))
#if 0 #if 0
mapnik::box2d<double> clipping_box(181,106,631,470); mapnik::box2d<double> clipping_box(181,106,631,470);
std::string filename_("./benchmark/data/polygon.wkt"); std::string filename_("./benchmark/data/polygon.wkt");

View file

@ -8,13 +8,12 @@ class test : public benchmark::test_case
{ {
std::string xml_; std::string xml_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
public: public:
test(mapnik::parameters const& params, test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d<double> const& extent)
std::string const& xml, : test_case(params)
mapnik::box2d<double> const& extent) , xml_(xml)
: test_case(params), , extent_(extent)
xml_(xml),
extent_(extent)
{} {}
bool validate() const bool validate() const
{ {
@ -42,7 +41,6 @@ public:
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::parameters params; mapnik::parameters params;

View file

@ -10,6 +10,7 @@ class test : public benchmark::test_case
mapnik::box2d<double> from_; mapnik::box2d<double> from_;
mapnik::box2d<double> to_; mapnik::box2d<double> to_;
bool defer_proj_init_; bool defer_proj_init_;
public: public:
test(mapnik::parameters const& params, test(mapnik::parameters const& params,
std::string const& src, std::string const& src,
@ -17,24 +18,23 @@ public:
mapnik::box2d<double> const& from, mapnik::box2d<double> const& from,
mapnik::box2d<double> const& to, mapnik::box2d<double> const& to,
bool defer_proj) bool defer_proj)
: test_case(params), : test_case(params)
src_(src), , src_(src)
dest_(dest), , dest_(dest)
from_(from), , from_(from)
to_(to), , to_(to)
defer_proj_init_(defer_proj) {} , defer_proj_init_(defer_proj)
{}
bool validate() const bool validate() const
{ {
mapnik::projection src(src_, defer_proj_init_); mapnik::projection src(src_, defer_proj_init_);
mapnik::projection dest(dest_, defer_proj_init_); mapnik::projection dest(dest_, defer_proj_init_);
mapnik::proj_transform tr(src, dest); mapnik::proj_transform tr(src, dest);
mapnik::box2d<double> bbox = from_; mapnik::box2d<double> bbox = from_;
if (!tr.forward(bbox)) return false; if (!tr.forward(bbox))
return ((std::fabs(bbox.minx() - to_.minx()) < .5) && return false;
(std::fabs(bbox.maxx() - to_.maxx()) < .5) && return ((std::fabs(bbox.minx() - to_.minx()) < .5) && (std::fabs(bbox.maxx() - to_.maxx()) < .5) &&
(std::fabs(bbox.miny() - to_.miny()) < .5) && (std::fabs(bbox.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5));
(std::fabs(bbox.maxy() - to_.maxy()) < .5)
);
} }
bool operator()() const bool operator()() const
{ {
@ -48,7 +48,8 @@ public:
for (int k = -85; k < 85; k = k + 5) for (int k = -85; k < 85; k = k + 5)
{ {
mapnik::box2d<double> box(j, k, j, k); mapnik::box2d<double> box(j, k, j, k);
if (!tr.forward(box)) throw std::runtime_error("could not transform coords"); if (!tr.forward(box))
throw std::runtime_error("could not transform coords");
} }
} }
} }
@ -64,7 +65,8 @@ int main(int argc, char** argv)
std::string from_str("epsg:4326"); std::string from_str("epsg:4326");
std::string to_str("epsg:3857"); std::string to_str("epsg:3857");
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"); std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m "
"+nadgrids=@null +wktext +no_defs +over");
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true) .run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true)
.run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true) .run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true)

View file

@ -8,12 +8,10 @@ class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
{}
bool validate() const bool validate() const { return true; }
{
return true;
}
bool operator()() const bool operator()() const
{ {

View file

@ -15,15 +15,16 @@ class test : public benchmark::test_case
mapnik::value_integer height_; mapnik::value_integer height_;
double scale_factor_; double scale_factor_;
std::string preview_; std::string preview_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
xml_(), , xml_()
extent_(), , extent_()
width_(*params.get<mapnik::value_integer>("width",256)), , width_(*params.get<mapnik::value_integer>("width", 256))
height_(*params.get<mapnik::value_integer>("height",256)), , height_(*params.get<mapnik::value_integer>("height", 256))
scale_factor_(*params.get<mapnik::value_double>("scale_factor",1.0)), , scale_factor_(*params.get<mapnik::value_double>("scale_factor", 1.0))
preview_(*params.get<std::string>("preview","")) , preview_(*params.get<std::string>("preview", ""))
{ {
boost::optional<std::string> map = params.get<std::string>("map"); boost::optional<std::string> map = params.get<std::string>("map");
if (!map) if (!map)
@ -43,21 +44,24 @@ public:
{ {
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg"); throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
}*/ }*/
} }
bool validate() const bool validate() const
{ {
mapnik::Map m(width_, height_); mapnik::Map m(width_, height_);
mapnik::load_map(m, xml_, true); mapnik::load_map(m, xml_, true);
if (extent_.valid()) { if (extent_.valid())
{
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
} else { }
else
{
m.zoom_all(); m.zoom_all();
} }
mapnik::image_rgba8 im(m.width(), m.height()); mapnik::image_rgba8 im(m.width(), m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_);
ren.apply(); ren.apply();
if (!preview_.empty()) { if (!preview_.empty())
{
std::clog << "preview available at " << preview_ << "\n"; std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im, preview_); mapnik::save_to_file(im, preview_);
} }
@ -65,14 +69,18 @@ public:
} }
bool operator()() const bool operator()() const
{ {
if (!preview_.empty()) { if (!preview_.empty())
{
return false; return false;
} }
mapnik::Map m(width_, height_); mapnik::Map m(width_, height_);
mapnik::load_map(m, xml_); mapnik::load_map(m, xml_);
if (extent_.valid()) { if (extent_.valid())
{
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
} else { }
else
{
m.zoom_all(); m.zoom_all();
} }
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i = 0; i < iterations_; ++i)
@ -85,7 +93,6 @@ public:
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int return_value = 0; int return_value = 0;
@ -105,8 +112,7 @@ int main(int argc, char** argv)
test test_runner(params); test test_runner(params);
return_value = run(test_runner, *name); return_value = run(test_runner, *name);
} }
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::clog << ex.what() << "\n"; std::clog << ex.what() << "\n";
return -1; return -1;

View file

@ -12,7 +12,8 @@
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <stdexcept> #include <stdexcept>
template <typename Renderer> void process_layers(Renderer & ren, template<typename Renderer>
void process_layers(Renderer& ren,
mapnik::request const& m_req, mapnik::request const& m_req,
mapnik::projection const& map_proj, mapnik::projection const& map_proj,
std::vector<mapnik::layer> const& layers, std::vector<mapnik::layer> const& layers,
@ -50,17 +51,18 @@ class test : public benchmark::test_case
double scale_factor_; double scale_factor_;
std::string preview_; std::string preview_;
mutable mapnik::image_rgba8 im_; mutable mapnik::image_rgba8 im_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
xml_(), , xml_()
extent_(), , extent_()
width_(*params.get<mapnik::value_integer>("width",256)), , width_(*params.get<mapnik::value_integer>("width", 256))
height_(*params.get<mapnik::value_integer>("height",256)), , height_(*params.get<mapnik::value_integer>("height", 256))
m_(new mapnik::Map(width_,height_)), , m_(new mapnik::Map(width_, height_))
scale_factor_(*params.get<mapnik::value_double>("scale_factor",2.0)), , scale_factor_(*params.get<mapnik::value_double>("scale_factor", 2.0))
preview_(*params.get<std::string>("preview","")), , preview_(*params.get<std::string>("preview", ""))
im_(m_->width(),m_->height()) , im_(m_->width(), m_->height())
{ {
boost::optional<std::string> map = params.get<std::string>("map"); boost::optional<std::string> map = params.get<std::string>("map");
if (!map) if (!map)
@ -98,7 +100,8 @@ public:
std::vector<mapnik::layer> const& layers = m_->layers(); std::vector<mapnik::layer> const& layers = m_->layers();
process_layers(ren, m_req, map_proj, layers, scale_denom); process_layers(ren, m_req, map_proj, layers, scale_denom);
ren.end_map_processing(*m_); ren.end_map_processing(*m_);
if (!preview_.empty()) { if (!preview_.empty())
{
std::clog << "preview available at " << preview_ << "\n"; std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im_, preview_); mapnik::save_to_file(im_, preview_);
} }
@ -107,7 +110,8 @@ public:
bool operator()() const bool operator()() const
{ {
if (!preview_.empty()) { if (!preview_.empty())
{
return false; return false;
} }
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i = 0; i < iterations_; ++i)
@ -133,16 +137,17 @@ public:
const unsigned int* row_to = dest.get_row(y); const unsigned int* row_to = dest.get_row(y);
for (unsigned int x = 0; x < width_; ++x) for (unsigned int x = 0; x < width_; ++x)
{ {
if (row_from[x] != row_to[x]) diff = true; if (row_from[x] != row_to[x])
diff = true;
} }
} }
if (diff) throw std::runtime_error("images differ"); if (diff)
throw std::runtime_error("images differ");
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int return_value = 0; int return_value = 0;
@ -162,8 +167,7 @@ int main(int argc, char** argv)
test test_runner(params); test test_runner(params);
return_value = run(test_runner, *name); return_value = run(test_runner, *name);
} }
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::clog << ex.what() << "\n"; std::clog << ex.what() << "\n";
return -1; return -1;

View file

@ -4,21 +4,25 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_("true") {} , value_("true")
{}
bool validate() const bool validate() const
{ {
bool result = false; bool result = false;
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);
if (!result) return result; if (!result)
return result;
mapnik::util::string2bool(value_, result); mapnik::util::string2bool(value_, result);
return (result == true); return (result == true);
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
bool result = false; bool result = false;
mapnik::util::string2bool(value_, result); mapnik::util::string2bool(value_, result);
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result);

View file

@ -4,23 +4,30 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_("1.23456789") {} , value_("1.23456789")
{}
bool validate() const bool validate() const
{ {
double result = 0; double result = 0;
if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false; if (!mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result))
if (result != 1.23456789) return false; return false;
if (result != 1.23456789)
return false;
result = 0; result = 0;
if (!mapnik::util::string2double(value_,result)) return false; if (!mapnik::util::string2double(value_, result))
if (result != 1.23456789) return false; return false;
if (result != 1.23456789)
return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
double result = 0; double result = 0;
mapnik::util::string2double(value_, result); mapnik::util::string2double(value_, result);
mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result);

View file

@ -4,23 +4,30 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_("123456789") {} , value_("123456789")
{}
bool validate() const bool validate() const
{ {
mapnik::value_integer result = 0; mapnik::value_integer result = 0;
if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false; if (!mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result))
if (result != 123456789) return false; return false;
if (result != 123456789)
return false;
result = 0; result = 0;
if (!mapnik::util::string2int(value_,result)) return false; if (!mapnik::util::string2int(value_, result))
if (result != 123456789) return false; return false;
if (result != 123456789)
return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
mapnik::value_integer result = 0; mapnik::value_integer result = 0;
mapnik::util::string2int(value_, result); mapnik::util::string2int(value_, result);
mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result);

View file

@ -4,10 +4,12 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
double value_; double value_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_(-0.1234) {} , value_(-0.1234)
{}
bool validate() const bool validate() const
{ {
std::string s; std::string s;
@ -17,7 +19,8 @@ public:
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
out.clear(); out.clear();
mapnik::util::to_string(out, value_); mapnik::util::to_string(out, value_);
} }

View file

@ -4,10 +4,12 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
double value_; double value_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
value_(-0.1234) {} , value_(-0.1234)
{}
bool validate() const bool validate() const
{ {
std::ostringstream s; std::ostringstream s;
@ -17,7 +19,8 @@ public:
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
std::ostringstream s; std::ostringstream s;
s << value_; s << value_;
out = s.str(); out = s.str();

View file

@ -13,26 +13,28 @@ using mapnik::util::from_u8string;
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params), : test_case(params)
utf8_(from_u8string(u8"שלום")) {} , utf8_(from_u8string(u8"שלום"))
{}
bool validate() const bool validate() const
{ {
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv; std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
std::u32string utf32 = utf32conv.from_bytes(utf8_); std::u32string utf32 = utf32conv.from_bytes(utf8_);
if (utf32.size() != 4) return false; if (utf32.size() != 4)
if (utf32[0] != 0x5e9 && return false;
utf32[1] != 0x5dc && if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
utf32[2] != 0x5d5 && return false;
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
std::u32string utf32; std::u32string utf32;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv; std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
utf32 = utf32conv.from_bytes(utf8_); utf32 = utf32conv.from_bytes(utf8_);
} }
return true; return true;
@ -44,24 +46,26 @@ public:
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public: public:
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params), : test_case(params)
utf8_(from_u8string(u8"שלום")) {} , utf8_(from_u8string(u8"שלום"))
{}
bool validate() const bool validate() const
{ {
std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
if (utf32.size() != 4) return false; if (utf32.size() != 4)
if (utf32[0] != 0x5e9 && return false;
utf32[1] != 0x5dc && if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
utf32[2] != 0x5d5 && return false;
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
std::u32string utf32; std::u32string utf32;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
} }
return true; return true;
@ -71,27 +75,29 @@ public:
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public: public:
test3(mapnik::parameters const& params) test3(mapnik::parameters const& params)
: test_case(params), : test_case(params)
utf8_(from_u8string(u8"שלום")) {} , utf8_(from_u8string(u8"שלום"))
{}
bool validate() const bool validate() const
{ {
mapnik::transcoder tr_("utf-8"); mapnik::transcoder tr_("utf-8");
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size()); mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size());
// std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); // std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
if (utf32.length() != 4) return false; if (utf32.length() != 4)
if (utf32[0] != 0x5e9 && return false;
utf32[1] != 0x5dc && if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd)
utf32[2] != 0x5d5 && return false;
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
mapnik::transcoder tr_("utf-8"); mapnik::transcoder tr_("utf-8");
mapnik::value_unicode_string utf32; mapnik::value_unicode_string utf32;
for (std::size_t i=0;i<iterations_;++i) { for (std::size_t i = 0; i < iterations_; ++i)
{
utf32 = tr_.transcode(utf8_.data(), utf8_.size()); utf32 = tr_.transcode(utf8_.data(), utf8_.size());
} }
return true; return true;

View file

@ -4,14 +4,10 @@ class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) {} : test_case(params)
bool validate() const {}
{ bool validate() const { return true; }
return true; void operator()() const {}
}
void operator()() const
{
}
}; };
BENCHMARK(test, "test name") BENCHMARK(test, "test name")

16
cmake/clang-format.cmake Normal file
View file

@ -0,0 +1,16 @@
function(format_dir dir)
file(GLOB_RECURSE sources
"${dir}/*.cpp"
"${dir}/*.hpp"
)
execute_process(COMMAND clang-format -style=file -i ${sources})
endfunction()
format_dir(benchmark)
format_dir(demo)
format_dir(include)
format_dir(plugins)
format_dir(src)
format_dir(test)
format_dir(utils)

View file

@ -45,14 +45,16 @@
#include <iostream> #include <iostream>
int main(int, char**) int main(int, char**)
{ {
using namespace mapnik; using namespace mapnik;
const std::string srs_lcc="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"; const std::string srs_lcc =
const std::string srs_merc="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over"; "+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs";
const std::string srs_merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 "
"+units=m +nadgrids=@null +wktext +no_defs +over";
try { try
{
std::cout << " running demo ... \n"; std::cout << " running demo ... \n";
datasource_cache::instance().register_datasources("plugins/input/"); datasource_cache::instance().register_datasources("plugins/input/");
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf"); freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
@ -215,7 +217,8 @@ int main ( int, char** )
placement_finder->defaults.format_defaults.fill = color(0, 0, 0); placement_finder->defaults.format_defaults.fill = color(0, 0, 0);
placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200); placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200);
placement_finder->defaults.format_defaults.halo_radius = 1.0; placement_finder->defaults.format_defaults.halo_radius = 1.0;
placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]"))); placement_finder->defaults.set_format_tree(
std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder); put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
r.append(std::move(text_sym)); r.append(std::move(text_sym));
} }
@ -342,8 +345,7 @@ int main ( int, char** )
but instead let's build up a surface for more flexibility but instead let's build up a surface for more flexibility
*/ */
cairo_surface_ptr image_surface( cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m.width(), m.height()),
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
cairo_surface_closer()); cairo_surface_closer());
double scale_factor = 1.0; double scale_factor = 1.0;
cairo_ptr image_context(create_context(image_surface)); cairo_ptr image_context(create_context(image_surface));
@ -353,7 +355,8 @@ int main ( int, char** )
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png"); cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
// but we can also benefit from quantization by converting // but we can also benefit from quantization by converting
// to a mapnik image object and then saving that // to a mapnik image object and then saving that
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface)); mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface),
cairo_image_surface_get_height(&*image_surface));
cairo_image_to_rgba8(im_data, image_surface); cairo_image_to_rgba8(im_data, image_surface);
save_to_file(im_data, "cairo-demo256.png", "png8"); save_to_file(im_data, "cairo-demo256.png", "png8");
cairo_surface_finish(&*image_surface); cairo_surface_finish(&*image_surface);
@ -367,13 +370,11 @@ int main ( int, char** )
#endif #endif
// save map definition (data + style) // save map definition (data + style)
save_map(m, "map.xml"); save_map(m, "map.xml");
} } catch (std::exception const& ex)
catch ( std::exception const& ex )
{ {
std::cerr << "### std::exception: " << ex.what() << std::endl; std::cerr << "### std::exception: " << ex.what() << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} } catch (...)
catch ( ... )
{ {
std::cerr << "### Unknown exception." << std::endl; std::cerr << "### Unknown exception." << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;

View file

@ -17,10 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "about_dialog.hpp" #include "about_dialog.hpp"
about_dialog::about_dialog(QWidget* parent) about_dialog::about_dialog(QWidget* parent)
: QDialog(parent) : QDialog(parent)
{ {

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#if !defined ABOUT_DIALOG_HPP #if !defined ABOUT_DIALOG_HPP
#define ABOUT_DIALOG_HPP #define ABOUT_DIALOG_HPP
@ -30,9 +28,9 @@ class about_dialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
about_dialog(QWidget* parent = 0); about_dialog(QWidget* parent = 0);
private: private:
Ui::Dialog ui; Ui::Dialog ui;
}; };
#endif // ABOUT_DIALOG_HPP #endif // ABOUT_DIALOG_HPP

View file

@ -17,10 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "info_dialog.hpp" #include "info_dialog.hpp"
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent) info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
: QDialog(parent) : QDialog(parent)
{ {

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef INFO_DIALOG_HPP #ifndef INFO_DIALOG_HPP
#define INFO_DIALOG_HPP #define INFO_DIALOG_HPP
@ -30,9 +28,9 @@ class info_dialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0); info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0);
private: private:
Ui::InfoDialog ui; Ui::InfoDialog ui;
}; };
#endif // INFO_DIALOG_HPP #endif // INFO_DIALOG_HPP

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "layer_info_dialog.hpp" #include "layer_info_dialog.hpp"
// mapnik // mapnik
@ -26,7 +25,6 @@
#include <mapnik/params_impl.hpp> #include <mapnik/params_impl.hpp>
#include <mapnik/layer.hpp> #include <mapnik/layer.hpp>
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent) layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
: QDialog(parent) : QDialog(parent)
{ {

View file

@ -17,16 +17,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef LAYER_INFO_DIALOG_HPP #ifndef LAYER_INFO_DIALOG_HPP
#define LAYER_INFO_DIALOG_HPP #define LAYER_INFO_DIALOG_HPP
#include "ui_layer_info.h" #include "ui_layer_info.h"
#include <QDialog> #include <QDialog>
namespace mapnik namespace mapnik {
{
class layer; class layer;
} }
@ -36,9 +33,9 @@ class layer_info_dialog : public QDialog
public: public:
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0); layer_info_dialog(mapnik::layer& l, QWidget* parent = 0);
Ui::LayerInfoDialog& getUI(); Ui::LayerInfoDialog& getUI();
private: private:
Ui::LayerInfoDialog ui; Ui::LayerInfoDialog ui;
}; };
#endif // LAYER_INFO_DIALOG_HPP #endif // LAYER_INFO_DIALOG_HPP

View file

@ -17,17 +17,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <QtGui> #include <QtGui>
#include "layerdelegate.hpp" #include "layerdelegate.hpp"
LayerDelegate::LayerDelegate(QObject* parent) LayerDelegate::LayerDelegate(QObject* parent)
: QAbstractItemDelegate(parent) : QAbstractItemDelegate(parent)
{ {}
}
void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, void LayerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
const QModelIndex &index) const
{ {
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(QPen(QColor(255, 0, 0), 1)); painter->setPen(QPen(QColor(255, 0, 0), 1));
@ -37,18 +34,15 @@ void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
else else
painter->setBrush(QBrush(QColor(255, 0, 0, 64))); painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
painter->drawRoundedRect(option.rect, 4, 4); painter->drawRoundedRect(option.rect, 4, 4);
if (option.state & QStyle::State_Selected) if (option.state & QStyle::State_Selected)
painter->setBrush(option.palette.highlightedText()); painter->setBrush(option.palette.highlightedText());
else else
painter->setBrush(QBrush(QColor(255, 120, 0, 127))); painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
} }
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem & /* option */, QSize LayerDelegate::sizeHint(const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const
const QModelIndex & /* index */) const
{ {
return QSize(120, 24); return QSize(120, 24);
} }

View file

@ -35,10 +35,8 @@ class LayerDelegate : public QAbstractItemDelegate
public: public:
LayerDelegate(QObject* parent = 0); LayerDelegate(QObject* parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
}; };
#endif // LAYER_DELEGATE_HPP #endif // LAYER_DELEGATE_HPP

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "layerlistmodel.hpp" #include "layerlistmodel.hpp"
#include <QIcon> #include <QIcon>
#include <QBrush> #include <QBrush>
@ -27,12 +25,14 @@
using mapnik::Map; using mapnik::Map;
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent) LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent)
: QAbstractListModel(parent), : QAbstractListModel(parent)
map_(map) {} , map_(map)
{}
int LayerListModel::rowCount(QModelIndex const&) const int LayerListModel::rowCount(QModelIndex const&) const
{ {
if (map_) return map_->layers().size(); if (map_)
return map_->layers().size();
return 0; return 0;
} }
@ -76,8 +76,7 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
} }
} }
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, int role) const
int role) const
{ {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
@ -88,10 +87,10 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
return QString("TODO Row %1").arg(section); return QString("TODO Row %1").arg(section);
} }
bool LayerListModel::setData(const QModelIndex &index, bool LayerListModel::setData(const QModelIndex& index, const QVariant& value, int role)
const QVariant &value, int role)
{ {
if (!map_) return false; if (!map_)
return false;
if (index.isValid() && role == Qt::CheckStateRole) if (index.isValid() && role == Qt::CheckStateRole)
{ {

View file

@ -17,8 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef LAYER_LIST_MODEL_HPP #ifndef LAYER_LIST_MODEL_HPP
#define LAYER_LIST_MODEL_HPP #define LAYER_LIST_MODEL_HPP
@ -37,10 +35,8 @@ class LayerListModel : public QAbstractListModel
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0); LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0);
int rowCount(const QModelIndex& parent = QModelIndex()) const; int rowCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const; QVariant data(const QModelIndex& index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
int role = Qt::DisplayRole) const; bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole);
Qt::ItemFlags flags(QModelIndex const& index) const; Qt::ItemFlags flags(QModelIndex const& index) const;
boost::optional<mapnik::layer&> map_layer(int i); boost::optional<mapnik::layer&> map_layer(int i);

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "layerwidget.hpp" #include "layerwidget.hpp"
#include <qabstractitemdelegate.h> #include <qabstractitemdelegate.h>
#include <qapplication.h> #include <qapplication.h>
@ -33,17 +32,15 @@
#include "layer_info_dialog.hpp" #include "layer_info_dialog.hpp"
LayerTab::LayerTab(QWidget* parent) LayerTab::LayerTab(QWidget* parent)
: QListView(parent) {} : QListView(parent)
{}
void LayerTab::paintEvent(QPaintEvent* e) void LayerTab::paintEvent(QPaintEvent* e)
{ {
QListView::paintEvent(e); QListView::paintEvent(e);
} }
void LayerTab::dataChanged(const QModelIndex &topLeft, void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
const QModelIndex &bottomRight,
const QVector<int> &roles)
{ {
emit update_mapwidget(); emit update_mapwidget();
QListView::dataChanged(topLeft, bottomRight, roles); QListView::dataChanged(topLeft, bottomRight, roles);
@ -66,7 +63,6 @@ void LayerTab::layerInfo()
if (indexes.size() > 0) if (indexes.size() > 0)
{ {
qDebug("id = %d", indexes[0].row()); qDebug("id = %d", indexes[0].row());
} }
} }
@ -86,10 +82,7 @@ void LayerTab::layerInfo2(QModelIndex const& index)
} }
} }
StyleTab::StyleTab(QWidget*) StyleTab::StyleTab(QWidget*) {}
{
}
void StyleTab::contextMenuEvent(QContextMenuEvent* event) void StyleTab::contextMenuEvent(QContextMenuEvent* event)
{ {

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef LAYERWIDGET_HPP #ifndef LAYERWIDGET_HPP
#define LAYERWIDGET_HPP #define LAYERWIDGET_HPP
@ -47,6 +46,7 @@ class StyleTab : public QTreeView
Q_OBJECT Q_OBJECT
public: public:
StyleTab(QWidget* parent = 0); StyleTab(QWidget* parent = 0);
protected: protected:
void contextMenuEvent(QContextMenuEvent* event); void contextMenuEvent(QContextMenuEvent* event);
}; };

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
// qt // qt
#include <QApplication> #include <QApplication>
#include <QStringList> #include <QStringList>
@ -41,8 +40,7 @@ int main( int argc, char **argv )
QSettings settings("viewer.ini", QSettings::IniFormat); QSettings settings("viewer.ini", QSettings::IniFormat);
// register input plug-ins // register input plug-ins
QString plugins_dir = settings.value("mapnik/plugins_dir", QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString();
QVariant("/usr/local/lib/mapnik/input/")).toString();
datasource_cache::instance().register_datasources(plugins_dir.toStdString()); datasource_cache::instance().register_datasources(plugins_dir.toStdString());
// register fonts // register fonts
int count = settings.beginReadArray("mapnik/fonts"); int count = settings.beginReadArray("mapnik/fonts");
@ -57,7 +55,8 @@ int main( int argc, char **argv )
QApplication app(argc, argv); QApplication app(argc, argv);
MainWindow window; MainWindow window;
window.show(); window.show();
if (argc > 1) window.open(argv[1]); if (argc > 1)
window.open(argv[1]);
if (argc >= 3) if (argc >= 3)
{ {
QStringList list = QString(argv[2]).split(","); QStringList list = QString(argv[2]).split(",");
@ -68,23 +67,25 @@ int main( int argc, char **argv )
double y0 = list[1].toDouble(&ok); double y0 = list[1].toDouble(&ok);
double x1 = list[2].toDouble(&ok); double x1 = list[2].toDouble(&ok);
double y1 = list[3].toDouble(&ok); double y1 = list[3].toDouble(&ok);
if (ok) window.set_default_extent(x0,y0,x1,y1); if (ok)
window.set_default_extent(x0, y0, x1, y1);
} }
} }
else else
{ {
std::shared_ptr<mapnik::Map> map = window.get_map(); std::shared_ptr<mapnik::Map> map = window.get_map();
if (map) map->zoom_all(); if (map)
map->zoom_all();
} }
if (argc == 4) if (argc == 4)
{ {
bool ok; bool ok;
double scaling_factor = QString(argv[3]).toDouble(&ok); double scaling_factor = QString(argv[3]).toDouble(&ok);
if (ok) window.set_scaling_factor(scaling_factor); if (ok)
window.set_scaling_factor(scaling_factor);
} }
return app.exec(); return app.exec();
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::cerr << "Could not start viewer: '" << ex.what() << "'\n"; std::cerr << "Could not start viewer: '" << ex.what() << "'\n";
return 1; return 1;

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
// stl // stl
#include <iostream> #include <iostream>
@ -58,8 +57,8 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
MainWindow::MainWindow() MainWindow::MainWindow()
: filename_(), : filename_()
default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428) , default_extent_(-20037508.3428, -20037508.3428, 20037508.3428, 20037508.3428)
{ {
mapWidget_ = new MapWidget(this); mapWidget_ = new MapWidget(this);
QSplitter* splitter = new QSplitter(this); QSplitter* splitter = new QSplitter(this);
@ -107,19 +106,18 @@ MainWindow::MainWindow()
// slider // slider
connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int))); connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int)));
// renderer selector // renderer selector
connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)), connect(renderer_selector_,
mapWidget_, SLOT(updateRenderer(QString const&))); SIGNAL(currentIndexChanged(QString const&)),
mapWidget_,
SLOT(updateRenderer(QString const&)));
// scale factor // scale factor
connect(scale_factor_,SIGNAL(valueChanged(double)), connect(scale_factor_, SIGNAL(valueChanged(double)), mapWidget_, SLOT(updateScaleFactor(double)));
mapWidget_, SLOT(updateScaleFactor(double)));
// //
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap())); connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap()));
connect(layerTab_,SIGNAL(layerSelected(int)), connect(layerTab_, SIGNAL(layerSelected(int)), mapWidget_, SLOT(layerSelected(int)));
mapWidget_,SLOT(layerSelected(int)));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete mapWidget_; delete mapWidget_;
@ -141,8 +139,7 @@ void MainWindow::open(QString const& path)
{ {
if (path.isNull()) if (path.isNull())
{ {
filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"), filename_ = QFileDialog::getOpenFileName(this, tr("Open Mapnik file"), currentPath, "*.xml");
currentPath,"*.xml");
} }
else else
{ {
@ -151,18 +148,15 @@ void MainWindow::open(QString const& path)
if (!filename_.isEmpty()) if (!filename_.isEmpty())
{ {
load_map_file(filename_); load_map_file(filename_);
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_)); setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
} }
} }
void MainWindow::reload() void MainWindow::reload()
{ {
if (!filename_.isEmpty()) if (!filename_.isEmpty())
{ {
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent(); mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
load_map_file(filename_); load_map_file(filename_);
mapWidget_->zoomToBox(bbox); mapWidget_->zoomToBox(bbox);
@ -173,10 +167,10 @@ void MainWindow::reload()
void MainWindow::save() void MainWindow::save()
{ {
QString initialPath = QDir::currentPath() + "/untitled.xml"; QString initialPath = QDir::currentPath() + "/untitled.xml";
QString filename = QFileDialog::getSaveFileName(this, tr("Save"), QString filename = QFileDialog::getSaveFileName(this,
tr("Save"),
initialPath, initialPath,
tr("%1 Files (*.xml)") tr("%1 Files (*.xml)").arg(QString("Mapnik definition")));
.arg(QString("Mapnik definition")));
if (!filename.isEmpty()) if (!filename.isEmpty())
{ {
std::cout << "saving " << filename.toStdString() << std::endl; std::cout << "saving " << filename.toStdString() << std::endl;
@ -195,12 +189,10 @@ void MainWindow::load_map_file(QString const& filename)
{ {
mapnik::auto_cpu_timer t(std::clog, "loading map took: "); mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
mapnik::load_map(*map, filename.toStdString()); mapnik::load_map(*map, filename.toStdString());
} } catch (std::exception const& ex)
catch (std::exception const& ex)
{ {
std::cout << ex.what() << "\n"; std::cout << ex.what() << "\n";
} } catch (...)
catch (...)
{ {
std::cerr << "Exception caught in load_map\n"; std::cerr << "Exception caught in load_map\n";
} }
@ -256,11 +248,11 @@ void MainWindow::export_as()
QByteArray fileFormat = action->data().toByteArray(); QByteArray fileFormat = action->data().toByteArray();
QString initialPath = QDir::currentPath() + "/map." + fileFormat; QString initialPath = QDir::currentPath() + "/map." + fileFormat;
QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"), QString fileName = QFileDialog::getSaveFileName(
this,
tr("Export As"),
initialPath, initialPath,
tr("%1 Files (*.%2);;All Files (*)") tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat)));
.arg(QString(fileFormat.toUpper()))
.arg(QString(fileFormat)));
if (!fileName.isEmpty()) if (!fileName.isEmpty())
{ {
QPixmap const& pix = mapWidget_->pixmap(); QPixmap const& pix = mapWidget_->pixmap();
@ -270,7 +262,6 @@ void MainWindow::export_as()
void MainWindow::print() void MainWindow::print()
{ {
// Q_ASSERT(mapWidget_->pixmap()); // Q_ASSERT(mapWidget_->pixmap());
// QPrintDialog dialog(&printer, this); // QPrintDialog dialog(&printer, this);
// if (dialog.exec()) { // if (dialog.exec()) {
@ -411,8 +402,6 @@ void MainWindow::createToolBars()
fileToolBar->addAction(aboutAct); fileToolBar->addAction(aboutAct);
} }
void MainWindow::set_default_extent(double x0, double y0, double x1, double y1) void MainWindow::set_default_extent(double x0, double y0, double x1, double y1)
{ {
try try
@ -427,8 +416,8 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
mapWidget_->zoomToBox(default_extent_); mapWidget_->zoomToBox(default_extent_);
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl; std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
} }
} } catch (...)
catch (...) {} {}
} }
void MainWindow::set_scaling_factor(double scaling_factor) void MainWindow::set_scaling_factor(double scaling_factor)

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef MAINWINDOW_HPP #ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP #define MAINWINDOW_HPP
@ -46,8 +45,10 @@ class MainWindow : public QMainWindow
virtual ~MainWindow(); virtual ~MainWindow();
void set_default_extent(double x0, double y0, double x1, double y1); void set_default_extent(double x0, double y0, double x1, double y1);
void set_scaling_factor(double scaling_factor); void set_scaling_factor(double scaling_factor);
public: public:
std::shared_ptr<mapnik::Map> get_map(); std::shared_ptr<mapnik::Map> get_map();
protected: protected:
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);
public slots: public slots:
@ -65,6 +66,7 @@ public slots:
void pan_right(); void pan_right();
void pan_up(); void pan_up();
void pan_down(); void pan_down();
private: private:
void createActions(); void createActions();
void createMenus(); void createMenus();
@ -112,5 +114,4 @@ private:
mapnik::box2d<double> default_extent_; mapnik::box2d<double> default_extent_;
}; };
#endif // MAINWINDOW_HPP #endif // MAINWINDOW_HPP

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <QtGui> #include <QtGui>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -41,54 +40,38 @@
#include "mapwidget.hpp" #include "mapwidget.hpp"
#include "info_dialog.hpp" #include "info_dialog.hpp"
using mapnik::image_rgba8;
using mapnik::Map;
using mapnik::layer;
using mapnik::box2d; using mapnik::box2d;
using mapnik::coord2d; using mapnik::coord2d;
using mapnik::feature_kv_iterator;
using mapnik::feature_ptr; using mapnik::feature_ptr;
using mapnik::view_transform; using mapnik::image_rgba8;
using mapnik::layer;
using mapnik::Map;
using mapnik::projection; using mapnik::projection;
using mapnik::scale_denominator; using mapnik::scale_denominator;
using mapnik::feature_kv_iterator; using mapnik::view_transform;
double scales [] = {279541132.014, double scales[] = {279541132.014, 139770566.007, 69885283.0036, 34942641.5018, 17471320.7509,
139770566.007, 8735660.37545, 4367830.18772, 2183915.09386, 1091957.54693, 545978.773466,
69885283.0036, 272989.386733, 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708,
34942641.5018, 8530.9183354, 4265.4591677, 2132.72958385, 1066.36479192, 533.182395962};
17471320.7509,
8735660.37545,
4367830.18772,
2183915.09386,
1091957.54693,
545978.773466,
272989.386733,
136494.693366,
68247.3466832,
34123.6733416,
17061.8366708,
8530.9183354,
4265.4591677,
2132.72958385,
1066.36479192,
533.182395962};
MapWidget::MapWidget(QWidget* parent) MapWidget::MapWidget(QWidget* parent)
: QWidget(parent), : QWidget(parent)
map_(), , map_()
selected_(1), , selected_(1)
extent_(), , extent_()
cur_tool_(ZoomToBox), , cur_tool_(ZoomToBox)
start_x_(0), , start_x_(0)
start_y_(0), , start_y_(0)
end_x_(0), , end_x_(0)
end_y_(0), , end_y_(0)
drag_(false), , drag_(false)
first_(true), , first_(true)
pen_(QColor(0,0,255,96)), , pen_(QColor(0, 0, 255, 96))
selectedLayer_(-1), , selectedLayer_(-1)
scaling_factor_(1.0), , scaling_factor_(1.0)
cur_renderer_(AGG) , cur_renderer_(AGG)
{ {
pen_.setWidth(3); pen_.setWidth(3);
pen_.setCapStyle(Qt::RoundCap); pen_.setCapStyle(Qt::RoundCap);
@ -162,10 +145,12 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
for (unsigned index = 0; index < map_->layer_count(); ++index) for (unsigned index = 0; index < map_->layer_count(); ++index)
{ {
if (int(index) != selectedLayer_) continue; if (int(index) != selectedLayer_)
continue;
layer& layer = map_->layers()[index]; layer& layer = map_->layers()[index];
if (!layer.visible(scale_denom)) continue; if (!layer.visible(scale_denom))
continue;
std::string name = layer.name(); std::string name = layer.name();
double x = e->x(); double x = e->x();
double y = e->y(); double y = e->y();
@ -231,10 +216,9 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
} }
// remove annotation layer // remove annotation layer
map_->layers().erase(remove_if(map_->layers().begin(), map_->layers().erase(
map_->layers().end(), remove_if(map_->layers().begin(), map_->layers().end(), bind(&layer::name, _1) == "*annotations*"),
bind(&layer::name,_1) == "*annotations*") map_->layers().end());
, map_->layers().end());
} }
} }
} }
@ -334,7 +318,8 @@ void MapWidget::wheelEvent(QWheelEvent* e)
void MapWidget::keyPressEvent(QKeyEvent* e) void MapWidget::keyPressEvent(QKeyEvent* e)
{ {
std::cout << "key pressed:" << e->key() << "\n"; std::cout << "key pressed:" << e->key() << "\n";
switch (e->key()) { switch (e->key())
{
case Qt::Key_Minus: case Qt::Key_Minus:
zoomOut(); zoomOut();
break; break;
@ -387,8 +372,6 @@ void MapWidget::keyPressEvent(QKeyEvent *e)
default: default:
QWidget::keyPressEvent(e); QWidget::keyPressEvent(e);
} }
} }
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox) void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
@ -472,7 +455,6 @@ void MapWidget::panRight()
} }
} }
void MapWidget::zoomToLevel(int level) void MapWidget::zoomToLevel(int level)
{ {
if (map_ && level >= 0 && level < 19) if (map_ && level >= 0 && level < 19)
@ -531,20 +513,17 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
catch (std::exception const& ex) catch (std::exception const& ex)
{ {
std::cerr << "exception: " << ex.what() << std::endl; std::cerr << "exception: " << ex.what() << std::endl;
} } catch (...)
catch (...)
{ {
std::cerr << "Unknown exception caught!\n"; std::cerr << "Unknown exception caught!\n";
} }
} }
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap& pix) void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
{ {
std::cerr << "Not supported" << std::endl; std::cerr << "Not supported" << std::endl;
} }
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix) void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
{ {
// FIXME // FIXME
@ -567,9 +546,12 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
void MapWidget::updateRenderer(QString const& txt) void MapWidget::updateRenderer(QString const& txt)
{ {
if (txt == "AGG") cur_renderer_ = AGG; if (txt == "AGG")
else if (txt == "Cairo") cur_renderer_ = Cairo; cur_renderer_ = AGG;
else if (txt == "Grid") cur_renderer_ = Grid; else if (txt == "Cairo")
cur_renderer_ = Cairo;
else if (txt == "Grid")
cur_renderer_ = Grid;
std::cerr << "Update renderer called" << std::endl; std::cerr << "Update renderer called" << std::endl;
updateMap(); updateMap();
} }
@ -620,8 +602,7 @@ void MapWidget::updateMap()
update(); update();
// emit signal to interested widgets // emit signal to interested widgets
emit mapViewChanged(); emit mapViewChanged();
} } catch (...)
catch (...)
{ {
std::cerr << "Unknown exception caught!\n"; std::cerr << "Unknown exception caught!\n";
} }
@ -638,7 +619,6 @@ void MapWidget::setMap(std::shared_ptr<Map> map)
map_ = map; map_ = map;
} }
void MapWidget::layerSelected(int index) void MapWidget::layerSelected(int index)
{ {
selectedLayer_ = index; selectedLayer_ = index;

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef MAP_WIDGET_HPP #ifndef MAP_WIDGET_HPP
#define MAP_WIDGET_HPP #define MAP_WIDGET_HPP
@ -30,7 +29,6 @@
#include <string> #include <string>
#include <memory> #include <memory>
#ifndef Q_MOC_RUN #ifndef Q_MOC_RUN
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#endif #endif
@ -40,19 +38,13 @@ class MapWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
enum eTool enum eTool {
{
ZoomToBox = 1, ZoomToBox = 1,
Pan, Pan,
Info, Info,
}; };
enum eRenderer enum eRenderer { AGG, Cairo, Grid };
{
AGG,
Cairo,
Grid
};
private: private:
std::shared_ptr<mapnik::Map> map_; std::shared_ptr<mapnik::Map> map_;
@ -70,6 +62,7 @@ private:
int selectedLayer_; int selectedLayer_;
double scaling_factor_; double scaling_factor_;
eRenderer cur_renderer_; eRenderer cur_renderer_;
public: public:
MapWidget(QWidget* parent = 0); MapWidget(QWidget* parent = 0);
void setTool(eTool tool); void setTool(eTool tool);
@ -93,6 +86,7 @@ public slots:
void updateScaleFactor(double scale_factor); void updateScaleFactor(double scale_factor);
signals: signals:
void mapViewChanged(); void mapViewChanged();
protected: protected:
void paintEvent(QPaintEvent* ev); void paintEvent(QPaintEvent* ev);
void resizeEvent(QResizeEvent* ev); void resizeEvent(QResizeEvent* ev);
@ -101,10 +95,7 @@ protected:
void mouseReleaseEvent(QMouseEvent* e); void mouseReleaseEvent(QMouseEvent* e);
void wheelEvent(QWheelEvent* e); void wheelEvent(QWheelEvent* e);
void keyPressEvent(QKeyEvent* e); void keyPressEvent(QKeyEvent* e);
void export_to_file(unsigned width, void export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type);
unsigned height,
std::string const& filename,
std::string const& type);
}; };
#endif // MAP_WIDGET_HPP #endif // MAP_WIDGET_HPP

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "styles_model.hpp" #include "styles_model.hpp"
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/util/variant.hpp> #include <mapnik/util/variant.hpp>
@ -48,19 +47,14 @@ class node : private mapnik::util::noncopyable
struct wrap : public node_base struct wrap : public node_base
{ {
wrap(T const& obj) wrap(T const& obj)
: obj_(obj) {} : obj_(obj)
{}
~wrap() {} ~wrap() {}
QString name () const QString name() const { return obj_.name(); }
{
return obj_.name();
}
QIcon icon() const QIcon icon() const { return obj_.icon(); }
{
return obj_.icon();
}
T obj_; T obj_;
}; };
@ -68,34 +62,19 @@ class node : private mapnik::util::noncopyable
public: public:
template<typename T> template<typename T>
node(T const& obj, node* parent = 0) node(T const& obj, node* parent = 0)
: impl_(new wrap<T>(obj)), : impl_(new wrap<T>(obj))
parent_(parent) , parent_(parent)
{} {}
QString name() const QString name() const { return impl_->name(); }
{
return impl_->name();
}
QIcon icon() const QIcon icon() const { return impl_->icon(); }
{
return impl_->icon();
}
unsigned num_children() const unsigned num_children() const { return children_.count(); }
{
return children_.count();
}
node * child(unsigned row) const node* child(unsigned row) const { return children_.value(row); }
{
return children_.value(row);
}
node * parent() const node* parent() const { return parent_; }
{
return parent_;
}
node* add_child(node* child) node* add_child(node* child)
{ {
@ -110,10 +89,7 @@ public:
return 0; return 0;
} }
~node() ~node() { qDeleteAll(children_); }
{
qDeleteAll(children_);
}
private: private:
const std::unique_ptr<node_base> impl_; const std::unique_ptr<node_base> impl_;
@ -121,7 +97,6 @@ private:
node* parent_; node* parent_;
}; };
struct symbolizer_info struct symbolizer_info
{ {
QString operator()(mapnik::point_symbolizer const& sym) const QString operator()(mapnik::point_symbolizer const& sym) const
@ -239,7 +214,8 @@ class symbolizer_node
{ {
public: public:
symbolizer_node(mapnik::symbolizer const& sym) symbolizer_node(mapnik::symbolizer const& sym)
: sym_(sym) {} : sym_(sym)
{}
~symbolizer_node() {} ~symbolizer_node() {}
QString name() const QString name() const
@ -259,8 +235,9 @@ class rule_node
{ {
public: public:
rule_node(QString name, mapnik::rule const& r) rule_node(QString name, mapnik::rule const& r)
: name_(name), : name_(name)
rule_(r) {} , rule_(r)
{}
~rule_node() {} ~rule_node() {}
QString name() const QString name() const
{ {
@ -268,10 +245,7 @@ public:
return QString(mapnik::to_expression_string(*filter).c_str()); return QString(mapnik::to_expression_string(*filter).c_str());
} }
QIcon icon() const QIcon icon() const { return QIcon(":/images/filter.png"); }
{
return QIcon(":/images/filter.png");
}
private: private:
QString name_; QString name_;
@ -282,20 +256,15 @@ class style_node
{ {
public: public:
style_node(QString name, mapnik::feature_type_style const& style) style_node(QString name, mapnik::feature_type_style const& style)
: name_(name), : name_(name)
style_(style) {} , style_(style)
{}
~style_node() {} ~style_node() {}
QString name() const QString name() const { return name_; }
{
return name_;
}
QIcon icon() const QIcon icon() const { return QIcon(":/images/style.png"); }
{
return QIcon(":/images/style.png");
}
private: private:
QString name_; QString name_;
@ -306,26 +275,21 @@ class map_node
{ {
public: public:
explicit map_node(std::shared_ptr<mapnik::Map> map) explicit map_node(std::shared_ptr<mapnik::Map> map)
: map_(map) {} : map_(map)
{}
~map_node() {} ~map_node() {}
QString name() const QString name() const { return QString("Map"); }
{
return QString("Map");
}
QIcon icon() const QIcon icon() const { return QIcon(":/images/map.png"); }
{
return QIcon(":/images/map.png");
}
private: private:
std::shared_ptr<mapnik::Map> map_; std::shared_ptr<mapnik::Map> map_;
}; };
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent) StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
: QAbstractItemModel(parent), : QAbstractItemModel(parent)
root_(new node(map_node(map))) , root_(new node(map_node(map)))
{ {
using style_type = std::map<std::string, mapnik::feature_type_style>; using style_type = std::map<std::string, mapnik::feature_type_style>;
style_type const& styles = map->styles(); style_type const& styles = map->styles();
@ -382,7 +346,8 @@ int StyleModel::rowCount(QModelIndex const& parent) const
{ {
// qDebug("rowCount"); // qDebug("rowCount");
node* parent_node; node* parent_node;
if (parent.column() > 0) return 0; if (parent.column() > 0)
return 0;
if (!parent.isValid()) if (!parent.isValid())
parent_node = root_.get(); parent_node = root_.get();
else else
@ -405,7 +370,6 @@ QVariant StyleModel::data(const QModelIndex & index, int role) const
{ {
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
{ {
return QVariant(cur_node->name()); return QVariant(cur_node->name());
} }
else if (role == Qt::DecorationRole) else if (role == Qt::DecorationRole)

View file

@ -17,7 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef STYLE_MODEL_HPP #ifndef STYLE_MODEL_HPP
#define STYLE_MODEL_HPP #define STYLE_MODEL_HPP
@ -27,8 +26,6 @@
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#endif #endif
class node; class node;
class StyleModel : public QAbstractItemModel class StyleModel : public QAbstractItemModel
{ {
@ -42,6 +39,7 @@ class StyleModel : public QAbstractItemModel
int rowCount(QModelIndex const& parent = QModelIndex()) const; int rowCount(QModelIndex const& parent = QModelIndex()) const;
int columnCount(QModelIndex const& parent = QModelIndex()) const; int columnCount(QModelIndex const& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
private: private:
// std::shared_ptr<mapnik::Map> map_; // std::shared_ptr<mapnik::Map> map_;
const std::unique_ptr<node> root_; const std::unique_ptr<node> root_;

View file

@ -9,8 +9,7 @@ MAPNIK_DISABLE_WARNING_PUSH
#include "agg_conv_smooth_poly1.h" #include "agg_conv_smooth_poly1.h"
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
struct vcgen_smooth_calucate_adaptive struct vcgen_smooth_calucate_adaptive
{ {
@ -57,12 +56,8 @@ struct vcgen_smooth_calucate_adaptive
} }
} }
return { return {{v1.x + s1 * smooth_value * (v2.x - xm1), v1.y + s1 * smooth_value * (v2.y - ym1)},
{v1.x + s1 * smooth_value * (v2.x - xm1), {v2.x + s2 * smooth_value * (v1.x - xm2), v2.y + s2 * smooth_value * (v1.y - ym2)}};
v1.y + s1 * smooth_value * (v2.y - ym1)},
{v2.x + s2 * smooth_value * (v1.x - xm2),
v2.y + s2 * smooth_value * (v1.y - ym2)}
};
} }
}; };
@ -95,45 +90,34 @@ class smooth_converter
} }
public: public:
smooth_converter(Geometry & geom) : smooth_converter(Geometry& geom)
geom_(geom), : geom_(geom)
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom))) , impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
{} {}
void algorithm(smooth_algorithm_enum algo) void algorithm(smooth_algorithm_enum algo) { impl_ = init_impl(algo, geom_); }
{
impl_ = init_impl(algo, geom_);
}
void smooth_value(double v) void smooth_value(double v)
{ {
return util::apply_visitor([=](auto & impl) { return util::apply_visitor([=](auto& impl) { impl.smooth_value(v); }, impl_);
impl.smooth_value(v);
}, impl_);
} }
void rewind(unsigned path_id) void rewind(unsigned path_id)
{ {
return util::apply_visitor([=](auto & impl) { return util::apply_visitor([=](auto& impl) { return impl.rewind(path_id); }, impl_);
return impl.rewind(path_id);
}, impl_);
} }
unsigned vertex(double* x, double* y) unsigned vertex(double* x, double* y)
{ {
return util::apply_visitor([=](auto & impl) { return util::apply_visitor([=](auto& impl) { return impl.vertex(x, y); }, impl_);
return impl.vertex(x, y);
}, impl_);
} }
unsigned type() const unsigned type() const
{ {
return util::apply_visitor([](auto const& impl) { return util::apply_visitor([](auto const& impl) { return impl.type(); }, impl_);
return impl.type();
}, impl_);
} }
}; };
} } // namespace mapnik
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP #endif // MAPNIK_ADAPTIVE_SMOOTH_HPP

View file

@ -78,41 +78,40 @@ struct agg_polygon_pattern : agg_pattern_base
using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>; using pixfmt_type = agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer>;
using wrap_x_type = agg::wrap_mode_repeat; using wrap_x_type = agg::wrap_mode_repeat;
using wrap_y_type = agg::wrap_mode_repeat; using wrap_y_type = agg::wrap_mode_repeat;
using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, using img_source_type = agg::image_accessor_wrap<agg::pixfmt_rgba32_pre, wrap_x_type, wrap_y_type>;
wrap_x_type,
wrap_y_type>;
using span_gen_type = agg::span_pattern_rgba<img_source_type>; using span_gen_type = agg::span_pattern_rgba<img_source_type>;
using renderer_base = agg::renderer_base<pixfmt_type>; using renderer_base = agg::renderer_base<pixfmt_type>;
using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base, using renderer_type =
agg::span_allocator<agg::rgba8>, agg::renderer_scanline_aa_alpha<renderer_base, agg::span_allocator<agg::rgba8>, span_gen_type>;
span_gen_type>;
agg_polygon_pattern(image_rgba8 const& pattern_img, agg_polygon_pattern(image_rgba8 const& pattern_img,
renderer_common const& common, renderer_common const& common,
symbolizer_base const& sym, symbolizer_base const& sym,
mapnik::feature_impl const& feature, mapnik::feature_impl const& feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
: agg_pattern_base{pattern_img, common, sym, feature, prj_trans}, : agg_pattern_base{pattern_img, common, sym, feature, prj_trans}
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)), , clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
clip_box_(clipping_extent(common)), , clip_box_(clipping_extent(common))
tr_(geom_transform()), , tr_(geom_transform())
converter_(clip_box_, sym, common.t_, prj_trans, tr_, , converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
feature, common.vars_, common.scale_factor_)
{ {
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_); value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym_, feature_, common_.vars_);
value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_); value_double smooth = get<value_double, keys::smooth>(sym_, feature_, common_.vars_);
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>(); if (simplify_tolerance > 0.0)
converter_.template set<simplify_tag>();
converter_.template set<affine_transform_tag>(); converter_.template set<affine_transform_tag>();
if (smooth > 0.0) converter_.template set<smooth_tag>(); if (smooth > 0.0)
converter_.template set<smooth_tag>();
} }
void render(renderer_base& ren_base, rasterizer& ras) void render(renderer_base& ren_base, rasterizer& ras)
{ {
coord<double, 2> offset(pattern_offset(sym_, feature_, prj_trans_, common_, coord<double, 2> offset(
pattern_img_.width(), pattern_img_.height())); pattern_offset(sym_, feature_, prj_trans_, common_, pattern_img_.width(), pattern_img_.height()));
agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(), agg::rendering_buffer pattern_rbuf((agg::int8u*)pattern_img_.bytes(),
pattern_img_.width(), pattern_img_.height(), pattern_img_.width(),
pattern_img_.height(),
pattern_img_.width() * 4); pattern_img_.width() * 4);
agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf); agg::pixfmt_rgba32_pre pixf_pattern(pattern_rbuf);
img_source_type img_src(pixf_pattern); img_source_type img_src(pixf_pattern);
@ -122,8 +121,7 @@ struct agg_polygon_pattern : agg_pattern_base
value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_); value_double opacity = get<double, keys::opacity>(sym_, feature_, common_.vars_);
renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255)); renderer_type rp(ren_base, sa, sg, unsigned(opacity * 255));
using apply_vertex_converter_type = detail::apply_vertex_converter< using apply_vertex_converter_type = detail::apply_vertex_converter<VertexConverter, rasterizer>;
VertexConverter, rasterizer>;
using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>; using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
apply_vertex_converter_type apply(converter_, ras); apply_vertex_converter_type apply(converter_, ras);
mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry()); mapnik::util::apply_visitor(vertex_processor_type(apply), feature_.get_geometry());
@ -139,5 +137,4 @@ struct agg_polygon_pattern : agg_pattern_base
} // namespace mapnik } // namespace mapnik
#endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP #endif // MAPNIK_RENDER_POLYGON_PATTERN_HPP

View file

@ -59,6 +59,6 @@ void set_gamma_method(T & ras_ptr, double gamma, gamma_method_enum method)
} }
} }
} } // namespace mapnik
#endif // MAPNIK_AGG_HELPERS_HPP #endif // MAPNIK_AGG_HELPERS_HPP

View file

@ -33,24 +33,18 @@ MAPNIK_DISABLE_WARNING_PUSH
#include "agg_color_rgba.h" #include "agg_color_rgba.h"
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
class pattern_source : private util::noncopyable class pattern_source : private util::noncopyable
{ {
public: public:
pattern_source(image_rgba8 const& pattern, double opacity = 1.0) pattern_source(image_rgba8 const& pattern, double opacity = 1.0)
: pattern_(pattern), : pattern_(pattern)
opacity_(opacity) {} , opacity_(opacity)
{}
unsigned int width() const unsigned int width() const { return pattern_.width(); }
{ unsigned int height() const { return pattern_.height(); }
return pattern_.width();
}
unsigned int height() const
{
return pattern_.height();
}
agg::rgba8 pixel(int x, int y) const agg::rgba8 pixel(int x, int y) const
{ {
unsigned c = pattern_(x, y); unsigned c = pattern_(x, y);
@ -59,10 +53,11 @@ public:
static_cast<unsigned>(((c >> 16) & 0xff) * opacity_), static_cast<unsigned>(((c >> 16) & 0xff) * opacity_),
static_cast<unsigned>(((c >> 24) & 0xff) * opacity_)); static_cast<unsigned>(((c >> 24) & 0xff) * opacity_));
} }
private: private:
image_rgba8 const& pattern_; image_rgba8 const& pattern_;
double opacity_; double opacity_;
}; };
} } // namespace mapnik
#endif // MAPNIK_AGG_PATTERN_SOURCE_HPP #endif // MAPNIK_AGG_PATTERN_SOURCE_HPP

View file

@ -26,7 +26,6 @@
// mapnik // mapnik
#include <mapnik/util/noncopyable.hpp> #include <mapnik/util/noncopyable.hpp>
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore_agg.hpp> #include <mapnik/warning_ignore_agg.hpp>
@ -35,8 +34,10 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>, util::noncopyable {}; struct rasterizer : agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_int_sat>,
util::noncopyable
{};
} } // namespace mapnik
#endif // MAPNIK_AGG_RASTERIZER_HPP #endif // MAPNIK_AGG_RASTERIZER_HPP

View file

@ -53,9 +53,13 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType> template<typename SvgRenderer, typename RasterizerType, typename RendererBaseType>
void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, RendererBaseType & renb, void render_vector_marker(SvgRenderer& svg_renderer,
box2d<double> const& bbox, agg::trans_affine const& tr, RasterizerType& ras,
double opacity, bool snap_to_pixels) RendererBaseType& renb,
box2d<double> const& bbox,
agg::trans_affine const& tr,
double opacity,
bool snap_to_pixels)
{ {
agg::scanline_u8 sl; agg::scanline_u8 sl;
if (snap_to_pixels) if (snap_to_pixels)
@ -73,9 +77,13 @@ void render_vector_marker(SvgRenderer & svg_renderer, RasterizerType & ras, Rend
} }
template<typename RendererType, typename RasterizerType> template<typename RendererType, typename RasterizerType>
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src, void render_raster_marker(RendererType renb,
agg::trans_affine const& tr, double opacity, RasterizerType& ras,
float scale_factor, bool snap_to_pixels) image_rgba8 const& src,
agg::trans_affine const& tr,
double opacity,
float scale_factor,
bool snap_to_pixels)
{ {
using color_type = agg::rgba8; using color_type = agg::rgba8;
using const_rendering_buffer = util::rendering_buffer<image_rgba8>; using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
@ -84,11 +92,9 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
agg::scanline_u8 sl; agg::scanline_u8 sl;
double width = src.width(); double width = src.width();
double height = src.height(); double height = src.height();
if (std::fabs(1.0 - scale_factor) < 0.001 if (std::fabs(1.0 - scale_factor) < 0.001 && (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) &&
&& (std::fabs(1.0 - tr.sx) < agg::affine_epsilon) (std::fabs(0.0 - tr.shy) < agg::affine_epsilon) && (std::fabs(0.0 - tr.shx) < agg::affine_epsilon) &&
&& (std::fabs(0.0 - tr.shy) < agg::affine_epsilon) (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
&& (std::fabs(0.0 - tr.shx) < agg::affine_epsilon)
&& (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
{ {
const_rendering_buffer src_buffer(src); const_rendering_buffer src_buffer(src);
pixfmt_pre pixf_mask(src_buffer); pixfmt_pre pixf_mask(src_buffer);
@ -102,11 +108,7 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
} }
else else
{ {
renb.blend_from(pixf_mask, renb.blend_from(pixf_mask, 0, static_cast<int>(tr.tx), static_cast<int>(tr.ty), unsigned(255 * opacity));
0,
static_cast<int>(tr.tx),
static_cast<int>(tr.ty),
unsigned(255*opacity));
} }
} }
else else
@ -115,15 +117,18 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
using interpolator_type = agg::span_interpolator_linear<>; using interpolator_type = agg::span_interpolator_linear<>;
// using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>; // using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>; using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
using renderer_type = agg::renderer_scanline_aa_alpha<RendererType, using renderer_type =
agg::span_allocator<color_type>, agg::renderer_scanline_aa_alpha<RendererType, agg::span_allocator<color_type>, span_gen_type>;
span_gen_type>;
double p[8]; double p[8];
p[0] = 0; p[1] = 0; p[0] = 0;
p[2] = width; p[3] = 0; p[1] = 0;
p[4] = width; p[5] = height; p[2] = width;
p[6] = 0; p[7] = height; p[3] = 0;
p[4] = width;
p[5] = height;
p[6] = 0;
p[7] = height;
tr.transform(&p[0], &p[1]); tr.transform(&p[0], &p[1]);
tr.transform(&p[2], &p[3]); tr.transform(&p[2], &p[3]);
tr.transform(&p[4], &p[5]); tr.transform(&p[4], &p[5]);
@ -151,6 +156,6 @@ void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 c
} }
} }
} } // namespace mapnik
#endif // MAPNIK_AGG_RENDER_MARKER_HPP #endif // MAPNIK_AGG_RENDER_MARKER_HPP

View file

@ -41,7 +41,9 @@
#include <stack> #include <stack>
// fwd declaration to avoid dependence on agg headers // fwd declaration to avoid dependence on agg headers
namespace agg { struct trans_affine; } namespace agg {
struct trans_affine;
}
// fwd declarations to speed up compile // fwd declarations to speed up compile
namespace mapnik { namespace mapnik {
@ -55,8 +57,9 @@ namespace mapnik {
class proj_transform; class proj_transform;
struct rasterizer; struct rasterizer;
struct rgba8_t; struct rgba8_t;
template<typename T> class image; template<typename T>
} class image;
} // namespace mapnik
namespace mapnik { namespace mapnik {
@ -65,12 +68,11 @@ class buffer_stack
{ {
public: public:
buffer_stack(std::size_t width, std::size_t height) buffer_stack(std::size_t width, std::size_t height)
: width_(width), : width_(width)
height_(height), , height_(height)
buffers_(), , buffers_()
position_(buffers_.begin()) , position_(buffers_.begin())
{ {}
}
T& push() T& push()
{ {
@ -86,10 +88,7 @@ public:
} }
return *position_; return *position_;
} }
bool in_range() const bool in_range() const { return (position_ != buffers_.end()); }
{
return (position_ != buffers_.end());
}
void pop() void pop()
{ {
@ -98,10 +97,7 @@ public:
++position_; ++position_;
} }
T & top() const T& top() const { return *position_; }
{
return *position_;
}
private: private:
const std::size_t width_; const std::size_t width_;
@ -114,18 +110,31 @@ template <typename T0, typename T1=label_collision_detector4>
class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>, class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T0>>,
private util::noncopyable private util::noncopyable
{ {
public: public:
using buffer_type = T0; using buffer_type = T0;
using processor_impl_type = agg_renderer<T0>; using processor_impl_type = agg_renderer<T0>;
using detector_type = T1; using detector_type = T1;
// create with default, empty placement detector // create with default, empty placement detector
agg_renderer(Map const& m, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); agg_renderer(Map const& m,
buffer_type& pixmap,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
// create with external placement detector, possibly non-empty // create with external placement detector, possibly non-empty
agg_renderer(Map const &m, buffer_type & pixmap, std::shared_ptr<detector_type> detector, agg_renderer(Map const& m,
double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); buffer_type& pixmap,
std::shared_ptr<detector_type> detector,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
// pass in mapnik::request object to provide the mutable things per render // pass in mapnik::request object to provide the mutable things per render
agg_renderer(Map const& m, request const& req, attributes const& vars, buffer_type & pixmap, double scale_factor=1.0, unsigned offset_x=0, unsigned offset_y=0); agg_renderer(Map const& m,
request const& req,
attributes const& vars,
buffer_type& pixmap,
double scale_factor = 1.0,
unsigned offset_x = 0,
unsigned offset_y = 0);
~agg_renderer(); ~agg_renderer();
void start_map_processing(Map const& map); void start_map_processing(Map const& map);
void end_map_processing(Map const& map); void end_map_processing(Map const& map);
@ -135,52 +144,27 @@ public:
void start_style_processing(feature_type_style const& st); void start_style_processing(feature_type_style const& st);
void end_style_processing(feature_type_style const& st); void end_style_processing(feature_type_style const& st);
void render_marker(pixel_position const& pos, marker const& marker, agg::trans_affine const& tr, void render_marker(pixel_position const& pos,
double opacity, composite_mode_e comp_op); marker const& marker,
agg::trans_affine const& tr,
double opacity,
composite_mode_e comp_op);
void process(point_symbolizer const& sym, void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(debug_symbolizer const& sym, feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym, void process(dot_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(raster_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(shield_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(markers_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(group_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(debug_symbolizer const& sym,
feature_impl & feature,
proj_transform const& prj_trans);
void process(dot_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
inline bool process(rule::symbolizers const&, inline bool process(rule::symbolizers const&, mapnik::feature_impl&, proj_transform const&)
mapnik::feature_impl&,
proj_transform const& )
{ {
// agg renderer doesn't support processing of multiple symbolizers. // agg renderer doesn't support processing of multiple symbolizers.
return false; return false;
@ -189,26 +173,16 @@ public:
void painted(bool painted); void painted(bool painted);
bool painted(); bool painted();
inline eAttributeCollectionPolicy attribute_collection_policy() const inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
{
return DEFAULT;
}
inline double scale_factor() const inline double scale_factor() const { return common_.scale_factor_; }
{
return common_.scale_factor_; inline attributes const& variables() const { return common_.vars_; }
}
inline attributes const& variables() const
{
return common_.vars_;
}
protected: protected:
template<typename R> template<typename R>
void debug_draw_box(R& buf, box2d<double> const& extent, void debug_draw_box(R& buf, box2d<double> const& extent, double x, double y, double angle = 0.0);
double x, double y, double angle = 0.0); void debug_draw_box(box2d<double> const& extent, double x, double y, double angle = 0.0);
void debug_draw_box(box2d<double> const& extent,
double x, double y, double angle = 0.0);
void draw_geo_extent(box2d<double> const& extent, mapnik::color const& color); void draw_geo_extent(box2d<double> const& extent, mapnik::color const& color);
private: private:

View file

@ -37,7 +37,8 @@ struct attribute
{ {
std::string name_; std::string name_;
explicit attribute(std::string const& _name) explicit attribute(std::string const& _name)
: name_(_name) {} : name_(_name)
{}
template<typename V, typename F> template<typename V, typename F>
V const& value(F const& f) const V const& value(F const& f) const
@ -61,7 +62,8 @@ struct global_attribute
{ {
std::string name; std::string name;
explicit global_attribute(std::string const& name_) explicit global_attribute(std::string const& name_)
: name(name_) {} : name(name_)
{}
template<typename V, typename C> template<typename V, typename C>
V const& operator()(C const& ctx) V const& operator()(C const& ctx)
@ -72,6 +74,6 @@ struct global_attribute
using attributes = std::unordered_map<std::string, value>; using attributes = std::unordered_map<std::string, value>;
} } // namespace mapnik
#endif // MAPNIK_ATTRIBUTE_HPP #endif // MAPNIK_ATTRIBUTE_HPP

View file

@ -55,12 +55,10 @@ template <typename Container>
struct expression_attributes struct expression_attributes
{ {
explicit expression_attributes(Container& names) explicit expression_attributes(Container& names)
: names_(names) {} : names_(names)
{}
void operator() (attribute const& attr) const void operator()(attribute const& attr) const { names_.emplace(attr.name()); }
{
names_.emplace(attr.name());
}
template<typename Tag> template<typename Tag>
void operator()(binary_node<Tag> const& x) const void operator()(binary_node<Tag> const& x) const
@ -75,18 +73,13 @@ struct expression_attributes
util::apply_visitor(*this, x.expr); util::apply_visitor(*this, x.expr);
} }
void operator() (regex_match_node const& x) const void operator()(regex_match_node const& x) const { util::apply_visitor(*this, x.expr); }
{
util::apply_visitor(*this, x.expr);
}
void operator() (regex_replace_node const& x) const void operator()(regex_replace_node const& x) const { util::apply_visitor(*this, x.expr); }
{
util::apply_visitor(*this, x.expr);
}
template<typename T> template<typename T>
void operator() (T const&) const {} void operator()(T const&) const
{}
private: private:
Container& names_; Container& names_;
@ -97,11 +90,12 @@ class group_attribute_collector : public util::noncopyable
private: private:
std::set<std::string>& names_; std::set<std::string>& names_;
bool expand_index_columns_; bool expand_index_columns_;
public: public:
group_attribute_collector(std::set<std::string>& names, group_attribute_collector(std::set<std::string>& names, bool expand_index_columns)
bool expand_index_columns) : names_(names)
: names_(names), , expand_index_columns_(expand_index_columns)
expand_index_columns_(expand_index_columns) {} {}
void operator()(group_symbolizer const& sym); void operator()(group_symbolizer const& sym);
}; };
@ -110,8 +104,9 @@ template <typename Container>
struct extract_attribute_names struct extract_attribute_names
{ {
explicit extract_attribute_names(Container& names) explicit extract_attribute_names(Container& names)
: names_(names), : names_(names)
f_attr_(names) {} , f_attr_(names)
{}
void operator()(mapnik::expression_ptr const& expr) const void operator()(mapnik::expression_ptr const& expr) const
{ {
@ -138,7 +133,8 @@ struct extract_attribute_names
expr->add_expressions(expressions); expr->add_expressions(expressions);
for (it = expressions.begin(); it != expressions.end(); ++it) for (it = expressions.begin(); it != expressions.end(); ++it)
{ {
if (*it) util::apply_visitor(f_attr_, **it); if (*it)
util::apply_visitor(f_attr_, **it);
} }
} }
} }
@ -152,7 +148,8 @@ struct extract_attribute_names
} }
template<typename T> template<typename T>
void operator() (T const&) const {} void operator()(T const&) const
{}
private: private:
Container& names_; Container& names_;
@ -161,11 +158,11 @@ private:
struct symbolizer_attributes struct symbolizer_attributes
{ {
symbolizer_attributes(std::set<std::string>& names, symbolizer_attributes(std::set<std::string>& names, double& filter_factor)
double & filter_factor) : filter_factor_(filter_factor)
: filter_factor_(filter_factor), , f_attrs_(names)
f_attrs_(names), , g_attrs_(names, true)
g_attrs_(names, true) {} {}
template<typename T> template<typename T>
void operator()(T const& sym) void operator()(T const& sym)
@ -197,10 +194,7 @@ struct symbolizer_attributes
} }
} }
void operator () (group_symbolizer const& sym) void operator()(group_symbolizer const& sym) { g_attrs_(sym); }
{
g_attrs_(sym);
}
private: private:
double& filter_factor_; double& filter_factor_;
@ -208,19 +202,20 @@ private:
group_attribute_collector g_attrs_; group_attribute_collector g_attrs_;
}; };
class attribute_collector : public util::noncopyable class attribute_collector : public util::noncopyable
{ {
private: private:
std::set<std::string>& names_; std::set<std::string>& names_;
double filter_factor_; double filter_factor_;
expression_attributes<std::set<std::string>> f_attr; expression_attributes<std::set<std::string>> f_attr;
public: public:
attribute_collector(std::set<std::string>& names) attribute_collector(std::set<std::string>& names)
: names_(names), : names_(names)
filter_factor_(1.0), , filter_factor_(1.0)
f_attr(names) {} , f_attr(names)
{}
template<typename RuleType> template<typename RuleType>
void operator()(RuleType const& r) void operator()(RuleType const& r)
{ {
@ -235,13 +230,9 @@ public:
util::apply_visitor(f_attr, *expr); util::apply_visitor(f_attr, *expr);
} }
double get_filter_factor() const double get_filter_factor() const { return filter_factor_; }
{
return filter_factor_;
}
}; };
inline void group_attribute_collector::operator()(group_symbolizer const& sym) inline void group_attribute_collector::operator()(group_symbolizer const& sym)
{ {
// find all column names referenced in the group symbolizer // find all column names referenced in the group symbolizer

View file

@ -27,35 +27,30 @@
namespace mapnik { namespace mapnik {
enum eAttributeType { enum eAttributeType { Integer = 1, Float = 2, Double = 3, String = 4, Boolean = 5, Geometry = 6, Object = 7 };
Integer=1,
Float =2,
Double =3,
String =4,
Boolean =5,
Geometry=6,
Object=7
};
class attribute_descriptor class attribute_descriptor
{ {
public: public:
attribute_descriptor(std::string const& name,unsigned type, attribute_descriptor(std::string const& name,
unsigned type,
bool primary_key = false, bool primary_key = false,
int size = -1, int size = -1,
int precision = -1) int precision = -1)
: name_(name), : name_(name)
type_(type), , type_(type)
size_(size), , size_(size)
precision_(precision), , precision_(precision)
primary_key_(primary_key) {} , primary_key_(primary_key)
{}
attribute_descriptor(attribute_descriptor const& other) attribute_descriptor(attribute_descriptor const& other)
: name_(other.name_), : name_(other.name_)
type_(other.type_), , type_(other.type_)
size_(other.size_), , size_(other.size_)
precision_(other.precision_), , precision_(other.precision_)
primary_key_(other.primary_key_) {} , primary_key_(other.primary_key_)
{}
attribute_descriptor& operator=(attribute_descriptor rhs) attribute_descriptor& operator=(attribute_descriptor rhs)
{ {
@ -68,30 +63,15 @@ public:
return *this; return *this;
} }
std::string const& get_name() const std::string const& get_name() const { return name_; }
{
return name_;
}
unsigned int get_type() const unsigned int get_type() const { return type_; }
{
return type_;
}
bool is_primary_key() const bool is_primary_key() const { return primary_key_; }
{
return primary_key_;
}
int get_size() const int get_size() const { return size_; }
{
return size_;
}
int get_precision() const int get_precision() const { return precision_; }
{
return precision_;
}
private: private:
std::string name_; std::string name_;
@ -101,6 +81,6 @@ private:
bool primary_key_; bool primary_key_;
}; };
} } // namespace mapnik
#endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP #endif // MAPNIK_ATTRIBUTE_DESCRIPTOR_HPP

View file

@ -30,23 +30,22 @@
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
namespace mapnik namespace mapnik {
{
class MAPNIK_DECL boolean_type class MAPNIK_DECL boolean_type
{ {
public: public:
boolean_type() boolean_type()
: b_(false) {} : b_(false)
{}
boolean_type(bool b) boolean_type(bool b)
: b_(b) {} : b_(b)
{}
boolean_type(boolean_type const& b) boolean_type(boolean_type const& b)
: b_(b.b_) {} : b_(b.b_)
{}
operator bool() const operator bool() const { return b_; }
{
return b_;
}
boolean_type& operator=(boolean_type const& other) boolean_type& operator=(boolean_type const& other)
{ {
@ -62,27 +61,26 @@ private:
// Special stream input operator for boolean_type values // Special stream input operator for boolean_type values
template<typename charT, typename traits> template<typename charT, typename traits>
std::basic_istream<charT, traits> & std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& s, boolean_type& b)
operator >> ( std::basic_istream<charT, traits> & s, boolean_type & b )
{ {
if (s) if (s)
{ {
std::string word; std::string word;
s >> word; s >> word;
bool result; bool result;
if (util::string2bool(word,result)) b = result; if (util::string2bool(word, result))
b = result;
} }
return s; return s;
} }
template<typename charT, typename traits> template<typename charT, typename traits>
std::basic_ostream<charT, traits> & std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, boolean_type const& b)
operator << ( std::basic_ostream<charT, traits> & s, boolean_type const& b )
{ {
s << (b ? "true" : "false"); s << (b ? "true" : "false");
return s; return s;
} }
} } // namespace mapnik
#endif // MAPNIK_BOOLEAN_HPP #endif // MAPNIK_BOOLEAN_HPP

View file

@ -23,17 +23,21 @@
#ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP #ifndef MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
#define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP #define MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP
namespace boost { namespace spirit { namespace x3 namespace boost {
{ namespace spirit {
namespace x3 {
// helper macro // helper macro
#define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \ #define BOOST_SPIRIT_INSTANTIATE_UNUSED(rule_type, Iterator, Context) \
template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \ template bool parse_rule<Iterator, Context, boost::spirit::x3::unused_type const>( \
rule_type rule_ \ rule_type rule_, \
, Iterator& first, Iterator const& last \ Iterator & first, \
, Context const& context, boost::spirit::x3::unused_type const& ); \ Iterator const& last, \
Context const& context, \
boost::spirit::x3::unused_type const&); \
/***/ /***/
}}} } // namespace x3
} // namespace spirit
} // namespace boost
#endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP #endif // MAPNIK_BOOST_SPIRIT_INSTANTIATE_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CAIRO_CONTEXT_HPP #ifndef MAPNIK_CAIRO_CONTEXT_HPP
#define MAPNIK_CAIRO_CONTEXT_HPP #define MAPNIK_CAIRO_CONTEXT_HPP
@ -57,7 +56,8 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
template <typename T> class box2d; template<typename T>
class box2d;
using ErrorStatus = cairo_status_t; using ErrorStatus = cairo_status_t;
@ -86,12 +86,15 @@ public:
cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face); cairo_face(std::shared_ptr<font_library> const& library, face_ptr const& face);
~cairo_face(); ~cairo_face();
cairo_font_face_t* face() const; cairo_font_face_t* face() const;
private: private:
class handle class handle
{ {
public: public:
handle(std::shared_ptr<font_library> const& library, face_ptr const& face) handle(std::shared_ptr<font_library> const& library, face_ptr const& face)
: library_(library), face_(face) {} : library_(library)
, face_(face)
{}
private: private:
std::shared_ptr<font_library> library_; std::shared_ptr<font_library> library_;
@ -127,7 +130,8 @@ struct cairo_closer
{ {
void operator()(cairo_t* obj) void operator()(cairo_t* obj)
{ {
if (obj) cairo_destroy(obj); if (obj)
cairo_destroy(obj);
} }
}; };
@ -135,7 +139,8 @@ struct cairo_surface_closer
{ {
void operator()(cairo_surface_t* surface) void operator()(cairo_surface_t* surface)
{ {
if (surface) cairo_surface_destroy(surface); if (surface)
cairo_surface_destroy(surface);
} }
}; };
@ -157,15 +162,12 @@ public:
const unsigned int* in_end = in_ptr + pixels; const unsigned int* in_end = in_ptr + pixels;
unsigned int* out_ptr; unsigned int* out_ptr;
surface_ = cairo_surface_ptr( surface_ = cairo_surface_ptr(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
cairo_image_surface_create(
CAIRO_FORMAT_ARGB32,
static_cast<int>(data.width()), static_cast<int>(data.width()),
static_cast<int>(data.height())), static_cast<int>(data.height())),
cairo_surface_closer()); cairo_surface_closer());
out_ptr = reinterpret_cast<unsigned int *>( out_ptr = reinterpret_cast<unsigned int*>(cairo_image_surface_get_data(surface_.get()));
cairo_image_surface_get_data(surface_.get()));
while (in_ptr < in_end) while (in_ptr < in_end)
{ {
@ -186,21 +188,18 @@ public:
pattern_ = cairo_pattern_create_for_surface(surface_.get()); pattern_ = cairo_pattern_create_for_surface(surface_.get());
} }
cairo_pattern(cairo_surface_ptr const& surface) : cairo_pattern(cairo_surface_ptr const& surface)
surface_(surface), : surface_(surface)
pattern_(cairo_pattern_create_for_surface(surface_.get())) , pattern_(cairo_pattern_create_for_surface(surface_.get()))
{ {}
}
~cairo_pattern() ~cairo_pattern()
{ {
if (pattern_) cairo_pattern_destroy(pattern_); if (pattern_)
cairo_pattern_destroy(pattern_);
} }
void set_matrix(cairo_matrix_t const& matrix) void set_matrix(cairo_matrix_t const& matrix) { cairo_pattern_set_matrix(pattern_, &matrix); }
{
cairo_pattern_set_matrix(pattern_, &matrix);
}
void set_origin(double x, double y) void set_origin(double x, double y)
{ {
@ -211,27 +210,17 @@ public:
cairo_pattern_set_matrix(pattern_, &matrix); cairo_pattern_set_matrix(pattern_, &matrix);
} }
void set_extend(cairo_extend_t extend) void set_extend(cairo_extend_t extend) { cairo_pattern_set_extend(pattern_, extend); }
{
cairo_pattern_set_extend(pattern_, extend);
}
void set_filter(cairo_filter_t filter) void set_filter(cairo_filter_t filter) { cairo_pattern_set_filter(pattern_, filter); }
{
cairo_pattern_set_filter(pattern_, filter);
}
cairo_pattern_t * pattern() const cairo_pattern_t* pattern() const { return pattern_; }
{
return pattern_;
}
private: private:
cairo_surface_ptr surface_; cairo_surface_ptr surface_;
cairo_pattern_t* pattern_; cairo_pattern_t* pattern_;
}; };
class cairo_gradient : private util::noncopyable class cairo_gradient : private util::noncopyable
{ {
public: public:
@ -275,21 +264,13 @@ public:
cairo_pattern_destroy(pattern_); cairo_pattern_destroy(pattern_);
} }
cairo_pattern_t* gradient() const { return pattern_; }
cairo_pattern_t * gradient() const gradient_unit_e units() const { return units_; }
{
return pattern_;
}
gradient_unit_e units() const
{
return units_;
}
private: private:
cairo_pattern_t* pattern_; cairo_pattern_t* pattern_;
gradient_unit_e units_; gradient_unit_e units_;
}; };
class cairo_context : private util::noncopyable class cairo_context : private util::noncopyable
@ -297,10 +278,7 @@ class cairo_context : private util::noncopyable
public: public:
cairo_context(cairo_ptr const& cairo); cairo_context(cairo_ptr const& cairo);
inline ErrorStatus get_status() const inline ErrorStatus get_status() const { return cairo_status(cairo_.get()); }
{
return cairo_status(cairo_.get());
}
void clip(); void clip();
void show_page(); void show_page();
@ -434,10 +412,11 @@ template <typename Context>
struct line_pattern_rasterizer struct line_pattern_rasterizer
{ {
line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height) line_pattern_rasterizer(Context& context, cairo_pattern& pattern, unsigned width, unsigned height)
: context_(context), : context_(context)
pattern_(pattern), , pattern_(pattern)
width_(width), , width_(width)
height_(height) {} , height_(height)
{}
template<typename T> template<typename T>
void add_path(T& path, unsigned start_index = 0) void add_path(T& path, unsigned start_index = 0)
@ -485,7 +464,6 @@ struct line_pattern_rasterizer
unsigned height_; unsigned height_;
}; };
} } // namespace mapnik
#endif // MAPNIK_CAIRO_CONTEXT_HPP #endif // MAPNIK_CAIRO_CONTEXT_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP #ifndef MAPNIK_CAIRO_IMAGE_UTIL_HPP
#define MAPNIK_CAIRO_IMAGE_UTIL_HPP #define MAPNIK_CAIRO_IMAGE_UTIL_HPP
@ -33,8 +32,7 @@
namespace mapnik { namespace mapnik {
static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data, static inline void cairo_image_to_rgba8(mapnik::image_rgba8& data, cairo_surface_ptr const& surface)
cairo_surface_ptr const& surface)
{ {
if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32) if (cairo_image_surface_get_format(&*surface) != CAIRO_FORMAT_ARGB32)
{ {
@ -62,10 +60,15 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
unsigned int g = (in >> 8) & 0xff; unsigned int g = (in >> 8) & 0xff;
unsigned int b = (in >> 0) & 0xff; unsigned int b = (in >> 0) & 0xff;
#define DE_ALPHA(x) do { \ #define DE_ALPHA(x) \
if (a == 0) x = 0; \ do \
else x = x * 255 / a; \ { \
if (x > 255) x = 255; \ if (a == 0) \
x = 0; \
else \
x = x * 255 / a; \
if (x > 255) \
x = 255; \
} while (0) } while (0)
DE_ALPHA(r); DE_ALPHA(r);
@ -78,7 +81,6 @@ static inline void cairo_image_to_rgba8(mapnik::image_rgba8 & data,
} }
} }
} } // namespace mapnik
#endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP #endif // MAPNIK_CAIRO_IMAGE_UTIL_HPP

View file

@ -32,12 +32,14 @@ namespace mapnik {
class cairo_context; class cairo_context;
void render_vector_marker(cairo_context & context, svg_path_adapter & svg_path, void render_vector_marker(cairo_context& context,
svg_path_adapter& svg_path,
svg_attribute_type const& attributes, svg_attribute_type const& attributes,
box2d<double> const& bbox, agg::trans_affine const& tr, box2d<double> const& bbox,
agg::trans_affine const& tr,
double opacity); double opacity);
} } // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP #endif // MAPNIK_CAIRO_RENDER_VECTOR_HPP

View file

@ -58,10 +58,7 @@ struct cairo_save_restore
{ {
context_.save(); context_.save();
} }
~cairo_save_restore() ~cairo_save_restore() { context_.restore(); }
{
context_.restore();
}
cairo_context& context_; cairo_context& context_;
}; };
@ -71,11 +68,7 @@ class MAPNIK_DECL cairo_renderer : public feature_style_processor<cairo_renderer
{ {
public: public:
using processor_impl_type = cairo_renderer<T>; using processor_impl_type = cairo_renderer<T>;
cairo_renderer(Map const& m, cairo_renderer(Map const& m, T const& obj, double scale_factor = 1.0, unsigned offset_x = 0, unsigned offset_y = 0);
T const& obj,
double scale_factor=1.0,
unsigned offset_x=0,
unsigned offset_y=0);
cairo_renderer(Map const& m, cairo_renderer(Map const& m,
request const& req, request const& req,
attributes const& vars, attributes const& vars,
@ -97,80 +90,44 @@ public:
void end_layer_processing(layer const& lay); void end_layer_processing(layer const& lay);
void start_style_processing(feature_type_style const& st); void start_style_processing(feature_type_style const& st);
void end_style_processing(feature_type_style const& st); void end_style_processing(feature_type_style const& st);
void process(point_symbolizer const& sym, void process(point_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(line_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(line_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_symbolizer const& sym, void process(polygon_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(polygon_pattern_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(raster_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(line_pattern_symbolizer const& sym, void process(shield_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(text_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(building_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_symbolizer const& sym, void process(markers_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
mapnik::feature_impl & feature, void process(group_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
proj_transform const& prj_trans); void process(debug_symbolizer const& sym, mapnik::feature_impl& feature, proj_transform const& prj_trans);
void process(polygon_pattern_symbolizer const& sym, inline bool
mapnik::feature_impl & feature, process(rule::symbolizers const& /*syms*/, mapnik::feature_impl& /*feature*/, proj_transform const& /*prj_trans*/)
proj_transform const& prj_trans);
void process(raster_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(shield_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(building_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(markers_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(group_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(debug_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
inline bool process(rule::symbolizers const& /*syms*/,
mapnik::feature_impl & /*feature*/,
proj_transform const& /*prj_trans*/)
{ {
// cairo renderer doesn't support processing of multiple symbolizers. // cairo renderer doesn't support processing of multiple symbolizers.
return false; return false;
} }
bool painted() bool painted() { return true; }
{
return true;
}
void painted(bool /*painted*/) void painted(bool /*painted*/)
{ {
// nothing to do // nothing to do
} }
inline eAttributeCollectionPolicy attribute_collection_policy() const inline eAttributeCollectionPolicy attribute_collection_policy() const { return DEFAULT; }
{
return DEFAULT;
}
inline double scale_factor() const inline double scale_factor() const { return common_.scale_factor_; }
{
return common_.scale_factor_;
}
inline attributes const& variables() const inline attributes const& variables() const { return common_.vars_; }
{
return common_.vars_;
}
void render_marker(pixel_position const& pos, void render_marker(pixel_position const& pos,
marker const& marker, marker const& marker,
agg::trans_affine const& mtx, agg::trans_affine const& mtx,
double opacity = 1.0, double opacity = 1.0,
bool recenter = true); bool recenter = true);
protected: protected:
Map const& m_; Map const& m_;
cairo_context context_; cairo_context context_;
@ -178,12 +135,11 @@ protected:
cairo_face_manager face_manager_; cairo_face_manager face_manager_;
bool style_level_compositing_; bool style_level_compositing_;
void setup(Map const& m); void setup(Map const& m);
}; };
extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>; extern template class MAPNIK_DECL cairo_renderer<cairo_ptr>;
} } // namespace mapnik
#endif // MAPNIK_CAIRO_RENDERER_HPP #endif // MAPNIK_CAIRO_RENDERER_HPP

View file

@ -36,10 +36,9 @@ namespace mapnik {
struct cairo_renderer_process_visitor_p struct cairo_renderer_process_visitor_p
{ {
cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, cairo_renderer_process_visitor_p(agg::trans_affine const& image_tr, double opacity)
double opacity) : image_tr_(image_tr)
: image_tr_(image_tr), , opacity_(opacity)
opacity_(opacity)
{} {}
cairo_surface_ptr operator()(marker_svg const& marker) const cairo_surface_ptr operator()(marker_svg const& marker) const
@ -50,9 +49,7 @@ struct cairo_renderer_process_visitor_p
double width = std::max(1.0, std::round(bbox.width())); double width = std::max(1.0, std::round(bbox.width()));
double height = std::max(1.0, std::round(bbox.height())); double height = std::max(1.0, std::round(bbox.height()));
cairo_rectangle_t extent{0, 0, width, height}; cairo_rectangle_t extent{0, 0, width, height};
cairo_surface_ptr surface( cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer()); cairo_surface_closer());
cairo_ptr cairo = create_context(surface); cairo_ptr cairo = create_context(surface);
@ -60,12 +57,10 @@ struct cairo_renderer_process_visitor_p
svg_storage_type& svg = *marker.get_data(); svg_storage_type& svg = *marker.get_data();
svg_attribute_type const& svg_attributes = svg.attributes(); svg_attribute_type const& svg_attributes = svg.attributes();
svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage( svg::vertex_stl_adapter<svg::svg_path_storage> stl_storage(svg.source());
svg.source());
svg::svg_path_adapter svg_path(stl_storage); svg::svg_path_adapter svg_path(stl_storage);
render_vector_marker(context, svg_path, svg_attributes, render_vector_marker(context, svg_path, svg_attributes, bbox, tr, opacity_);
bbox, tr, opacity_);
return surface; return surface;
} }
@ -76,9 +71,7 @@ struct cairo_renderer_process_visitor_p
agg::trans_affine tr(transform(bbox)); agg::trans_affine tr(transform(bbox));
cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()}; cairo_rectangle_t extent{0, 0, bbox.width(), bbox.height()};
cairo_surface_ptr surface( cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, &extent),
cairo_surface_closer()); cairo_surface_closer());
cairo_ptr cairo = create_context(surface); cairo_ptr cairo = create_context(surface);
@ -91,9 +84,7 @@ struct cairo_renderer_process_visitor_p
cairo_surface_ptr operator()(marker_null const&) const cairo_surface_ptr operator()(marker_null const&) const
{ {
cairo_surface_ptr surface( cairo_surface_ptr surface(cairo_recording_surface_create(CAIRO_CONTENT_COLOR_ALPHA, nullptr),
cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, nullptr),
cairo_surface_closer()); cairo_surface_closer());
cairo_ptr cairo = create_context(surface); cairo_ptr cairo = create_context(surface);
cairo_context context(cairo); cairo_context context(cairo);
@ -105,9 +96,7 @@ private:
{ {
bbox *= image_tr_; bbox *= image_tr_;
coord<double, 2> c = bbox.center(); coord<double, 2> c = bbox.center();
agg::trans_affine mtx = agg::trans_affine_translation( agg::trans_affine mtx = agg::trans_affine_translation(0.5 * bbox.width() - c.x, 0.5 * bbox.height() - c.y);
0.5 * bbox.width() - c.x,
0.5 * bbox.height() - c.y);
return image_tr_ * mtx; return image_tr_ * mtx;
} }
@ -143,19 +132,20 @@ struct cairo_polygon_pattern : cairo_pattern_base
symbolizer_base const& sym, symbolizer_base const& sym,
mapnik::feature_impl const& feature, mapnik::feature_impl const& feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
: cairo_pattern_base{marker, common, sym, feature, prj_trans}, : cairo_pattern_base{marker, common, sym, feature, prj_trans}
clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_)), , clip_(get<value_bool, keys::clip>(sym_, feature_, common_.vars_))
clip_box_(clipping_extent(common)), , clip_box_(clipping_extent(common))
tr_(geom_transform()), , tr_(geom_transform())
converter_(clip_box_, sym, common.t_, prj_trans, tr_, , converter_(clip_box_, sym, common.t_, prj_trans, tr_, feature, common.vars_, common.scale_factor_)
feature, common.vars_, common.scale_factor_)
{ {
value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_); value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_); value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);
converter_.template set<affine_transform_tag>(); converter_.template set<affine_transform_tag>();
if (simplify_tolerance > 0.0) converter_.template set<simplify_tag>(); if (simplify_tolerance > 0.0)
if (smooth > 0.0) converter_.template set<smooth_tag>(); converter_.template set<simplify_tag>();
if (smooth > 0.0)
converter_.template set<smooth_tag>();
} }
void render(cairo_fill_rule_t fill_rule, cairo_context& context) void render(cairo_fill_rule_t fill_rule, cairo_context& context)
@ -181,8 +171,12 @@ struct cairo_polygon_pattern : cairo_pattern_base
cairo_rectangle_t pattern_surface_extent; cairo_rectangle_t pattern_surface_extent;
if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent)) if (cairo_recording_surface_get_extents(surface.get(), &pattern_surface_extent))
{ {
offset = pattern_offset(sym_, feature_, prj_trans_, common_, offset = pattern_offset(sym_,
pattern_surface_extent.width, pattern_surface_extent.height); feature_,
prj_trans_,
common_,
pattern_surface_extent.width,
pattern_surface_extent.height);
} }
cairo_pattern pattern(surface); cairo_pattern pattern(surface);
@ -207,5 +201,4 @@ struct cairo_polygon_pattern : cairo_pattern_base
} // namespace mapnik } // namespace mapnik
#endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP #endif // MAPNIK_CAIRO_RENDER_POLYGON_PATTERN_HPP

View file

@ -44,6 +44,6 @@ MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map,
double scale_denominator = 0.0); double scale_denominator = 0.0);
#endif #endif
} // end ns } // namespace mapnik
#endif // MAPNIK_CAIRO_IO_HPP #endif // MAPNIK_CAIRO_IO_HPP

View file

@ -50,44 +50,50 @@ public:
// default ctor // default ctor
color() color()
: red_(0xff), : red_(0xff)
green_(0xff), , green_(0xff)
blue_(0xff), , blue_(0xff)
alpha_(0xff), , alpha_(0xff)
premultiplied_(false) , premultiplied_(false)
{} {}
color(std::uint8_t _red, std::uint8_t _green, std::uint8_t _blue, std::uint8_t _alpha = 0xff, bool premultiplied = false) color(std::uint8_t _red,
: red_(_red), std::uint8_t _green,
green_(_green), std::uint8_t _blue,
blue_(_blue), std::uint8_t _alpha = 0xff,
alpha_(_alpha), bool premultiplied = false)
premultiplied_(premultiplied) : red_(_red)
, green_(_green)
, blue_(_blue)
, alpha_(_alpha)
, premultiplied_(premultiplied)
{} {}
color(std::uint32_t _rgba, bool premultiplied = false) color(std::uint32_t _rgba, bool premultiplied = false)
: red_(_rgba & 0xff), : red_(_rgba & 0xff)
green_((_rgba >> 8) & 0xff), , green_((_rgba >> 8) & 0xff)
blue_((_rgba >> 16) & 0xff), , blue_((_rgba >> 16) & 0xff)
alpha_((_rgba >> 24) & 0xff), , alpha_((_rgba >> 24) & 0xff)
premultiplied_(premultiplied) {} , premultiplied_(premultiplied)
{}
// copy ctor // copy ctor
color(const color& rhs) color(const color& rhs)
: red_(rhs.red_), : red_(rhs.red_)
green_(rhs.green_), , green_(rhs.green_)
blue_(rhs.blue_), , blue_(rhs.blue_)
alpha_(rhs.alpha_), , alpha_(rhs.alpha_)
premultiplied_(rhs.premultiplied_) , premultiplied_(rhs.premultiplied_)
{} {}
// move ctor // move ctor
color(color&& rhs) color(color&& rhs)
: red_(std::move(rhs.red_)), : red_(std::move(rhs.red_))
green_(std::move(rhs.green_)), , green_(std::move(rhs.green_))
blue_(std::move(rhs.blue_)), , blue_(std::move(rhs.blue_))
alpha_(std::move(rhs.alpha_)), , alpha_(std::move(rhs.alpha_))
premultiplied_(std::move(rhs.premultiplied_)) {} , premultiplied_(std::move(rhs.premultiplied_))
{}
color(std::string const& str, bool premultiplied = false); color(std::string const& str, bool premultiplied = false);
@ -104,64 +110,32 @@ public:
inline bool operator==(color const& rhs) const inline bool operator==(color const& rhs) const
{ {
return (red_== rhs.red_) && return (red_ == rhs.red_) && (green_ == rhs.green_) && (blue_ == rhs.blue_) && (alpha_ == rhs.alpha_) &&
(green_ == rhs.green_) &&
(blue_ == rhs.blue_) &&
(alpha_ == rhs.alpha_) &&
(premultiplied_ == rhs.premultiplied_); (premultiplied_ == rhs.premultiplied_);
} }
inline std::uint8_t red() const inline std::uint8_t red() const { return red_; }
{
return red_;
}
inline std::uint8_t green() const inline std::uint8_t green() const { return green_; }
{
return green_;
}
inline std::uint8_t blue() const inline std::uint8_t blue() const { return blue_; }
{
return blue_;
}
inline std::uint8_t alpha() const inline std::uint8_t alpha() const { return alpha_; }
{
return alpha_;
}
inline void set_red(std::uint8_t _red) inline void set_red(std::uint8_t _red) { red_ = _red; }
{
red_ = _red;
}
inline void set_green(std::uint8_t _green) inline void set_green(std::uint8_t _green) { green_ = _green; }
{
green_ = _green;
}
inline void set_blue(std::uint8_t _blue) inline void set_blue(std::uint8_t _blue) { blue_ = _blue; }
{ inline void set_alpha(std::uint8_t _alpha) { alpha_ = _alpha; }
blue_ = _blue; inline bool get_premultiplied() const { return premultiplied_; }
} inline void set_premultiplied(bool val) { premultiplied_ = val; }
inline void set_alpha(std::uint8_t _alpha)
{
alpha_ = _alpha;
}
inline bool get_premultiplied() const
{
return premultiplied_;
}
inline void set_premultiplied(bool val)
{
premultiplied_ = val;
}
inline unsigned rgba() const inline unsigned rgba() const
{ {
return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_)); return static_cast<unsigned>((alpha_ << 24) | (blue_ << 16) | (green_ << 8) | (red_));
} }
private: private:
void swap(color& rhs) void swap(color& rhs)
{ {
@ -174,8 +148,7 @@ private:
}; };
template<typename charT, typename traits> template<typename charT, typename traits>
std::basic_ostream<charT, traits> & std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, mapnik::color const& c)
operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
{ {
s << c.to_string(); s << c.to_string();
return s; return s;
@ -187,6 +160,6 @@ inline std::size_t hash_value(color const& c)
return c.rgba(); return c.rgba();
} }
} } // namespace mapnik
#endif // MAPNIK_COLOR_HPP #endif // MAPNIK_COLOR_HPP

View file

@ -47,6 +47,14 @@
#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE #pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE
#endif #endif
#else #else
#define MAPNIK_DECL __declspec(dllimport)
#endif
#pragma warning(disable: 4251)
#pragma warning(disable: 4275)
#if (_MSC_VER >= 1400) // vc8
#pragma warning(disable: 4996) //_CRT_SECURE_NO_DEPRECATE
#endif
#else
#if __GNUC__ >= 4 #if __GNUC__ >= 4
#define MAPNIK_EXP __attribute__((visibility("default"))) #define MAPNIK_EXP __attribute__((visibility("default")))
#define MAPNIK_DECL __attribute__((visibility("default"))) #define MAPNIK_DECL __attribute__((visibility("default")))

View file

@ -36,16 +36,14 @@ class config_error : public std::exception
{ {
public: public:
config_error(std::string const& what); config_error(std::string const& what);
config_error(std::string const& what, config_error(std::string const& what, xml_node const& node);
xml_node const& node); config_error(std::string const& what, unsigned line_number, std::string const& filename);
config_error(std::string const& what,
unsigned line_number,
std::string const& filename);
virtual ~config_error() {} virtual ~config_error() {}
virtual const char* what() const noexcept; virtual const char* what() const noexcept;
void append_context(std::string const& ctx) const; void append_context(std::string const& ctx) const;
void append_context(std::string const& ctx, xml_node const& node) const; void append_context(std::string const& ctx, xml_node const& node) const;
void append_context(xml_node const& node) const; void append_context(xml_node const& node) const;
protected: protected:
mutable std::string what_; mutable std::string what_;
mutable unsigned line_number_; mutable unsigned line_number_;
@ -54,6 +52,6 @@ protected:
mutable std::string msg_; mutable std::string msg_;
}; };
} } // namespace mapnik
#endif // MAPNIK_CONFIG_ERROR_HPP #endif // MAPNIK_CONFIG_ERROR_HPP

View file

@ -31,41 +31,53 @@ MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace mapnik {
template<typename T, int dim> template<typename T, int dim>
struct coord { struct coord
{
using type = T; using type = T;
}; };
template<typename T> template<typename T>
struct coord<T, 2> struct coord<T, 2>
: boost::addable<coord<T,2>, : boost::addable<
boost::addable2<coord<T,2>,T, coord<T, 2>,
boost::subtractable<coord<T,2>, boost::addable2<
boost::subtractable2<coord<T,2>,T, coord<T, 2>,
boost::dividable2<coord<T,2>, T, T,
boost::multipliable2<coord<T,2>, T > > > > > > boost::subtractable<
coord<T, 2>,
boost::
subtractable2<coord<T, 2>, T, boost::dividable2<coord<T, 2>, T, boost::multipliable2<coord<T, 2>, T>>>>>>
{ {
using type = T; using type = T;
T x; T x;
T y; T y;
public: public:
coord() coord()
: x(),y() {} : x()
, y()
{}
coord(T x_, T y_) coord(T x_, T y_)
: x(x_),y(y_) {} : x(x_)
, y(y_)
{}
coord(coord<T, 2> const& rhs) coord(coord<T, 2> const& rhs)
: x(rhs.x), : x(rhs.x)
y(rhs.y) {} , y(rhs.y)
{}
template<typename T2> template<typename T2>
coord(coord<T2, 2> const& rhs) coord(coord<T2, 2> const& rhs)
: x(type(rhs.x)), : x(type(rhs.x))
y(type(rhs.y)) {} , y(type(rhs.y))
{}
coord(coord<T, 2>&& rhs) noexcept coord(coord<T, 2>&& rhs) noexcept
: x(std::move(rhs.x)), : x(std::move(rhs.x))
y(std::move(rhs.y)) {} , y(std::move(rhs.y))
{}
coord<T, 2>& operator=(coord<T, 2> rhs) coord<T, 2>& operator=(coord<T, 2> rhs)
{ {
@ -127,6 +139,7 @@ public:
y /= t; y /= t;
return *this; return *this;
} }
private: private:
void swap(coord<T, 2>& rhs) void swap(coord<T, 2>& rhs)
{ {
@ -142,22 +155,31 @@ struct coord<T,3>
T x; T x;
T y; T y;
T z; T z;
public: public:
coord() coord()
: x(),y(),z() {} : x()
, y()
, z()
{}
coord(T x_, T y_, T z_) coord(T x_, T y_, T z_)
: x(x_),y(y_),z(z_) {} : x(x_)
, y(y_)
, z(z_)
{}
template<typename T2> template<typename T2>
coord(coord<T2, 3> const& rhs) coord(coord<T2, 3> const& rhs)
: x(type(rhs.x)), : x(type(rhs.x))
y(type(rhs.y)), , y(type(rhs.y))
z(type(rhs.z)) {} , z(type(rhs.z))
{}
coord(coord<T, 3>&& rhs) noexcept coord(coord<T, 3>&& rhs) noexcept
: x(std::move(rhs.x)), : x(std::move(rhs.x))
y(std::move(rhs.y)), , y(std::move(rhs.y))
z(std::move(rhs.z)) {} , z(std::move(rhs.z))
{}
coord<T, 3> operator=(coord<T, 3> rhs) coord<T, 3> operator=(coord<T, 3> rhs)
{ {
@ -172,6 +194,7 @@ public:
swap(tmp); swap(tmp);
return *this; return *this;
} }
private: private:
void swap(coord<T, 3>& rhs) void swap(coord<T, 3>& rhs)
{ {
@ -185,6 +208,6 @@ using coord2d = coord<double,2>;
using coord2f = coord<float, 2>; using coord2f = coord<float, 2>;
using coord2i = coord<int, 2>; using coord2i = coord<int, 2>;
} } // namespace mapnik
#endif // MAPNIK_COORD_HPP #endif // MAPNIK_COORD_HPP

View file

@ -31,13 +31,11 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace css_color_grammar namespace css_color_grammar {
{
struct css_color_class; struct css_color_class;
using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>; using css_color_grammar_type = x3::rule<css_color_class, mapnik::color>;
@ -46,6 +44,7 @@ css_color_grammar_type const css_color = "css_color";
BOOST_SPIRIT_DECLARE(css_color_grammar_type); BOOST_SPIRIT_DECLARE(css_color_grammar_type);
}} } // namespace css_color_grammar
} // namespace mapnik
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP #endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_HPP

View file

@ -37,13 +37,8 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/fusion/adapted/std_tuple.hpp> #include <boost/fusion/adapted/std_tuple.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
BOOST_FUSION_ADAPT_STRUCT ( BOOST_FUSION_ADAPT_STRUCT(mapnik::color,
mapnik::color, (std::uint8_t, red_)(std::uint8_t, green_)(std::uint8_t, blue_)(std::uint8_t, alpha_))
(std::uint8_t, red_)
(std::uint8_t, green_)
(std::uint8_t, blue_)
(std::uint8_t, alpha_)
)
namespace mapnik { namespace mapnik {
@ -51,20 +46,21 @@ namespace x3 = boost::spirit::x3;
namespace css_color_grammar { namespace css_color_grammar {
using x3::lit;
using x3::uint_parser;
using x3::hex;
using x3::symbols;
using x3::omit;
using x3::attr; using x3::attr;
using x3::double_; using x3::double_;
using x3::hex;
using x3::lit;
using x3::no_case; using x3::no_case;
using x3::no_skip; using x3::no_skip;
using x3::omit;
using x3::symbols;
using x3::uint_parser;
struct named_colors_ : x3::symbols<color> struct named_colors_ : x3::symbols<color>
{ {
named_colors_() named_colors_()
{ {
// clang-format off
add add
("aliceblue", color(240, 248, 255)) ("aliceblue", color(240, 248, 255))
("antiquewhite", color(250, 235, 215)) ("antiquewhite", color(250, 235, 215))
@ -216,6 +212,7 @@ struct named_colors_ : x3::symbols<color>
("yellowgreen", color(154, 205, 50)) ("yellowgreen", color(154, 205, 50))
("transparent", color(0, 0, 0, 0)) ("transparent", color(0, 0, 0, 0))
; ;
// clang-format on
} }
} named_colors; } named_colors;
@ -235,97 +232,80 @@ struct clip_opacity
{ {
static double call(double val) static double call(double val)
{ {
if (val > 1.0) return 1.0; if (val > 1.0)
if (val < 0.0) return 0.0; return 1.0;
if (val < 0.0)
return 0.0;
return val; return val;
} }
}; };
struct percent_converter struct percent_converter
{ {
static std::uint8_t call(double val) static std::uint8_t call(double val) { return safe_cast<std::uint8_t>(std::lround((255.0 * val) / 100.0)); }
{
return safe_cast<std::uint8_t>(std::lround((255.0 * val)/100.0));
}
}; };
auto dec_red = [](auto& ctx) auto dec_red = [](auto& ctx) {
{
_val(ctx).red_ = _attr(ctx); _val(ctx).red_ = _attr(ctx);
}; };
auto dec_green = [](auto& ctx) auto dec_green = [](auto& ctx) {
{
_val(ctx).green_ = _attr(ctx); _val(ctx).green_ = _attr(ctx);
}; };
auto dec_blue = [](auto& ctx) auto dec_blue = [](auto& ctx) {
{
_val(ctx).blue_ = _attr(ctx); _val(ctx).blue_ = _attr(ctx);
}; };
auto opacity = [](auto& ctx) auto opacity = [](auto& ctx) {
{
_val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5); _val(ctx).alpha_ = uint8_t((255.0 * clip_opacity::call(_attr(ctx))) + 0.5);
}; };
auto percent_red = [] (auto & ctx) auto percent_red = [](auto& ctx) {
{
_val(ctx).red_ = percent_converter::call(_attr(ctx)); _val(ctx).red_ = percent_converter::call(_attr(ctx));
}; };
auto percent_green = [] (auto & ctx) auto percent_green = [](auto& ctx) {
{
_val(ctx).green_ = percent_converter::call(_attr(ctx)); _val(ctx).green_ = percent_converter::call(_attr(ctx));
}; };
auto percent_blue = [] (auto & ctx) auto percent_blue = [](auto& ctx) {
{
_val(ctx).blue_ = percent_converter::call(_attr(ctx)); _val(ctx).blue_ = percent_converter::call(_attr(ctx));
}; };
auto hex1_red = [](auto& ctx) auto hex1_red = [](auto& ctx) {
{
_val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).red_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex1_green = [](auto& ctx) auto hex1_green = [](auto& ctx) {
{
_val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).green_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex1_blue = [](auto& ctx) auto hex1_blue = [](auto& ctx) {
{
_val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).blue_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex1_opacity = [](auto& ctx) auto hex1_opacity = [](auto& ctx) {
{
_val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4; _val(ctx).alpha_ = _attr(ctx) | _attr(ctx) << 4;
}; };
auto hex2_red = [](auto& ctx) auto hex2_red = [](auto& ctx) {
{
_val(ctx).red_ = _attr(ctx); _val(ctx).red_ = _attr(ctx);
}; };
auto hex2_green = [](auto& ctx) auto hex2_green = [](auto& ctx) {
{
_val(ctx).green_ = _attr(ctx); _val(ctx).green_ = _attr(ctx);
}; };
auto hex2_blue = [](auto& ctx) auto hex2_blue = [](auto& ctx) {
{
_val(ctx).blue_ = _attr(ctx); _val(ctx).blue_ = _attr(ctx);
}; };
auto hex2_opacity = [](auto& ctx) auto hex2_opacity = [](auto& ctx) {
{
_val(ctx).alpha_ = _attr(ctx); _val(ctx).alpha_ = _attr(ctx);
}; };
auto hsl_to_rgba = [] (auto& ctx) auto hsl_to_rgba = [](auto& ctx) {
{
double h = std::get<0>(_attr(ctx)); double h = std::get<0>(_attr(ctx));
double s = std::get<1>(_attr(ctx)); double s = std::get<1>(_attr(ctx));
double l = std::get<2>(_attr(ctx)); double l = std::get<2>(_attr(ctx));
@ -354,7 +334,7 @@ auto hsl_to_rgba = [] (auto& ctx)
safe_cast<uint8_t>(std::lround(255.0 * b)), safe_cast<uint8_t>(std::lround(255.0 * b)),
alpha); alpha);
}; };
// clang-format off
auto const hex2_color_def = no_skip[lit('#') auto const hex2_color_def = no_skip[lit('#')
>> hex2[hex2_red] >> hex2[hex2_red]
>> hex2[hex2_green] >> hex2[hex2_green]
@ -429,21 +409,13 @@ auto const css_color_def =
| |
hsla_color hsla_color
; ;
// clang-format on
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
BOOST_SPIRIT_DEFINE( BOOST_SPIRIT_DEFINE(css_color, hex2_color, hex1_color, rgb_color, rgba_color, rgb_color_percent, rgba_color_percent);
css_color,
hex2_color,
hex1_color,
rgb_color,
rgba_color,
rgb_color_percent,
rgba_color_percent
);
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
} // ns } // namespace css_color_grammar
} //ns mapnik } // namespace mapnik
#endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSS_COLOR_GRAMMAR_X3_DEF_HPP

View file

@ -31,8 +31,7 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik namespace mapnik {
{
using property_value_type = boost::iterator_range<char const*>; using property_value_type = boost::iterator_range<char const*>;
using css_key_value = std::pair<std::string, property_value_type>; using css_key_value = std::pair<std::string, property_value_type>;
using definition_type = std::vector<css_key_value>; using definition_type = std::vector<css_key_value>;
@ -40,8 +39,7 @@ using css_data = std::unordered_multimap<std::string, definition_type>;
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace css_grammar namespace css_grammar {
{
class css_tag; class css_tag;
class ident_tag; class ident_tag;
@ -58,17 +56,14 @@ css_grammar_type const css_grammar{"css"};
css_skipper_type const css_skipper{"css skipper"}; css_skipper_type const css_skipper{"css skipper"};
css_classes_type const css_classes{"css classes"}; css_classes_type const css_classes{"css classes"};
BOOST_SPIRIT_DECLARE(ident_grammar_type, BOOST_SPIRIT_DECLARE(ident_grammar_type, css_classes_type, css_grammar_type, css_skipper_type);
css_classes_type,
css_grammar_type,
css_skipper_type);
} } // namespace css_grammar
css_grammar::ident_grammar_type const ident_grammar(); css_grammar::ident_grammar_type const ident_grammar();
css_grammar::css_classes_type const classes(); css_grammar::css_classes_type const classes();
css_grammar::css_grammar_type const grammar(); css_grammar::css_grammar_type const grammar();
css_grammar::css_skipper_type const skipper(); css_grammar::css_skipper_type const skipper();
} } // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_HPP #endif // MAPNIK_CSS_GRAMMAR_X3_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #ifndef MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
#define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #define MAPNIK_CSS_GRAMMAR_X3_DEF_HPP
@ -33,9 +32,10 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/fusion/adapted/std_pair.hpp> #include <boost/fusion/adapted/std_pair.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
/* /*
The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand notation beyond yacc [15] is used: The grammar below is LL(1) (but note that most UA's should not use it directly, since it doesn't express the parsing
conventions, only the CSS1 syntax). The format of the productions is optimized for human consumption and some shorthand
notation beyond yacc [15] is used:
* : 0 or more * : 0 or more
+ : 1 or more + : 1 or more
@ -148,34 +148,36 @@ namespace x3 = boost::spirit::x3;
namespace css_grammar { namespace css_grammar {
using x3::lit; using x3::alnum;
using x3::alpha;
using x3::attr; using x3::attr;
using x3::char_;
using x3::lexeme;
using x3::lit;
using x3::no_case; using x3::no_case;
using x3::no_skip; using x3::no_skip;
using x3::lexeme;
using x3::alpha;
using x3::alnum;
using x3::char_;
using x3::raw; using x3::raw;
using x3::standard::space; using x3::standard::space;
// import unicode string rule // import unicode string rule
namespace { auto const& css_string = mapnik::json::grammar::unicode_string; } namespace {
auto const& css_string = mapnik::json::grammar::unicode_string;
}
auto assign_def = [] (auto const& ctx) auto assign_def = [](auto const& ctx) {
{
for (auto const& k : std::get<0>(_attr(ctx))) for (auto const& k : std::get<0>(_attr(ctx)))
{ {
_val(ctx).emplace(k, std::get<1>(_attr(ctx))); _val(ctx).emplace(k, std::get<1>(_attr(ctx)));
} }
}; };
auto assign_key = [] (auto const& ctx) auto assign_key = [](auto const& ctx) {
{
_val(ctx).first = std::move(_attr(ctx)); _val(ctx).first = std::move(_attr(ctx));
}; };
auto assign_value = [] (auto const& ctx) {_val(ctx).second = std::move(_attr(ctx));}; auto assign_value = [](auto const& ctx) {
_val(ctx).second = std::move(_attr(ctx));
};
// rules // rules
x3::rule<class simple_selector_tag, std::string> const simple_selector{"Simple selector"}; x3::rule<class simple_selector_tag, std::string> const simple_selector{"Simple selector"};
@ -185,9 +187,9 @@ x3::rule<class key_value_tag, css_key_value> const key_value {"CSS Key/Value"};
x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"}; x3::rule<class definition_tag, std::pair<std::vector<std::string>, definition_type>> const definition{"CSS Definition"};
auto const ident_def = alpha >> *(alnum | char_('-')); auto const ident_def = alpha >> *(alnum | char_('-'));
auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] auto const simple_selector_def = lexeme[ident >> -((char_('.') | char_('#') | char_(':')) >> ident)] |
| lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] lexeme[char_('#') >> ident >> -((char_('.') | char_(':')) >> ident)] |
| lexeme[char_('.') >> ident >> -(char_(':') >> ident)]; lexeme[char_('.') >> ident >> -(char_(':') >> ident)];
auto const selector_def = simple_selector % lit(','); auto const selector_def = simple_selector % lit(',');
auto const value_def = raw[lexeme[+~char_(";}")]]; auto const value_def = raw[lexeme[+~char_(";}")]];
@ -202,8 +204,7 @@ auto const css_classes_def = +lexeme[ident];
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp> #include <mapnik/warning_ignore.hpp>
BOOST_SPIRIT_DEFINE( BOOST_SPIRIT_DEFINE(ident,
ident,
css_classes, css_classes,
simple_selector, simple_selector,
selector, selector,
@ -211,12 +212,11 @@ BOOST_SPIRIT_DEFINE(
key_value, key_value,
definition, definition,
css_grammar, css_grammar,
css_skipper css_skipper);
);
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
} //css_grammar } // namespace css_grammar
} //mapnik } // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#ifndef MAPNIK_CSS_UNIT_VALUE_HPP #ifndef MAPNIK_CSS_UNIT_VALUE_HPP
#define MAPNIK_CSS_UNIT_VALUE_HPP #define MAPNIK_CSS_UNIT_VALUE_HPP
@ -36,7 +35,7 @@ struct css_unit_value : x3::symbols<double>
constexpr static double DPI = 96; constexpr static double DPI = 96;
css_unit_value() css_unit_value()
{ {
add add //
("px", 1.0) // pixels ("px", 1.0) // pixels
("pt", DPI / 72.0) // points ("pt", DPI / 72.0) // points
("pc", DPI / 6.0) // picas ("pc", DPI / 6.0) // picas
@ -53,14 +52,14 @@ struct css_absolute_size : x3::symbols<double>
constexpr static double EM = 10.0; // 1em == 10px constexpr static double EM = 10.0; // 1em == 10px
css_absolute_size() css_absolute_size()
{ {
add add //
("xx-small", 0.6 * EM) ("xx-small", 0.6 * EM) //
("x-small", 0.75 * EM) ("x-small", 0.75 * EM) //
("small", 0.88 * EM) ("small", 0.88 * EM) //
("medium", 1.0 * EM) ("medium", 1.0 * EM) //
("large", 1.2 * EM) ("large", 1.2 * EM) //
("x-large", 1.5 * EM) ("x-large", 1.5 * EM) //
("xx-large", 2.0 * EM) ("xx-large", 2.0 * EM) //
; ;
} }
}; };
@ -69,13 +68,12 @@ struct css_relative_size : x3::symbols<double>
{ {
css_relative_size() css_relative_size()
{ {
add add //
("larger", 1.2) ("larger", 1.2) //
("smaller", 0.8) ("smaller", 0.8);
;
} }
}; };
} //mapnik } // namespace mapnik
#endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSS_GRAMMAR_X3_DEF_HPP

View file

@ -36,8 +36,7 @@ struct csv_white_space_skipper : x3::parser<csv_white_space_skipper>
static bool const has_attribute = false; static bool const has_attribute = false;
template<typename Iterator, typename Context, typename Attribute> template<typename Iterator, typename Context, typename Attribute>
bool parse(Iterator& first, Iterator const& last, bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
Context const& context, x3::unused_type, Attribute& ) const
{ {
x3::skip_over(first, last, context); x3::skip_over(first, last, context);
if (first != last && *first == ' ') if (first != last && *first == ' ')
@ -64,6 +63,7 @@ csv_line_grammar_type const line = "csv-line";
BOOST_SPIRIT_DECLARE(csv_line_grammar_type); BOOST_SPIRIT_DECLARE(csv_line_grammar_type);
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_CSV_GRAMMAR_X3_HPP #endif // MAPNIK_CSV_GRAMMAR_X3_HPP

View file

@ -29,30 +29,30 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/csv/csv_grammar_x3.hpp> #include <mapnik/csv/csv_grammar_x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik {
namespace mapnik { namespace grammar { namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace standard = boost::spirit::x3::standard; namespace standard = boost::spirit::x3::standard;
using x3::lit;
using x3::lexeme;
using standard::char_; using standard::char_;
using x3::lexeme;
using x3::lit;
struct unesc_char_ : x3::symbols<char> struct unesc_char_ : x3::symbols<char>
{ {
unesc_char_() unesc_char_()
{ {
add("\\a", '\a') add("\\a", '\a') //
("\\b", '\b') ("\\b", '\b') //
("\\f", '\f') ("\\f", '\f') //
("\\n", '\n') ("\\n", '\n') //
("\\r", '\r') ("\\r", '\r') //
("\\t", '\t') ("\\t", '\t') //
("\\v", '\v') ("\\v", '\v') //
("\\\\",'\\') ("\\\\", '\\') //
("\\\'", '\'') ("\\\'", '\'') //
("\\\"", '\"') ("\\\"", '\"') //
("\"\"", '\"') // double quote ("\"\"", '\"') // double quote
; ;
} }
@ -66,8 +66,7 @@ struct literal : x3::parser<literal<T>>
static bool const has_attribute = false; static bool const has_attribute = false;
template<typename Iterator, typename Context, typename Attribute> template<typename Iterator, typename Context, typename Attribute>
bool parse(Iterator& first, Iterator const& last, bool parse(Iterator& first, Iterator const& last, Context const& context, x3::unused_type, Attribute&) const
Context const& context, x3::unused_type, Attribute& ) const
{ {
x3::skip_over(first, last, context); x3::skip_over(first, last, context);
if (first != last && *first == x3::get<context_tag>(context)) if (first != last && *first == x3::get<context_tag>(context))
@ -87,27 +86,18 @@ x3::rule<class csv_column, csv_value> const column("csv-column");
x3::rule<class csv_text, csv_value> const text("csv-text"); x3::rule<class csv_text, csv_value> const text("csv-text");
x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text"); x3::rule<class csc_quoted_text, csv_value> const quoted_text("csv-quoted-text");
auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator auto const line_def = -lit('\r') > -lit('\n') > lexeme[column] % separator;
;
auto const column_def = quoted_text | *(char_ - separator) auto const column_def = quoted_text | *(char_ - separator);
;
auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??) auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??)
; ;
auto const text_def = *(unesc_char | (char_ - quote)) auto const text_def = *(unesc_char | (char_ - quote));
;
BOOST_SPIRIT_DEFINE ( BOOST_SPIRIT_DEFINE(line, column, quoted_text, text);
line,
column,
quoted_text,
text
);
} // grammar } // namespace grammar
} // namespace mapnik } // namespace mapnik
#endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_CSV_GRAMMAR_X3_DEF_HPP

View file

@ -32,6 +32,6 @@ using csv_value = std::string;
using csv_line = std::vector<csv_value>; using csv_line = std::vector<csv_value>;
using csv_data = std::vector<csv_line>; using csv_data = std::vector<csv_line>;
} } // namespace mapnik
#endif // MAPNIK_CSV_TYPES_HPP #endif // MAPNIK_CSV_TYPES_HPP

View file

@ -1,43 +0,0 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2021 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_CXX11_SUPPORT_HPP
#define MAPNIK_CXX11_SUPPORT_HPP
#include <type_traits>
namespace mapnik {
namespace detail {
template <bool B, typename T, typename F>
using conditional_t = typename std::conditional<B, T, F>::type;
template <typename T>
using decay_t = typename std::decay<T>::type;
template <bool B, typename T = void>
using enable_if_t = typename std::enable_if<B, T>::type;
} // namespace detail
} // namespace mapnik
#endif // MAPNIK_CXX11_SUPPORT_HPP

View file

@ -50,10 +50,8 @@ public:
~datasource_exception() {} ~datasource_exception() {}
virtual const char* what() const noexcept virtual const char* what() const noexcept { return message_.c_str(); }
{
return message_.c_str();
}
private: private:
std::string message_; std::string message_;
}; };
@ -61,13 +59,11 @@ private:
class MAPNIK_DECL datasource : private util::noncopyable class MAPNIK_DECL datasource : private util::noncopyable
{ {
public: public:
enum datasource_t : std::uint8_t { enum datasource_t : std::uint8_t { Vector, Raster };
Vector,
Raster
};
datasource(parameters const& _params) datasource(parameters const& _params)
: params_(_params) {} : params_(_params)
{}
/*! /*!
* @brief Get the configuration parameters of the data source. * @brief Get the configuration parameters of the data source.
@ -76,25 +72,13 @@ public:
* *
* @return The configuration parameters of the data source. * @return The configuration parameters of the data source.
*/ */
parameters const& params() const parameters const& params() const { return params_; }
{
return params_;
}
parameters & params() parameters& params() { return params_; }
{
return params_;
}
bool operator==(datasource const& rhs) const bool operator==(datasource const& rhs) const { return params_ == rhs.params(); }
{
return params_ == rhs.params();
}
bool operator!=(datasource const& rhs) const bool operator!=(datasource const& rhs) const { return !(*this == rhs); }
{
return !(*this == rhs);
}
/*! /*!
* @brief Get the type of the datasource * @brief Get the type of the datasource
@ -113,6 +97,7 @@ public:
virtual box2d<double> envelope() const = 0; virtual box2d<double> envelope() const = 0;
virtual layer_descriptor get_descriptor() const = 0; virtual layer_descriptor get_descriptor() const = 0;
virtual ~datasource() {} virtual ~datasource() {}
protected: protected:
parameters params_; parameters params_;
}; };
@ -124,32 +109,10 @@ using destroy_ds = void (*) (datasource *);
class datasource_deleter class datasource_deleter
{ {
public: public:
void operator() (datasource* ds) void operator()(datasource* ds) { delete ds; }
{
delete ds;
}
}; };
using datasource_ptr = std::shared_ptr<datasource>; using datasource_ptr = std::shared_ptr<datasource>;
} // namespace mapnik
#ifdef MAPNIK_STATIC_PLUGINS
#define DATASOURCE_PLUGIN(classname)
#else
#define DATASOURCE_PLUGIN(classname) \
extern "C" MAPNIK_DECL const char * datasource_name() \
{ \
return classname::name(); \
} \
extern "C" MAPNIK_DECL datasource* create(parameters const& params) \
{ \
return new classname(params); \
} \
extern "C" MAPNIK_DECL void destroy(datasource *ds) \
{ \
delete ds; \
}
#endif
}
#endif // MAPNIK_DATASOURCE_HPP #endif // MAPNIK_DATASOURCE_HPP

View file

@ -41,17 +41,18 @@ class datasource;
class parameters; class parameters;
class PluginInfo; class PluginInfo;
class MAPNIK_DECL datasource_cache class MAPNIK_DECL datasource_cache : public singleton<datasource_cache, CreateStatic>,
: public singleton<datasource_cache, CreateStatic>,
private util::noncopyable private util::noncopyable
{ {
friend class CreateStatic<datasource_cache>; friend class CreateStatic<datasource_cache>;
public: public:
std::vector<std::string> plugin_names(); std::vector<std::string> plugin_names();
std::string plugin_directories(); std::string plugin_directories();
bool register_datasources(std::string const& path, bool recurse = false); bool register_datasources(std::string const& path, bool recurse = false);
bool register_datasource(std::string const& path); bool register_datasource(std::string const& path);
std::shared_ptr<datasource> create(parameters const& params); std::shared_ptr<datasource> create(parameters const& params);
private: private:
datasource_cache(); datasource_cache();
~datasource_cache(); ~datasource_cache();
@ -66,6 +67,6 @@ private:
extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>; extern template class MAPNIK_DECL singleton<datasource_cache, CreateStatic>;
} } // namespace mapnik
#endif // MAPNIK_DATASOURCE_CACHE_HPP #endif // MAPNIK_DATASOURCE_CACHE_HPP

View file

@ -27,15 +27,8 @@
namespace mapnik { namespace mapnik {
enum datasource_geometry_t : std::uint8_t { enum datasource_geometry_t : std::uint8_t { Unknown = 0, Point = 1, LineString = 2, Polygon = 3, Collection = 4 };
Unknown = 0,
Point = 1,
LineString = 2,
Polygon = 3,
Collection = 4
};
} }
#endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP #endif // MAPNIK_DATASOURCE_GEOMETRY_TYPE_HPP

View file

@ -42,35 +42,21 @@
namespace mapnik { namespace mapnik {
// Global logger class that holds the configuration of severity, format // Global logger class that holds the configuration of severity, format
// and file/console redirection. // and file/console redirection.
class MAPNIK_DECL logger : class MAPNIK_DECL logger : public singleton<logger, CreateStatic>,
public singleton<logger,CreateStatic>,
private util::noncopyable private util::noncopyable
{ {
public: public:
enum severity_type enum severity_type { debug = 0, warn = 1, error = 2, none = 3 };
{
debug = 0,
warn = 1,
error = 2,
none = 3
};
using severity_map = std::unordered_map<std::string, severity_type>; using severity_map = std::unordered_map<std::string, severity_type>;
// global security level // global security level
static severity_type get_severity() static severity_type get_severity() { return severity_level_; }
{
return severity_level_;
}
static void set_severity(severity_type severity_level) static void set_severity(severity_type severity_level) { severity_level_ = severity_level; }
{
severity_level_ = severity_level;
}
// per object security levels // per object security levels
static severity_type get_object_severity(std::string const& object_name) static severity_type get_object_severity(std::string const& object_name)
@ -89,8 +75,7 @@ public:
} }
} }
static void set_object_severity(std::string const& object_name, static void set_object_severity(std::string const& object_name, severity_type const& security_level)
severity_type const& security_level)
{ {
if (!object_name.empty()) if (!object_name.empty())
{ {
@ -111,10 +96,7 @@ public:
} }
// format // format
static std::string const& get_format() static std::string const& get_format() { return format_; }
{
return format_;
}
static void set_format(std::string const& format) static void set_format(std::string const& format)
{ {
@ -151,7 +133,6 @@ private:
#endif #endif
}; };
namespace detail { namespace detail {
// Default sink, it regulates access to clog // Default sink, it regulates access to clog
@ -198,9 +179,7 @@ public:
} }
} }
#else #else
base_log(const char* /*object_name*/) base_log(const char* /*object_name*/) {}
{
}
#endif #endif
~base_log() ~base_log()
@ -217,32 +196,25 @@ public:
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG
base_log& operator<<(T const& x) base_log& operator<<(T const& x)
{ {
streambuf_ << x; streambuf_ << x;
return *this; return *this;
} }
#else #else
base_log& operator<<(T const& /*x*/) base_log& operator<<(T const& /*x*/)
{ {
return *this; return *this;
} }
#endif #endif
private: private:
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG
inline bool check_severity() inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
{
return Severity >= logger::get_object_severity(object_name_);
}
typename output_policy::stream_buffer streambuf_; typename output_policy::stream_buffer streambuf_;
std::string object_name_; std::string object_name_;
#endif #endif
}; };
// Base log class that always log, regardless of MAPNIK_LOG. // Base log class that always log, regardless of MAPNIK_LOG.
// This is used for error reporting that should always log something // This is used for error reporting that should always log something
@ -282,49 +254,56 @@ public:
} }
private: private:
inline bool check_severity() inline bool check_severity() { return Severity >= logger::get_object_severity(object_name_); }
{
return Severity >= logger::get_object_severity(object_name_);
}
typename output_policy::stream_buffer streambuf_; typename output_policy::stream_buffer streambuf_;
std::string object_name_; std::string object_name_;
}; };
using base_log_debug = base_log<clog_sink, logger::debug>; using base_log_debug = base_log<clog_sink, logger::debug>;
using base_log_warn = base_log<clog_sink, logger::warn>; using base_log_warn = base_log<clog_sink, logger::warn>;
using base_log_error = base_log_always<clog_sink, logger::error>; using base_log_error = base_log_always<clog_sink, logger::error>;
} // namespace detail } // namespace detail
// real interfaces // real interfaces
class MAPNIK_DECL warn : public detail::base_log_warn class MAPNIK_DECL warn : public detail::base_log_warn
{ {
public: public:
warn() : detail::base_log_warn() {} warn()
warn(const char* object_name) : detail::base_log_warn(object_name) {} : detail::base_log_warn()
{}
warn(const char* object_name)
: detail::base_log_warn(object_name)
{}
}; };
class MAPNIK_DECL debug : public detail::base_log_debug class MAPNIK_DECL debug : public detail::base_log_debug
{ {
public: public:
debug() : detail::base_log_debug() {} debug()
debug(const char* object_name) : detail::base_log_debug(object_name) {} : detail::base_log_debug()
{}
debug(const char* object_name)
: detail::base_log_debug(object_name)
{}
}; };
class MAPNIK_DECL error : public detail::base_log_error class MAPNIK_DECL error : public detail::base_log_error
{ {
public: public:
error() : detail::base_log_error() {} error()
error(const char* object_name) : detail::base_log_error(object_name) {} : detail::base_log_error()
{}
error(const char* object_name)
: detail::base_log_error(object_name)
{}
}; };
// logging helpers // logging helpers
#define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s) #define MAPNIK_LOG_DEBUG(s) mapnik::debug(#s)
#define MAPNIK_LOG_WARN(s) mapnik::warn(#s) #define MAPNIK_LOG_WARN(s) mapnik::warn(#s)
#define MAPNIK_LOG_ERROR(s) mapnik::error(#s) #define MAPNIK_LOG_ERROR(s) mapnik::error(#s)
} } // namespace mapnik
#endif // MAPNIK_DEBUG_HPP #endif // MAPNIK_DEBUG_HPP

View file

@ -39,25 +39,21 @@ namespace mapnik {
class illegal_enum_value : public std::exception class illegal_enum_value : public std::exception
{ {
public: public:
illegal_enum_value(): illegal_enum_value()
what_() {} : what_()
{}
illegal_enum_value( std::string const& _what ) : illegal_enum_value(std::string const& _what)
what_( _what ) : what_(_what)
{ {}
}
virtual ~illegal_enum_value() {} virtual ~illegal_enum_value() {}
virtual const char * what() const noexcept virtual const char* what() const noexcept { return what_.c_str(); }
{
return what_.c_str();
}
protected: protected:
std::string what_; std::string what_;
}; };
/** Slim wrapper for enumerations. It creates a new type from a native enum and /** Slim wrapper for enumerations. It creates a new type from a native enum and
* a char pointer array. It almost exactly behaves like a native enumeration * a char pointer array. It almost exactly behaves like a native enumeration
* type. It supports string conversion through stream operators. This is useful * type. It supports string conversion through stream operators. This is useful
@ -138,41 +134,33 @@ protected:
*/ */
template<typename ENUM, int THE_MAX> template<typename ENUM, int THE_MAX>
class MAPNIK_DECL enumeration { class MAPNIK_DECL enumeration
{
public: public:
using native_type = ENUM; using native_type = ENUM;
enumeration() enumeration()
: value_() {} : value_()
{}
enumeration(ENUM v) enumeration(ENUM v)
: value_(v) {} : value_(v)
{}
enumeration(enumeration const& other) enumeration(enumeration const& other)
: value_(other.value_) {} : value_(other.value_)
{}
/** Assignment operator for native enum values. */ /** Assignment operator for native enum values. */
void operator=(ENUM v) void operator=(ENUM v) { value_ = v; }
{
value_ = v;
}
/** Assignment operator. */ /** Assignment operator. */
void operator=(enumeration const& other) void operator=(enumeration const& other) { value_ = other.value_; }
{
value_ = other.value_;
}
/** Conversion operator for native enum values. */ /** Conversion operator for native enum values. */
operator ENUM() const operator ENUM() const { return value_; }
{
return value_;
}
enum Max enum Max { MAX = THE_MAX };
{
MAX = THE_MAX
};
/** Converts @p str to an enum. /** Converts @p str to an enum.
* @throw illegal_enum_value @p str is not a legal identifier. * @throw illegal_enum_value @p str is not a legal identifier.
@ -190,7 +178,6 @@ public:
} }
for (unsigned i = 0; i < THE_MAX; ++i) for (unsigned i = 0; i < THE_MAX; ++i)
{ {
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS MAPNIK_DISABLE_WARNING_PRAGMAS
@ -201,7 +188,10 @@ MAPNIK_DISABLE_WARNING_POP
value_ = static_cast<ENUM>(i); value_ = static_cast<ENUM>(i);
if (deprecated) if (deprecated)
{ {
MAPNIK_LOG_ERROR(enumerations) << "enumeration value (" << str << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy << "' instead"; MAPNIK_LOG_ERROR(enumerations)
<< "enumeration value (" << str
<< ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy
<< "' instead";
} }
return; return;
} }
@ -210,8 +200,7 @@ MAPNIK_DISABLE_WARNING_PUSH
MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS MAPNIK_DISABLE_WARNING_UNKNOWN_PRAGMAS
MAPNIK_DISABLE_WARNING_PRAGMAS MAPNIK_DISABLE_WARNING_PRAGMAS
MAPNIK_DISABLE_LONG_LONG MAPNIK_DISABLE_LONG_LONG
throw illegal_enum_value(std::string("Illegal enumeration value '") + throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_);
str + "' for enum " + our_name_);
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
} }
@ -227,10 +216,7 @@ MAPNIK_DISABLE_WARNING_POP
} }
/** Static helper function to iterate over valid identifiers. */ /** Static helper function to iterate over valid identifiers. */
static const char * get_string(unsigned i) static const char* get_string(unsigned i) { return our_strings_[i]; }
{
return our_strings_[i];
}
/** Performs some simple checks and quits the application if /** Performs some simple checks and quits the application if
* any error is detected. Tries to print helpful error messages. * any error is detected. Tries to print helpful error messages.
@ -241,16 +227,14 @@ MAPNIK_DISABLE_WARNING_POP
{ {
if (our_strings_[i] == 0) if (our_strings_[i] == 0)
{ {
std::cerr << "### FATAL: Not enough strings for enum " std::cerr << "### FATAL: Not enough strings for enum " << our_name_ << " defined in file '" << filename
<< our_name_ << " defined in file '" << filename
<< "' at line " << line_no; << "' at line " << line_no;
} }
} }
if (std::string("") != our_strings_[THE_MAX]) if (std::string("") != our_strings_[THE_MAX])
{ {
std::cerr << "### FATAL: The string array for enum " << our_name_ std::cerr << "### FATAL: The string array for enum " << our_name_ << " defined in file '" << filename
<< " defined in file '" << filename << "' at line " << line_no << "' at line " << line_no << " has too many items or is not terminated with an "
<< " has too many items or is not terminated with an "
<< "empty string"; << "empty string";
} }
return true; return true;
@ -267,13 +251,12 @@ private:
* @relates mapnik::enumeration * @relates mapnik::enumeration
*/ */
template<class ENUM, int THE_MAX> template<class ENUM, int THE_MAX>
std::ostream & std::ostream& operator<<(std::ostream& os, const mapnik::enumeration<ENUM, THE_MAX>& e)
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
{ {
return os << e.as_string(); return os << e.as_string();
} }
} // end of namespace } // namespace mapnik
/** Helper macro. /** Helper macro.
* @relates mapnik::enumeration * @relates mapnik::enumeration
@ -285,9 +268,12 @@ operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
#else #else
#define DEFINE_ENUM(name, e) \ #define DEFINE_ENUM(name, e) \
using name = enumeration<e, e##_MAX>; \ using name = enumeration<e, e##_MAX>; \
template <> MAPNIK_DECL const char ** name ::our_strings_; \ template<> \
template <> MAPNIK_DECL std::string name ::our_name_; \ MAPNIK_DECL const char** name ::our_strings_; \
template <> MAPNIK_DECL bool name ::our_verified_flag_; template<> \
MAPNIK_DECL std::string name ::our_name_; \
template<> \
MAPNIK_DECL bool name ::our_verified_flag_;
#endif #endif
/** Helper macro. Runs the verify_mapnik_enum() method during static initialization. /** Helper macro. Runs the verify_mapnik_enum() method during static initialization.
@ -295,8 +281,11 @@ operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
*/ */
#define IMPLEMENT_ENUM(name, strings) \ #define IMPLEMENT_ENUM(name, strings) \
template <> MAPNIK_DECL const char ** name ::our_strings_ = strings; \ template<> \
template <> MAPNIK_DECL std::string name ::our_name_ = #name; \ MAPNIK_DECL const char** name ::our_strings_ = strings; \
template <> MAPNIK_DECL bool name ::our_verified_flag_( name ::verify_mapnik_enum(__FILE__, __LINE__)); template<> \
MAPNIK_DECL std::string name ::our_name_ = #name; \
template<> \
MAPNIK_DECL bool name ::our_verified_flag_(name ::verify_mapnik_enum(__FILE__, __LINE__));
#endif // MAPNIK_ENUMERATION_HPP #endif // MAPNIK_ENUMERATION_HPP

View file

@ -44,7 +44,8 @@ struct evaluate_expression
using value_type = T; using value_type = T;
explicit evaluate_expression(Attributes const& attrs) explicit evaluate_expression(Attributes const& attrs)
: attrs_(attrs) {} : attrs_(attrs)
{}
value_type operator()(attribute const&) const value_type operator()(attribute const&) const
{ {
@ -68,22 +69,19 @@ struct evaluate_expression
value_type operator()(binary_node<tags::logical_and> const& x) const value_type operator()(binary_node<tags::logical_and> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
&& (util::apply_visitor(*this, x.right).to_bool());
} }
value_type operator()(binary_node<tags::logical_or> const& x) const value_type operator()(binary_node<tags::logical_or> const& x) const
{ {
return (util::apply_visitor(*this,x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|| (util::apply_visitor(*this,x.right).to_bool());
} }
template<typename Tag> template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const value_type operator()(binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left), return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
util::apply_visitor(*this, x.right));
} }
template<typename Tag> template<typename Tag>
@ -156,22 +154,19 @@ struct evaluate_expression<T, boost::none_t>
value_type operator()(binary_node<tags::logical_and> const& x) const value_type operator()(binary_node<tags::logical_and> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
&& (util::apply_visitor(*this, x.right).to_bool());
} }
value_type operator()(binary_node<tags::logical_or> const& x) const value_type operator()(binary_node<tags::logical_or> const& x) const
{ {
return (util::apply_visitor(*this,x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|| (util::apply_visitor(*this,x.right).to_bool());
} }
template<typename Tag> template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const value_type operator()(binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left), return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
util::apply_visitor(*this, x.right));
} }
template<typename Tag> template<typename Tag>
@ -221,33 +216,39 @@ struct evaluate_expression<T, boost::none_t>
struct assign_value struct assign_value
{ {
template<typename Attributes> template<typename Attributes>
static void apply(symbolizer_base::value_type & val, expression_ptr const& expr, Attributes const& attrs, property_types target ) static void apply(symbolizer_base::value_type& val,
expression_ptr const& expr,
Attributes const& attrs,
property_types target)
{ {
switch (target) switch (target)
{ {
case property_types::target_color: case property_types::target_color: {
{
// evaluate expression as a string then parse as css color // evaluate expression as a string then parse as css color
std::string str = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, std::string str =
Attributes>(attrs),*expr).to_string(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_string();
try { val = parse_color(str); } try
catch (...) { val = color(0,0,0);} {
val = parse_color(str);
} catch (...)
{
val = color(0, 0, 0);
}
break; break;
} }
case property_types::target_double: case property_types::target_double: {
{ val =
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_double(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_double();
break; break;
} }
case property_types::target_integer: case property_types::target_integer: {
{ val =
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_int(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_int();
break; break;
} }
case property_types::target_bool: case property_types::target_bool: {
{ val =
val = util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs),*expr).to_bool(); util::apply_visitor(mapnik::evaluate_expression<mapnik::value, Attributes>(attrs), *expr).to_bool();
break; break;
} }
default: // no-op default: // no-op
@ -256,16 +257,16 @@ struct assign_value
} }
}; };
} } // namespace
template<typename T> template<typename T>
std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr) std::tuple<T, bool> pre_evaluate_expression(expression_ptr const& expr)
{ {
try try
{ {
return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none),*expr), true); return std::make_tuple(util::apply_visitor(mapnik::evaluate_expression<T, boost::none_t>(boost::none), *expr),
} true);
catch (...) } catch (...)
{ {
return std::make_tuple(T(), false); return std::make_tuple(T(), false);
} }
@ -277,8 +278,9 @@ struct evaluate_global_attributes : util::noncopyable
struct evaluator struct evaluator
{ {
evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs) evaluator(symbolizer_base::cont_type::value_type& prop, Attributes const& attrs)
: prop_(prop), : prop_(prop)
attrs_(attrs) {} , attrs_(attrs)
{}
void operator()(expression_ptr const& expr) const void operator()(expression_ptr const& expr) const
{ {
@ -299,7 +301,8 @@ struct evaluate_global_attributes : util::noncopyable
struct extract_symbolizer struct extract_symbolizer
{ {
extract_symbolizer(Attributes const& attrs) extract_symbolizer(Attributes const& attrs)
: attrs_(attrs) {} : attrs_(attrs)
{}
template<typename Symbolizer> template<typename Symbolizer>
void operator()(Symbolizer& sym) const void operator()(Symbolizer& sym) const
@ -328,6 +331,6 @@ struct evaluate_global_attributes : util::noncopyable
} }
}; };
} } // namespace mapnik
#endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP #endif // MAPNIK_EVALUATE_GLOBAL_ATTRIBUTES_HPP

View file

@ -34,14 +34,13 @@
#include <string> #include <string>
#include <set> #include <set>
namespace mapnik namespace mapnik {
{
// fwd declare to reduce compile time // fwd declare to reduce compile time
using expression_ptr = std::shared_ptr<expr_node>; using expression_ptr = std::shared_ptr<expr_node>;
using expression_set = std::set<expression_ptr>; using expression_set = std::set<expression_ptr>;
MAPNIK_DECL expression_ptr parse_expression(std::string const& wkt); MAPNIK_DECL expression_ptr parse_expression(std::string const& wkt);
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_HPP #endif // MAPNIK_EXPRESSION_HPP

View file

@ -31,8 +31,7 @@
#include <mapnik/util/variant.hpp> #include <mapnik/util/variant.hpp>
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
namespace mapnik namespace mapnik {
{
template<typename T0, typename T1, typename T2> template<typename T0, typename T1, typename T2>
struct evaluate struct evaluate
@ -42,38 +41,21 @@ struct evaluate
using variable_type = T2; using variable_type = T2;
using result_type = T1; // we need this because automatic result_type deduction fails using result_type = T1; // we need this because automatic result_type deduction fails
explicit evaluate(feature_type const& f, variable_type const& v) explicit evaluate(feature_type const& f, variable_type const& v)
: feature_(f), : feature_(f)
vars_(v) {} , vars_(v)
{}
value_type operator() (value_integer val) const value_type operator()(value_integer val) const { return val; }
{
return val;
}
value_type operator() (value_double val) const value_type operator()(value_double val) const { return val; }
{
return val;
}
value_type operator() (value_bool val) const value_type operator()(value_bool val) const { return val; }
{
return val;
}
value_type operator() (value_null val) const value_type operator()(value_null val) const { return val; }
{
return val;
}
value_type operator() (value_unicode_string const& str) const value_type operator()(value_unicode_string const& str) const { return str; }
{
return str;
}
value_type operator() (attribute const& attr) const value_type operator()(attribute const& attr) const { return attr.value<value_type, feature_type>(feature_); }
{
return attr.value<value_type,feature_type>(feature_);
}
value_type operator()(global_attribute const& attr) const value_type operator()(global_attribute const& attr) const
{ {
@ -92,22 +74,19 @@ struct evaluate
value_type operator()(binary_node<tags::logical_and> const& x) const value_type operator()(binary_node<tags::logical_and> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) && (util::apply_visitor(*this, x.right).to_bool());
&& (util::apply_visitor(*this, x.right).to_bool());
} }
value_type operator()(binary_node<tags::logical_or> const& x) const value_type operator()(binary_node<tags::logical_or> const& x) const
{ {
return (util::apply_visitor(*this, x.left).to_bool()) return (util::apply_visitor(*this, x.left).to_bool()) || (util::apply_visitor(*this, x.right).to_bool());
|| (util::apply_visitor(*this, x.right).to_bool());
} }
template<typename Tag> template<typename Tag>
value_type operator()(binary_node<Tag> const& x) const value_type operator()(binary_node<Tag> const& x) const
{ {
typename make_op<Tag>::type operation; typename make_op<Tag>::type operation;
return operation(util::apply_visitor(*this, x.left), return operation(util::apply_visitor(*this, x.left), util::apply_visitor(*this, x.right));
util::apply_visitor(*this, x.right));
} }
template<typename Tag> template<typename Tag>
@ -151,6 +130,6 @@ struct evaluate
variable_type const& vars_; variable_type const& vars_;
}; };
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_EVALUATOR_HPP #endif // MAPNIK_EXPRESSION_EVALUATOR_HPP

View file

@ -31,7 +31,8 @@ MAPNIK_DISABLE_WARNING_PUSH
#include <boost/spirit/home/x3.hpp> #include <boost/spirit/home/x3.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
namespace mapnik { namespace grammar { namespace mapnik {
namespace grammar {
#if BOOST_VERSION >= 106700 #if BOOST_VERSION >= 106700
using transcoder_type = mapnik::transcoder; using transcoder_type = mapnik::transcoder;
@ -39,7 +40,6 @@ using transcoder_type = mapnik::transcoder;
using transcoder_type = std::reference_wrapper<mapnik::transcoder const>; using transcoder_type = std::reference_wrapper<mapnik::transcoder const>;
#endif #endif
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
struct transcoder_tag; struct transcoder_tag;
struct expression_class; // top-most ID struct expression_class; // top-most ID
@ -49,6 +49,7 @@ expression_grammar_type const expression("expression");
BOOST_SPIRIT_DECLARE(expression_grammar_type); BOOST_SPIRIT_DECLARE(expression_grammar_type);
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP #endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_HPP

View file

@ -26,16 +26,16 @@
#include <mapnik/expression_grammar_x3.hpp> #include <mapnik/expression_grammar_x3.hpp>
#include <string> #include <string>
namespace mapnik { namespace grammar { namespace mapnik {
namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
using iterator_type = std::string::const_iterator; using iterator_type = std::string::const_iterator;
using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type; using phrase_context_type = x3::phrase_parse_context<x3::ascii::space_type>::type;
// define combined context // define combined context
using context_type = x3::context<transcoder_tag, using context_type = x3::context<transcoder_tag, transcoder_type const, phrase_context_type>;
transcoder_type const,
phrase_context_type>;
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP #endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_CONFIG_HPP

View file

@ -24,47 +24,45 @@
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP #define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
#include <mapnik/expression_grammar_x3.hpp> #include <mapnik/expression_grammar_x3.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/expression_node.hpp> #include <mapnik/expression_node.hpp>
#include <mapnik/function_call.hpp> #include <mapnik/function_call.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
#include <mapnik/warning.hpp> #include <mapnik/warning.hpp>
MAPNIK_DISABLE_WARNING_PUSH MAPNIK_DISABLE_WARNING_PUSH
#include <mapnik/warning_ignore.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/std_pair.hpp> #include <boost/fusion/include/std_pair.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <mapnik/warning_ignore.hpp>
MAPNIK_DISABLE_WARNING_POP MAPNIK_DISABLE_WARNING_POP
BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call, BOOST_FUSION_ADAPT_STRUCT(mapnik::unary_function_call,
(mapnik::unary_function_impl, fun) (mapnik::unary_function_impl, fun)(mapnik::unary_function_call::argument_type, arg))
(mapnik::unary_function_call::argument_type, arg))
BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call, BOOST_FUSION_ADAPT_STRUCT(mapnik::binary_function_call,
(mapnik::binary_function_impl, fun) (mapnik::binary_function_impl, fun)(mapnik::binary_function_call::argument_type,
(mapnik::binary_function_call::argument_type, arg1) arg1)(mapnik::binary_function_call::argument_type, arg2))
(mapnik::binary_function_call::argument_type, arg2))
namespace mapnik {
namespace mapnik { namespace grammar { namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
namespace ascii = boost::spirit::x3::ascii; namespace ascii = boost::spirit::x3::ascii;
using ascii::char_; using ascii::char_;
using ascii::string; using ascii::string;
using x3::lit;
using x3::double_;
using x3::int_;
using x3::bool_;
using x3::_attr; using x3::_attr;
using x3::_val; using x3::_val;
using x3::no_skip;
using x3::lexeme;
using x3::no_case;
using x3::alpha;
using x3::alnum; using x3::alnum;
using x3::alpha;
using x3::bool_;
using x3::double_;
using x3::int_;
using x3::lexeme;
using x3::lit;
using x3::no_case;
using x3::no_skip;
x3::uint_parser<char, 16, 2, 2> const hex2{}; x3::uint_parser<char, 16, 2, 2> const hex2{};
namespace { namespace {
@ -77,23 +75,19 @@ namespace mapnik { namespace grammar {
return x3::get<transcoder_tag>(ctx); return x3::get<transcoder_tag>(ctx);
} }
auto append = [](auto const& ctx) auto append = [](auto const& ctx) {
{
_val(ctx) += _attr(ctx); _val(ctx) += _attr(ctx);
}; };
auto do_assign = [] (auto const& ctx) auto do_assign = [](auto const& ctx) {
{
_val(ctx) = std::move(_attr(ctx)); _val(ctx) = std::move(_attr(ctx));
}; };
auto do_negate = [] (auto const& ctx) auto do_negate = [](auto const& ctx) {
{
_val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx))); _val(ctx) = std::move(unary_node<mapnik::tags::negate>(_attr(ctx)));
}; };
auto do_attribute = [] (auto const& ctx) auto do_attribute = [](auto const& ctx) {
{
auto const& attr = _attr(ctx); auto const& attr = _attr(ctx);
if (attr == "mapnik::geometry_type") if (attr == "mapnik::geometry_type")
{ {
@ -105,102 +99,84 @@ namespace mapnik { namespace grammar {
} }
}; };
auto do_global_attribute = [] (auto const& ctx) auto do_global_attribute = [](auto const& ctx) {
{
_val(ctx) = std::move(global_attribute(_attr(ctx))); _val(ctx) = std::move(global_attribute(_attr(ctx)));
}; };
auto do_add = [] (auto const& ctx) auto do_add = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::plus>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_subt = [] (auto const& ctx) auto do_subt = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::minus>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_mult = [] (auto const& ctx) auto do_mult = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mult>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_div = [] (auto const& ctx) auto do_div = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::div>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_mod = [] (auto const& ctx) auto do_mod = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::mod>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_unicode = [] (auto const& ctx) auto do_unicode = [](auto const& ctx) {
{
auto const& tr = extract_transcoder(ctx); auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(tr.transcode(_attr(ctx).c_str())); _val(ctx) = std::move(tr.transcode(_attr(ctx).c_str()));
}; };
auto do_null = [] (auto const& ctx) auto do_null = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::value_null()); _val(ctx) = std::move(mapnik::value_null());
}; };
auto do_not = [] (auto const& ctx) auto do_not = [](auto const& ctx) {
{
mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx)); mapnik::unary_node<mapnik::tags::logical_not> node(_attr(ctx));
_val(ctx) = std::move(node); _val(ctx) = std::move(node);
}; };
auto do_and = [] (auto const& ctx) auto do_and = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_and>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_or = [] (auto const& ctx) auto do_or = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::logical_or>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_equal = [] (auto const& ctx) auto do_equal = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_not_equal = [] (auto const& ctx) auto do_not_equal = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::not_equal_to>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_less = [] (auto const& ctx) auto do_less = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_less_equal = [] (auto const& ctx) auto do_less_equal = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::less_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_greater = [] (auto const& ctx) auto do_greater = [](auto const& ctx) {
{
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_greater_equal = [] (auto const& ctx) auto do_greater_equal = [](auto const& ctx) {
{ _val(ctx) =
_val(ctx) = std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx)))); std::move(mapnik::binary_node<mapnik::tags::greater_equal>(std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
// regex // regex
auto do_regex_match = [] (auto const& ctx) auto do_regex_match = [](auto const& ctx) {
{
auto const& tr = extract_transcoder(ctx); auto const& tr = extract_transcoder(ctx);
_val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx)))); _val(ctx) = std::move(mapnik::regex_match_node(tr, std::move(_val(ctx)), std::move(_attr(ctx))));
}; };
auto do_regex_replace = [] (auto const& ctx) auto do_regex_replace = [](auto const& ctx) {
{
auto const& tr = extract_transcoder(ctx); auto const& tr = extract_transcoder(ctx);
auto const& pair = _attr(ctx); auto const& pair = _attr(ctx);
auto const& pattern = std::get<0>(pair); auto const& pattern = std::get<0>(pair);
@ -217,9 +193,8 @@ namespace mapnik { namespace grammar {
{ {
boolean_() boolean_()
{ {
add add("true", true) //
("true", true) ("false", false) //
("false", false)
; ;
} }
} boolean; } boolean;
@ -228,10 +203,9 @@ namespace mapnik { namespace grammar {
{ {
floating_point_constants() floating_point_constants()
{ {
add add("pi", 3.1415926535897932384626433832795) //
("pi", 3.1415926535897932384626433832795) ("deg_to_rad", 0.017453292519943295769236907684886) //
("deg_to_rad",0.017453292519943295769236907684886) ("rad_to_deg", 57.295779513082320876798154814105) //
("rad_to_deg",57.295779513082320876798154814105)
; ;
} }
} float_const; } float_const;
@ -241,30 +215,27 @@ namespace mapnik { namespace grammar {
{ {
unary_function_types_() unary_function_types_()
{ {
add add("sin", sin_impl()) //
("sin", sin_impl()) ("cos", cos_impl()) //
("cos", cos_impl()) ("tan", tan_impl()) //
("tan", tan_impl()) ("atan", atan_impl()) //
("atan", atan_impl()) ("exp", exp_impl()) //
("exp", exp_impl()) ("log", log_impl()) //
("log", log_impl()) ("abs", abs_impl()) //
("abs", abs_impl()) ("length", length_impl()) //
("length",length_impl())
; ;
} }
} unary_func_types; } unary_func_types;
// binary functions // binary functions
struct binary_function_types_ : x3::symbols<binary_function_impl> struct binary_function_types_ : x3::symbols<binary_function_impl>
{ {
binary_function_types_() binary_function_types_()
{ {
add add("min", binary_function_impl(min_impl)) //
("min", binary_function_impl(min_impl)) ("max", binary_function_impl(max_impl)) //
("max", binary_function_impl(max_impl)) ("pow", binary_function_impl(pow_impl)) //
("pow", binary_function_impl(pow_impl))
; ;
} }
} binary_func_types; } binary_func_types;
@ -274,11 +245,10 @@ namespace mapnik { namespace grammar {
{ {
geometry_types_() geometry_types_()
{ {
add add("point", 1) //
("point", 1) ("linestring", 2) //
("linestring", 2) ("polygon", 3) //
("polygon",3) ("collection", 4) //
("collection",4)
; ;
} }
} geometry_type; } geometry_type;
@ -287,17 +257,16 @@ namespace mapnik { namespace grammar {
{ {
unesc_chars_() unesc_chars_()
{ {
add add("\\a", '\a') //
("\\a", '\a') ("\\b", '\b') //
("\\b", '\b') ("\\f", '\f') //
("\\f", '\f') ("\\n", '\n') //
("\\n", '\n') ("\\r", '\r') //
("\\r", '\r') ("\\t", '\t') //
("\\t", '\t') ("\\v", '\v') //
("\\v", '\v') ("\\\\", '\\') //
("\\\\", '\\') ("\\\'", '\'') //
("\\\'", '\'') ("\\\"", '\"') //
("\\\"", '\"')
; ;
} }
} unesc_char; } unesc_char;
@ -309,14 +278,18 @@ namespace mapnik { namespace grammar {
x3::rule<class equality_expression, mapnik::expr_node> const equality_expression("equality expression"); x3::rule<class equality_expression, mapnik::expr_node> const equality_expression("equality expression");
x3::rule<class relational_expression, mapnik::expr_node> const relational_expression("relational expression"); x3::rule<class relational_expression, mapnik::expr_node> const relational_expression("relational expression");
x3::rule<class additive_expression, mapnik::expr_node> const additive_expression("additive expression"); x3::rule<class additive_expression, mapnik::expr_node> const additive_expression("additive expression");
x3::rule<class multiplicative_expression, mapnik::expr_node> const multiplicative_expression("multiplicative expression"); x3::rule<class multiplicative_expression, mapnik::expr_node> const
x3::rule<class unary_func_expression, mapnik::unary_function_call> const unary_func_expression("unary function expression"); multiplicative_expression("multiplicative expression");
x3::rule<class binary_func_expression, mapnik::binary_function_call> const binary_func_expression("binary function expression"); x3::rule<class unary_func_expression, mapnik::unary_function_call> const
unary_func_expression("unary function expression");
x3::rule<class binary_func_expression, mapnik::binary_function_call> const
binary_func_expression("binary function expression");
x3::rule<class unary_expression, mapnik::expr_node> const unary_expression("unary expression"); x3::rule<class unary_expression, mapnik::expr_node> const unary_expression("unary expression");
x3::rule<class primary_expression, mapnik::expr_node> const primary_expression("primary expression"); x3::rule<class primary_expression, mapnik::expr_node> const primary_expression("primary expression");
x3::rule<class regex_match_expression, std::string> const regex_match_expression("regex match expression"); x3::rule<class regex_match_expression, std::string> const regex_match_expression("regex match expression");
x3::rule<class regex_replace_expression, std::pair<std::string,std::string> > const regex_replace_expression("regex replace expression"); x3::rule<class regex_replace_expression, std::pair<std::string, std::string>> const
regex_replace_expression("regex replace expression");
// clang-format off
// strings // strings
auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'') auto const single_quoted_string = x3::rule<class single_quoted_string, std::string> {} = lit('\'')
>> no_skip[*(unesc_char[append] >> no_skip[*(unesc_char[append]
@ -431,9 +404,8 @@ namespace mapnik { namespace grammar {
unquoted_ustring[do_unicode] unquoted_ustring[do_unicode]
// ^ https://github.com/mapnik/mapnik/pull/3389 // ^ https://github.com/mapnik/mapnik/pull/3389
; ;
// clang-format on
BOOST_SPIRIT_DEFINE ( BOOST_SPIRIT_DEFINE(expression,
expression,
logical_expression, logical_expression,
not_expression, not_expression,
conditional_expression, conditional_expression,
@ -446,9 +418,9 @@ namespace mapnik { namespace grammar {
unary_func_expression, unary_func_expression,
binary_func_expression, binary_func_expression,
unary_expression, unary_expression,
primary_expression primary_expression);
);
}} } // namespace grammar
} // namespace mapnik
#endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP #endif // MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP

View file

@ -34,41 +34,100 @@
// stl // stl
#include <memory> #include <memory>
namespace mapnik namespace mapnik {
{
using value_type = mapnik::value; using value_type = mapnik::value;
template <typename Tag> struct make_op; template<typename Tag>
template <> struct make_op<mapnik::tags::negate> { using type = std::negate<value_type>;}; struct make_op;
template <> struct make_op<mapnik::tags::plus> { using type = std::plus<value_type>;}; template<>
template <> struct make_op<mapnik::tags::minus> { using type = std::minus<value_type>;}; struct make_op<mapnik::tags::negate>
template <> struct make_op<mapnik::tags::mult> { using type = std::multiplies<value_type>;}; {
template <> struct make_op<mapnik::tags::div> { using type = std::divides<value_type>;}; using type = std::negate<value_type>;
template <> struct make_op<mapnik::tags::mod> { using type = std::modulus<value_type>;}; };
template <> struct make_op<mapnik::tags::less> { using type = std::less<value_type>;}; template<>
template <> struct make_op<mapnik::tags::less_equal> { using type = std::less_equal<value_type>;}; struct make_op<mapnik::tags::plus>
template <> struct make_op<mapnik::tags::greater> { using type = std::greater<value_type>;}; {
template <> struct make_op<mapnik::tags::greater_equal> { using type = std::greater_equal<value_type>;}; using type = std::plus<value_type>;
template <> struct make_op<mapnik::tags::equal_to> { using type = std::equal_to<value_type>;}; };
template <> struct make_op<mapnik::tags::not_equal_to> { using type = std::not_equal_to<value_type>;}; template<>
template <> struct make_op<mapnik::tags::logical_not> { using type = std::logical_not<value_type>;}; struct make_op<mapnik::tags::minus>
template <> struct make_op<mapnik::tags::logical_and> { using type = std::logical_and<value_type>;}; {
template <> struct make_op<mapnik::tags::logical_or> { using type = std::logical_or<value_type>;}; using type = std::minus<value_type>;
};
template<>
struct make_op<mapnik::tags::mult>
{
using type = std::multiplies<value_type>;
};
template<>
struct make_op<mapnik::tags::div>
{
using type = std::divides<value_type>;
};
template<>
struct make_op<mapnik::tags::mod>
{
using type = std::modulus<value_type>;
};
template<>
struct make_op<mapnik::tags::less>
{
using type = std::less<value_type>;
};
template<>
struct make_op<mapnik::tags::less_equal>
{
using type = std::less_equal<value_type>;
};
template<>
struct make_op<mapnik::tags::greater>
{
using type = std::greater<value_type>;
};
template<>
struct make_op<mapnik::tags::greater_equal>
{
using type = std::greater_equal<value_type>;
};
template<>
struct make_op<mapnik::tags::equal_to>
{
using type = std::equal_to<value_type>;
};
template<>
struct make_op<mapnik::tags::not_equal_to>
{
using type = std::not_equal_to<value_type>;
};
template<>
struct make_op<mapnik::tags::logical_not>
{
using type = std::logical_not<value_type>;
};
template<>
struct make_op<mapnik::tags::logical_and>
{
using type = std::logical_and<value_type>;
};
template<>
struct make_op<mapnik::tags::logical_or>
{
using type = std::logical_or<value_type>;
};
template<typename Tag> template<typename Tag>
struct unary_node struct unary_node
{ {
unary_node(expr_node&& a) unary_node(expr_node&& a)
: expr(std::move(a)) {} : expr(std::move(a))
{}
unary_node(expr_node const& a) unary_node(expr_node const& a)
: expr(a) {} : expr(a)
{}
static const char* type() static const char* type() { return Tag::str(); }
{
return Tag::str();
}
expr_node expr; expr_node expr;
}; };
@ -77,17 +136,16 @@ template <typename Tag>
struct binary_node struct binary_node
{ {
binary_node(expr_node&& a, expr_node&& b) binary_node(expr_node&& a, expr_node&& b)
: left(std::move(a)), : left(std::move(a))
right(std::move(b)) {} , right(std::move(b))
{}
binary_node(expr_node const& a, expr_node const& b) binary_node(expr_node const& a, expr_node const& b)
: left(a), : left(a)
right(b) {} , right(b)
{}
static const char* type() static const char* type() { return Tag::str(); }
{
return Tag::str();
}
expr_node left, right; expr_node left, right;
}; };
@ -96,7 +154,9 @@ struct unary_function_call
using argument_type = expr_node; using argument_type = expr_node;
unary_function_call() = default; unary_function_call() = default;
unary_function_call(unary_function_impl _fun, argument_type const& _arg) unary_function_call(unary_function_impl _fun, argument_type const& _arg)
: fun(_fun), arg(_arg) {} : fun(_fun)
, arg(_arg)
{}
unary_function_impl fun; unary_function_impl fun;
argument_type arg; argument_type arg;
@ -107,7 +167,10 @@ struct binary_function_call
using argument_type = expr_node; using argument_type = expr_node;
binary_function_call() = default; binary_function_call() = default;
binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2) binary_function_call(binary_function_impl _fun, argument_type const& _arg1, argument_type const& _arg2)
: fun(_fun), arg1(_arg1), arg2(_arg2) {} : fun(_fun)
, arg1(_arg1)
, arg2(_arg2)
{}
binary_function_impl fun; binary_function_impl fun;
argument_type arg1; argument_type arg1;
argument_type arg2; argument_type arg2;
@ -137,7 +200,6 @@ struct MAPNIK_DECL regex_replace_node
std::shared_ptr<_regex_replace_impl> impl_; std::shared_ptr<_regex_replace_impl> impl_;
}; };
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_NODE_HPP #endif // MAPNIK_EXPRESSION_NODE_HPP

View file

@ -28,136 +28,90 @@
#include <mapnik/value/types.hpp> #include <mapnik/value/types.hpp>
#include <mapnik/util/variant.hpp> #include <mapnik/util/variant.hpp>
namespace mapnik namespace mapnik {
{
namespace tags { namespace tags {
struct negate struct negate
{ {
static const char* str() static const char* str() { return "-"; }
{
return "-";
}
}; };
struct plus struct plus
{ {
static const char* str() static const char* str() { return "+"; }
{
return "+";
}
}; };
struct minus struct minus
{ {
static const char* str() static const char* str() { return "-"; }
{
return "-";
}
}; };
struct mult struct mult
{ {
static const char* str() static const char* str() { return "*"; }
{
return "*";
}
}; };
struct div struct div
{ {
static const char* str() static const char* str() { return "/"; }
{
return "/";
}
}; };
struct mod struct mod
{ {
static const char* str() static const char* str() { return "%"; }
{
return "%";
}
}; };
struct less struct less
{ {
static const char* str() static const char* str() { return "<"; }
{
return "<";
}
}; };
struct less_equal struct less_equal
{ {
static const char* str() static const char* str() { return "<="; }
{
return "<=";
}
}; };
struct greater struct greater
{ {
static const char* str() static const char* str() { return ">"; }
{
return ">";
}
}; };
struct greater_equal struct greater_equal
{ {
static const char* str() static const char* str() { return ">="; }
{
return ">=";
}
}; };
struct equal_to struct equal_to
{ {
static const char* str() static const char* str() { return "="; }
{
return "=";
}
}; };
struct not_equal_to struct not_equal_to
{ {
static const char* str() static const char* str() { return "!="; }
{
return "!=";
}
}; };
struct logical_not struct logical_not
{ {
static const char* str() static const char* str() { return "not "; }
{
return "not ";
}
}; };
struct logical_and struct logical_and
{ {
static const char* str() static const char* str() { return " and "; }
{
return " and ";
}
}; };
struct logical_or struct logical_or
{ {
static const char* str() static const char* str() { return " or "; }
{
return " or ";
}
}; };
} // end operation tags } // namespace tags
template<typename Tag>
template <typename Tag> struct binary_node; struct binary_node;
template <typename Tag> struct unary_node; template<typename Tag>
struct unary_node;
struct regex_match_node; struct regex_match_node;
struct regex_replace_node; struct regex_replace_node;
struct attribute; struct attribute;
@ -166,8 +120,7 @@ struct geometry_type_attribute;
struct unary_function_call; struct unary_function_call;
struct binary_function_call; struct binary_function_call;
using expr_node = util::variant< using expr_node = util::variant<value_null,
value_null,
value_bool, value_bool,
value_integer, value_integer,
value_double, value_double,
@ -193,10 +146,8 @@ util::recursive_wrapper<binary_node<mapnik::tags::logical_or> >,
util::recursive_wrapper<regex_match_node>, util::recursive_wrapper<regex_match_node>,
util::recursive_wrapper<regex_replace_node>, util::recursive_wrapper<regex_replace_node>,
util::recursive_wrapper<unary_function_call>, util::recursive_wrapper<unary_function_call>,
util::recursive_wrapper<binary_function_call> util::recursive_wrapper<binary_function_call>>;
>;
}
} // namespace mapnik
#endif // MAPNIK_EXPRESSION_NODE_HPP #endif // MAPNIK_EXPRESSION_NODE_HPP

View file

@ -35,8 +35,7 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
namespace mapnik namespace mapnik {
{
MAPNIK_DECL std::string to_expression_string(expr_node const& node); MAPNIK_DECL std::string to_expression_string(expr_node const& node);
/* /*
@ -63,6 +62,6 @@ std::string to_expression_string(std::shared_ptr<T> const& expr_node_ptr)
// compile error intended here; comment on the next line shows in clang output // compile error intended here; comment on the next line shows in clang output
return expr_node_ptr; // to_expression_string() called with pointer argument return expr_node_ptr; // to_expression_string() called with pointer argument
} }
} } // namespace mapnik
#endif // MAPNIK_EXPRESSION_STRING_HPP #endif // MAPNIK_EXPRESSION_STRING_HPP

View file

@ -38,11 +38,9 @@ MAPNIK_DISABLE_WARNING_POP
// stl // stl
#include <cmath> #include <cmath>
namespace mapnik namespace mapnik {
{
namespace detail namespace detail {
{
namespace msm = boost::msm; namespace msm = boost::msm;
namespace mpl = boost::mpl; namespace mpl = boost::mpl;
@ -55,26 +53,37 @@ T extend(T const & v1, T const & v2, double length)
double dy = v2.y - v1.y; double dy = v2.y - v1.y;
double l12 = std::sqrt(dx * dx + dy * dy); double l12 = std::sqrt(dx * dx + dy * dy);
double coef = 1.0 + length / l12; double coef = 1.0 + length / l12;
return vertex2d(v1.x + dx * coef, return vertex2d(v1.x + dx * coef, v1.y + dy * coef, v2.cmd);
v1.y + dy * coef, v2.cmd);
} }
namespace events namespace events {
{
struct vertex_event struct vertex_event
{ {
vertex_event(vertex2d const & vertex) : vertex(vertex) { } vertex_event(vertex2d const& vertex)
: vertex(vertex)
{}
vertex2d const& vertex; vertex2d const& vertex;
}; };
struct move_to : vertex_event { using vertex_event::vertex_event; }; struct move_to : vertex_event
struct line_to : vertex_event { using vertex_event::vertex_event; };
struct close : vertex_event { using vertex_event::vertex_event; };
struct end : vertex_event { using vertex_event::vertex_event; };
}
namespace actions
{ {
using vertex_event::vertex_event;
};
struct line_to : vertex_event
{
using vertex_event::vertex_event;
};
struct close : vertex_event
{
using vertex_event::vertex_event;
};
struct end : vertex_event
{
using vertex_event::vertex_event;
};
} // namespace events
namespace actions {
struct store struct store
{ {
template<class FSM, class EVT, class SourceState, class TargetState> template<class FSM, class EVT, class SourceState, class TargetState>
@ -126,20 +135,25 @@ namespace actions
m.v1 = e.vertex; m.v1 = e.vertex;
} }
}; };
} } // namespace actions
struct extender_def : public msm::front::state_machine_def<extender_def> struct extender_def : public msm::front::state_machine_def<extender_def>
{ {
using no_exception_thrown = int; using no_exception_thrown = int;
using no_message_queue = int; using no_message_queue = int;
struct initial : public msm::front::state<> { }; struct initial : public msm::front::state<>
struct vertex_one : public msm::front::state<> { }; {};
struct vertex_two : public msm::front::state<> { }; struct vertex_one : public msm::front::state<>
struct end : public msm::front::state<> { }; {};
struct vertex_two : public msm::front::state<>
{};
struct end : public msm::front::state<>
{};
using initial_state = initial; using initial_state = initial;
// clang-format off
struct transition_table : mpl::vector< struct transition_table : mpl::vector<
// Start Event Next Action Guard // Start Event Next Action Guard
// +------------+-----------------+------------+--------------------+------+ // +------------+-----------------+------------+--------------------+------+
@ -157,11 +171,11 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
Row < vertex_two , events::end , end , actions::output_end >, Row < vertex_two , events::end , end , actions::output_end >,
Row < end , events::end , end , actions::output > Row < end , events::end , end , actions::output >
> {}; > {};
// clang-format on
extender_def(double extend_length) extender_def(double extend_length)
: extend_length(extend_length) : extend_length(extend_length)
{ {}
}
boost::optional<vertex2d> output; boost::optional<vertex2d> output;
vertex2d v1, v2; vertex2d v1, v2;
@ -170,7 +184,7 @@ struct extender_def : public msm::front::state_machine_def<extender_def>
using extender = msm::back::state_machine<extender_def>; using extender = msm::back::state_machine<extender_def>;
} } // namespace detail
template<typename Geometry> template<typename Geometry>
struct extend_converter struct extend_converter
@ -180,13 +194,11 @@ struct extend_converter
{} {}
extend_converter(Geometry& geom, double extend) extend_converter(Geometry& geom, double extend)
: geom_(geom), extender_(extend) : geom_(geom)
, extender_(extend)
{} {}
void set_extend(double extend) void set_extend(double extend) { extender_.extend_length = extend; }
{
extender_.extend_length = extend;
}
unsigned vertex(double* x, double* y) unsigned vertex(double* x, double* y)
{ {
@ -229,6 +241,6 @@ private:
detail::extender extender_; detail::extender extender_;
}; };
} } // namespace mapnik
#endif // MAPNIK_EXTEND_CONVERTER_HPP #endif // MAPNIK_EXTEND_CONVERTER_HPP

Some files were not shown because too many files have changed in this diff Show more