├── .gitignore ├── .travis.yml ├── Dockerfile ├── README.md ├── bounds ├── bounds.go └── bounds_test.go ├── cmd └── snap │ ├── README.md │ ├── cmd │ ├── generate.go │ ├── generate_tile.go │ ├── root.go │ ├── server.go │ └── version.go │ ├── generate │ └── image.go │ └── main.go ├── mbgl ├── README.md ├── README_build.md ├── c │ ├── Makefile │ ├── bin │ │ ├── render_stripped.cpp │ │ └── style.json │ ├── build_render.sh │ ├── build_render_with_local.sh │ ├── include │ │ ├── auto_cpu_timer.hpp │ │ ├── catch.hpp │ │ ├── expected.hpp │ │ ├── include │ │ │ ├── jni │ │ │ │ └── string_conversion.hpp │ │ │ └── mbgl │ │ │ │ ├── gl │ │ │ │ ├── headless_backend.hpp │ │ │ │ └── headless_frontend.hpp │ │ │ │ ├── map │ │ │ │ └── map_snapshotter.hpp │ │ │ │ ├── storage │ │ │ │ ├── file_source_request.hpp │ │ │ │ ├── local_file_request.hpp │ │ │ │ ├── merge_sideloaded.hpp │ │ │ │ ├── offline_database.hpp │ │ │ │ ├── offline_download.hpp │ │ │ │ ├── offline_schema.hpp │ │ │ │ └── sqlite3.hpp │ │ │ │ ├── text │ │ │ │ └── unaccent.hpp │ │ │ │ └── util │ │ │ │ ├── default_styles.hpp │ │ │ │ ├── default_thread_pool.hpp │ │ │ │ └── shared_thread_pool.hpp │ │ ├── mapbox │ │ │ ├── feature.hpp │ │ │ ├── geometry.hpp │ │ │ ├── geometry │ │ │ │ ├── box.hpp │ │ │ │ ├── empty.hpp │ │ │ │ ├── envelope.hpp │ │ │ │ ├── for_each_point.hpp │ │ │ │ ├── geometry.hpp │ │ │ │ ├── line_string.hpp │ │ │ │ ├── multi_line_string.hpp │ │ │ │ ├── multi_point.hpp │ │ │ │ ├── multi_polygon.hpp │ │ │ │ ├── point.hpp │ │ │ │ ├── point_arithmetic.hpp │ │ │ │ └── polygon.hpp │ │ │ ├── geometry_io.hpp │ │ │ ├── optional.hpp │ │ │ ├── recursive_wrapper.hpp │ │ │ ├── variant.hpp │ │ │ ├── variant_io.hpp │ │ │ └── variant_visitor.hpp │ │ └── mbgl │ │ │ ├── actor │ │ │ ├── actor.hpp │ │ │ ├── actor_ref.hpp │ │ │ ├── aspiring_actor.hpp │ │ │ ├── established_actor.hpp │ │ │ ├── mailbox.hpp │ │ │ ├── message.hpp │ │ │ └── scheduler.hpp │ │ │ ├── annotation │ │ │ └── annotation.hpp │ │ │ ├── layermanager │ │ │ ├── background_layer_factory.hpp │ │ │ ├── circle_layer_factory.hpp │ │ │ ├── custom_layer_factory.hpp │ │ │ ├── fill_extrusion_layer_factory.hpp │ │ │ ├── fill_layer_factory.hpp │ │ │ ├── heatmap_layer_factory.hpp │ │ │ ├── hillshade_layer_factory.hpp │ │ │ ├── layer_factory.hpp │ │ │ ├── layer_manager.hpp │ │ │ ├── line_layer_factory.hpp │ │ │ ├── raster_layer_factory.hpp │ │ │ └── symbol_layer_factory.hpp │ │ │ ├── map │ │ │ ├── camera.hpp │ │ │ ├── change.hpp │ │ │ ├── map.hpp │ │ │ ├── map_observer.hpp │ │ │ └── mode.hpp │ │ │ ├── math │ │ │ ├── clamp.hpp │ │ │ ├── log2.hpp │ │ │ ├── minmax.hpp │ │ │ └── wrap.hpp │ │ │ ├── platform │ │ │ └── gl_functions.hpp │ │ │ ├── renderer │ │ │ ├── backend_scope.hpp │ │ │ ├── mode.hpp │ │ │ ├── query.hpp │ │ │ ├── renderer.hpp │ │ │ ├── renderer_backend.hpp │ │ │ ├── renderer_frontend.hpp │ │ │ ├── renderer_observer.hpp │ │ │ └── renderer_state.hpp │ │ │ ├── storage │ │ │ ├── default_file_source.hpp │ │ │ ├── file_source.hpp │ │ │ ├── network_status.hpp │ │ │ ├── offline.hpp │ │ │ ├── online_file_source.hpp │ │ │ ├── resource.hpp │ │ │ ├── resource_transform.hpp │ │ │ └── response.hpp │ │ │ ├── style │ │ │ ├── color_ramp_property_value.hpp │ │ │ ├── conversion.hpp │ │ │ ├── conversion │ │ │ │ ├── color_ramp_property_value.hpp │ │ │ │ ├── constant.hpp │ │ │ │ ├── coordinate.hpp │ │ │ │ ├── custom_geometry_source_options.hpp │ │ │ │ ├── filter.hpp │ │ │ │ ├── function.hpp │ │ │ │ ├── geojson.hpp │ │ │ │ ├── geojson_options.hpp │ │ │ │ ├── get_json_type.hpp │ │ │ │ ├── layer.hpp │ │ │ │ ├── light.hpp │ │ │ │ ├── position.hpp │ │ │ │ ├── property_value.hpp │ │ │ │ ├── source.hpp │ │ │ │ ├── tileset.hpp │ │ │ │ └── transition_options.hpp │ │ │ ├── conversion_impl.hpp │ │ │ ├── expression │ │ │ │ ├── assertion.hpp │ │ │ │ ├── at.hpp │ │ │ │ ├── boolean_operator.hpp │ │ │ │ ├── case.hpp │ │ │ │ ├── check_subtype.hpp │ │ │ │ ├── coalesce.hpp │ │ │ │ ├── coercion.hpp │ │ │ │ ├── collator.hpp │ │ │ │ ├── collator_expression.hpp │ │ │ │ ├── comparison.hpp │ │ │ │ ├── compound_expression.hpp │ │ │ │ ├── dsl.hpp │ │ │ │ ├── error.hpp │ │ │ │ ├── expression.hpp │ │ │ │ ├── find_zoom_curve.hpp │ │ │ │ ├── format_expression.hpp │ │ │ │ ├── formatted.hpp │ │ │ │ ├── get_covering_stops.hpp │ │ │ │ ├── interpolate.hpp │ │ │ │ ├── interpolator.hpp │ │ │ │ ├── is_constant.hpp │ │ │ │ ├── is_expression.hpp │ │ │ │ ├── length.hpp │ │ │ │ ├── let.hpp │ │ │ │ ├── literal.hpp │ │ │ │ ├── match.hpp │ │ │ │ ├── parsing_context.hpp │ │ │ │ ├── step.hpp │ │ │ │ ├── type.hpp │ │ │ │ └── value.hpp │ │ │ ├── filter.hpp │ │ │ ├── image.hpp │ │ │ ├── layer.hpp │ │ │ ├── layers │ │ │ │ ├── background_layer.hpp │ │ │ │ ├── circle_layer.hpp │ │ │ │ ├── custom_layer.hpp │ │ │ │ ├── fill_extrusion_layer.hpp │ │ │ │ ├── fill_layer.hpp │ │ │ │ ├── heatmap_layer.hpp │ │ │ │ ├── hillshade_layer.hpp │ │ │ │ ├── layer.hpp.ejs │ │ │ │ ├── line_layer.hpp │ │ │ │ ├── raster_layer.hpp │ │ │ │ └── symbol_layer.hpp │ │ │ ├── light.hpp │ │ │ ├── light.hpp.ejs │ │ │ ├── position.hpp │ │ │ ├── property_expression.hpp │ │ │ ├── property_value.hpp │ │ │ ├── source.hpp │ │ │ ├── sources │ │ │ │ ├── custom_geometry_source.hpp │ │ │ │ ├── geojson_source.hpp │ │ │ │ ├── image_source.hpp │ │ │ │ ├── raster_dem_source.hpp │ │ │ │ ├── raster_source.hpp │ │ │ │ └── vector_source.hpp │ │ │ ├── style.hpp │ │ │ ├── transition_options.hpp │ │ │ ├── types.hpp │ │ │ └── undefined.hpp │ │ │ ├── tile │ │ │ ├── tile_id.hpp │ │ │ └── tile_necessity.hpp │ │ │ └── util │ │ │ ├── async_request.hpp │ │ │ ├── async_task.hpp │ │ │ ├── char_array_buffer.hpp │ │ │ ├── chrono.hpp │ │ │ ├── color.hpp │ │ │ ├── compression.hpp │ │ │ ├── constants.hpp │ │ │ ├── convert.hpp │ │ │ ├── enum.hpp │ │ │ ├── event.hpp │ │ │ ├── exception.hpp │ │ │ ├── expected.hpp │ │ │ ├── feature.hpp │ │ │ ├── font_stack.hpp │ │ │ ├── geo.hpp │ │ │ ├── geojson.hpp │ │ │ ├── geometry.hpp │ │ │ ├── ignore.hpp │ │ │ ├── image.hpp │ │ │ ├── immutable.hpp │ │ │ ├── indexed_tuple.hpp │ │ │ ├── interpolate.hpp │ │ │ ├── logging.hpp │ │ │ ├── noncopyable.hpp │ │ │ ├── optional.hpp │ │ │ ├── peer.hpp │ │ │ ├── platform.hpp │ │ │ ├── premultiply.hpp │ │ │ ├── projection.hpp │ │ │ ├── range.hpp │ │ │ ├── run_loop.hpp │ │ │ ├── size.hpp │ │ │ ├── string.hpp │ │ │ ├── thread.hpp │ │ │ ├── tileset.hpp │ │ │ ├── timer.hpp │ │ │ ├── traits.hpp │ │ │ ├── type_list.hpp │ │ │ ├── unitbezier.hpp │ │ │ ├── util.hpp │ │ │ ├── variant.hpp │ │ │ ├── work_request.hpp │ │ │ ├── work_task.hpp │ │ │ └── work_task_impl.hpp │ ├── install.sh │ ├── lib │ │ └── linux │ │ │ ├── .gitattributes │ │ │ ├── libicu.a │ │ │ ├── libjpeg.a │ │ │ ├── libmbgl-core.a │ │ │ ├── libmbgl-filesource.a │ │ │ ├── libmbgl-loop-uv.a │ │ │ ├── libnunicode.a │ │ │ ├── libpng.a │ │ │ ├── libpng16.a │ │ │ ├── libsqlite.a │ │ │ └── libuv.a │ └── patches │ │ └── 0001-Removed-CURLOPT_CAINFO-so-that-it-can-use-the-system.patch ├── camera_options.cpp ├── camera_options.go ├── camera_options.h ├── camera_options_test.go ├── default_file_source.cpp ├── default_file_source.go ├── default_file_source.h ├── default_file_source_test.go ├── error.h ├── file_source.go ├── file_source.h ├── headless_frontend.cpp ├── headless_frontend.go ├── headless_frontend.h ├── headless_frontend_test.go ├── lat_lng.cpp ├── lat_lng.go ├── lat_lng.h ├── map.cpp ├── map.go ├── map.h ├── map_test.go ├── mbgl.go ├── mbgl_darwin.go ├── mbgl_linux.go ├── premultiplied_image.cpp ├── premultiplied_image.go ├── premultiplied_image.h ├── renderer_frontend.go ├── renderer_frontend.h ├── run_loop.cpp ├── run_loop.go ├── run_loop.h ├── scheduler.cpp ├── scheduler.go ├── scheduler.h ├── scheduler_internal_test.go ├── scheduler_test.go ├── simplified │ ├── image.go │ ├── simplified.go │ ├── simplified_linux.go │ ├── snapshot.cpp │ ├── snapshot.go │ └── snapshot.h ├── size.cpp ├── size.go ├── size.h ├── size_test.go ├── thread_pool.cpp ├── thread_pool.go ├── thread_pool.h └── thread_pool_test.go ├── snapshotter.go ├── snapshotter_test.go └── version.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.png 3 | mason_packages/ 4 | .idea/ 5 | .DS_Store 6 | mapbox-gl-native/ 7 | mason-js/ 8 | lib/ 9 | cmd/snapshot/snapshot 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - "1.9" 4 | - "1.10" 5 | - "1.11" 6 | 7 | script: go test -v ./... -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | RUN apt-get update; \ 4 | apt-get install software-properties-common; \ 5 | add-apt-repository --yes ppa:ubuntu-toolchain-r/test; \ 6 | apt-get update; 7 | 8 | 9 | # Go 10 | RUN apt-get install -y golang-1.10 git build-essential; \ 11 | ln -s /usr/lib/go-1.10/bin/go /bin/go; \ 12 | ln -s /usr/lib/go-1.10/bin/gofmt /bin/gofmt 13 | 14 | # gcc 15 | 16 | RUN apt-get install -y gcc g++ 17 | # 18 | RUN apt-get install -y curl zlib1g-dev automake \ 19 | libtool xutils-dev make pkg-config python-pip \ 20 | libcurl4-openssl-dev \ 21 | libllvm3.9 \ 22 | git-lfs;\ 23 | apt-get update; 24 | 25 | # 26 | RUN apt-get update 27 | RUN apt-get install -y cmake cmake-data 28 | RUN apt-get install -y ccache 29 | RUN apt-get install -y libglu1-mesa-dev 30 | RUN apt-get install -y libosmesa6-dev libsqlite3-dev 31 | RUN apt-get update 32 | 33 | # 34 | #RUN apt-get install -y libxi-dev libglu1-mesa-dev x11proto-randr-dev \ 35 | # x11proto-xext-dev libxrandr-dev \ 36 | # x11proto-xf86vidmode-dev libxxf86vm-dev \ 37 | # libxcursor-dev libxinerama-dev 38 | # 39 | # 40 | 41 | RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - 42 | RUN apt-get install -y nodejs 43 | 44 | # Tools for Development 45 | RUN apt-get install -y neovim tree 46 | 47 | ENV GOPATH=/go 48 | RUN go get \ 49 | github.com/arolek/p \ 50 | github.com/go-spatial/geom \ 51 | github.com/dimfeld/httptreemux \ 52 | github.com/disintegration/imaging \ 53 | github.com/spf13/cobra 54 | 55 | #RUN go get -d github.com/go-spatial/go-mbgl 56 | 57 | 58 | #RUN mkdir -p /go/src/github.com/go-spatial/go-mbgl 59 | #WORKDIR /go/src/github.com/go-spatial/go-mbgl 60 | 61 | ENTRYPOINT bash 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-mbgl 2 | 3 | go-mbgl aims to provide Go bindings for [Mapbox GL native's C++ API.](https://github.com/mapbox/mapbox-gl-native) 4 | 5 | **WARNING**: This project is under heavly development, and is not production ready. 6 | 7 | **WARNING**: This will only work on Linux 8 | 9 | This repository depends on [*git-lfs*](https://git-lfs.github.com/) 10 | 11 | ## Repoistory Layout 12 | 13 | * [cmd/snap](cmd/snap) -- Holds the primary CLI (command line interface) tool. This tool servers both as a raster tile server, and static map generator. 14 | * [mbgl/simplifed](mbgl/simplifed) -- Go bindings for snapshot API. 15 | * [mbgl/c](mbgl/c) -- the C bridge for Go. (_Not working?_) 16 | * [mbgl/c/linux/lib](mbgl/c/linux/lib) -- location of the precompiled Linux libraries. 17 | 18 | 19 | ## Development Env 20 | 21 | Running the following commands should set up a working development environment 22 | 23 | ```console 24 | 25 | docker build -t mbgl . 26 | 27 | docker run --rm -v "$(pwd)":/go/src/github.com/go-spatial/go-mbgl -it mbgl 28 | 29 | ``` 30 | 31 | In the docker image if you need to rebuil the c archive files, you can use the `mbgl/c/install.sh` bash script 32 | to rebuild them. 33 | 34 | ## Build snap commandline utility. 35 | 36 | ```console 37 | 38 | cd cmd/snap 39 | 40 | go build 41 | 42 | ``` 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /cmd/snap/cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import "github.com/spf13/cobra" 4 | 5 | var RootCmd = &cobra.Command{ 6 | Use: "snap", 7 | Short: "snap is a raster tile server", 8 | Long: `snap is a raster tile server version: ` + Version, 9 | } 10 | 11 | const DefaultRootStyle = "https://raw.githubusercontent.com/go-spatial/tegola-web-demo/master/styles/hot-osm.json" 12 | 13 | var RootStyle string = DefaultRootStyle 14 | 15 | func init() { 16 | 17 | RootCmd.PersistentFlags().StringVarP(&RootStyle, "style", "s", DefaultRootStyle, "style to use. Style name will be default") 18 | 19 | RootCmd.AddCommand(cmdServer) 20 | RootCmd.AddCommand(cmdVersion) 21 | RootCmd.AddCommand(cmdGenerate) 22 | } 23 | -------------------------------------------------------------------------------- /cmd/snap/cmd/version.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var Version = "version not set" 10 | 11 | var cmdVersion = &cobra.Command{ 12 | Use: "version", 13 | Short: "Print the version number.", 14 | Long: `The version of the software. [` + Version + `]`, 15 | Run: func(cmd *cobra.Command, args []string) { 16 | fmt.Println(Version) 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /cmd/snap/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/go-spatial/go-mbgl/cmd/snap/cmd" 8 | ) 9 | 10 | func main() { 11 | if err := cmd.RootCmd.Execute(); err != nil { 12 | fmt.Println(err) 13 | os.Exit(1) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mbgl/README.md: -------------------------------------------------------------------------------- 1 | # mbgl 2 | 3 | This directory contains direct go bindings against the Mapbox GL Native C++ API. 4 | 5 | ## Design overview 6 | 7 | * follow the C++ api as closely as possible, not idiomatic Go 8 | * keeping in mind Go can only interface with C defintions 9 | * manual memory management through `(T).Destruct()` methods 10 | * C++ types are aliased in C as empty structs 11 | * they are named `MbglTypeName` 12 | * [WIP] C++ classes are aliased in Go as the C type 13 | * ie. `type TypeName C.TypeName` 14 | * C++ classes will always be passed around as pointers to C aliases and `reinterpret_cast<>`ed 15 | * [WIP] C++ structs are represented in Go as normal structs with Go memebers 16 | * ie. `type TypeName struct{ field1 *TypeNameX, field2 *TypeNameY }` 17 | * they must be accesse through a `(TypeName).cPtr() *C.MbglTypeName` method which updates the values of a C++ instance of the struct with the current values of the Go struct 18 | * this keeps us from having to write a getter and setter for every struct 19 | * Memory management is the responsibility of the programmer, through use of `(TypeName).Destruct()` methods which will call `delete` on the object 20 | 21 | ## Using the bindings 22 | 23 | * in the higher level package, `runtime.SetFinalizer` is used for memory management, note that this cannot be done for classes (which are aliased as empty structs) as: 24 | 25 | > It is not guaranteed that a finalizer will run if the size of *obj is zero bytes. 26 | > https://golang.org/pkg/runtime/#SetFinalizer 27 | 28 | * after calling `(T).Destruct()` make sure to not reuse the variable, this will result in strange errors; another `(T).Destruct()` call might yeild something like "freed block must be allocated with malloc". -------------------------------------------------------------------------------- /mbgl/README_build.md: -------------------------------------------------------------------------------- 1 | # go-mbgl 2 | go bindings for mapbox gl native's c++ api 3 | 4 | ## Development 5 | 6 | ### Dev Deps 7 | **Darwin**: 8 | see inssructions [on the mblg page](https://github.com/mapbox/mapbox-gl-native/blob/master/platform/macos/INSTALL.md), but do not build the library. 9 | In list form: 10 | * xcode 11 | * node 12 | * cmake 13 | * ccache 14 | * xcpretty 15 | * jazzy 16 | 17 | **Linux**: 18 | todo 19 | 20 | ### install 21 | run the install script provided in the repo. Note, it'll install a node package, [`mason-js`](https://github.com/mapbox/mason-js) globally with `npm i -g`. 22 | ```bash 23 | ./install.sh 24 | ``` 25 | 26 | ### build/tests 27 | regular go tool commands (`go build`, `go test`) can be used for building the library. 28 | 29 | ### Old install instructions (deprecated) 30 | 31 | 1. Download and build [Mapbox-GL-Native](https://github.com/mapbox/mapbox-gl-native) for your platform. 32 | 33 | 2. Add the absolute or relative path to the `include` and `platform/default` to the CGO_CXXFLAGS variable in the makefile as `-I` flags 34 | 35 | 3. Make library binaries accessible to linker 36 | * For `darwin` this requires copying a `.framework` file into `/Libray/Frameworks` and `.a` files into `./mason_packages/.link/lib` 37 | * For `linux` this can be done by copying `.a` files into `./mason_packages/.link/lib` 38 | 39 | 4. Install [mason-js](https://github.com/mapbox/mason-js) and run `mason-js install` and then `mason-js link` in the atto root directory to download the required dependencies 40 | 41 | 5. `go build` to build... 42 | 43 | There is a Dockerfile in /docker which details the steps required to set up a build and runtime environment for go-mbgl. 44 | -------------------------------------------------------------------------------- /mbgl/c/Makefile: -------------------------------------------------------------------------------- 1 | # PLACE YOUR MAPBOXGL INCLUDES HERE 2 | INCLUDES=\ 3 | -I/Users/julio/lib/c/mapbox-gl-native/include \ 4 | -I/Users/julio/lib/c/mapbox-gl-native/platform/default 5 | 6 | LINKS_DW=\ 7 | -lmbgl-loop-darwin\ 8 | -framework Mapbox\ 9 | -framework CoreFoundation\ 10 | -framework CoreGraphics\ 11 | -framework ImageIO\ 12 | -framework OpenGL\ 13 | -framework CoreText\ 14 | -framework Foundation 15 | 16 | # reflecetd in mblg.go file 17 | BUILD_FLAGS=-fPIC\ 18 | -D_GLIBCXX_USE_CXX11_ABI=1\ 19 | -std=c++14 -std=gnu++14\ 20 | -g\ 21 | -I./mason_packages/\.link/include\ 22 | -L./mason_packages/.link/lib\ 23 | -lsqlite3 -lz\ 24 | -lmbgl-filesource -lmbgl-core 25 | 26 | CGO_CXXFLAGS=$(INCLUDES) 27 | 28 | GO_FLAGS=CGO_CXXFLAGS="$(CGO_CXXFLAGS)" 29 | 30 | run= 31 | dir=./... 32 | 33 | .PHONY: test 34 | test: 35 | $(GO_FLAGS) go test -v $(dir) --run=$(run) 36 | 37 | f= 38 | .PHONY: dwfile 39 | dwfile: 40 | g++ $(BUILD_FLAGS) $(CGO_CXXFLAGS) $(LINKS_DW) -c $(f) 41 | -------------------------------------------------------------------------------- /mbgl/c/build_render_with_local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | echo "Building the object file." 4 | 5 | g++ \ 6 | -DRAPIDJSON_HAS_STDSTRING=1 \ 7 | -D_GLIBCXX_USE_CXX11_ABI=1 \ 8 | -Iinclude \ 9 | -Iinclude/include \ 10 | -ftemplate-depth=1024 \ 11 | -Wall \ 12 | -Wextra \ 13 | -Wshadow \ 14 | -Wnon-virtual-dtor \ 15 | -Wno-variadic-macros \ 16 | -Wno-unknown-pragmas \ 17 | -Werror \ 18 | -fext-numeric-literals \ 19 | -g \ 20 | -fPIE \ 21 | -fvisibility=hidden \ 22 | -fvisibility-inlines-hidden \ 23 | -std=c++14 \ 24 | -o bin/render_stripped.cpp.o \ 25 | -c bin/render_stripped.cpp 26 | 27 | 28 | echo "Building executable." 29 | 30 | # libmbgl-core.a libmbgl-filesource.a libmbgl-loop-uv.a libsqlite.a -Wl,--no-as-needed -lcurl -Wl,--as-needed libmbgl-core.a -lOSMesa ../../../mason_packages/linux-x86_64/libpng/1.6.25/lib/libpng.a -lz -lm ../../../mason_packages/linux-x86_64/libjpeg-turbo/1.5.0/lib/libjpeg.a libnunicode.a libicu.a -lz -static-libstdc++ -Wl,-Bsymbolic-functions ../../../mason_packages/linux-x86_64/libuv/1.9.1/lib/libuv.a -lrt -lpthread -lnsl -ldl 31 | 32 | g++ \ 33 | -ftemplate-depth=1024 \ 34 | -Wall \ 35 | -Wextra \ 36 | -Wshadow \ 37 | -Wnon-virtual-dtor \ 38 | -Wno-variadic-macros \ 39 | -Wno-unknown-pragmas \ 40 | -Werror -fext-numeric-literals \ 41 | -static-libstdc++ \ 42 | -g bin/render_stripped.cpp.o \ 43 | lib/linux/libmbgl-core.a \ 44 | lib/linux/libmbgl-filesource.a \ 45 | lib/linux/libmbgl-loop-uv.a \ 46 | lib/linux/libsqlite.a \ 47 | -Wl,--no-as-needed -lcurl \ 48 | -Wl,--as-needed lib/linux/libmbgl-core.a \ 49 | -lOSMesa \ 50 | lib/linux/libpng.a \ 51 | -lz \ 52 | -lm \ 53 | lib/linux/libjpeg.a \ 54 | lib/linux/libnunicode.a \ 55 | lib/linux/libicu.a \ 56 | -Wl,-Bsymbolic-functions lib/linux/libuv.a \ 57 | -lrt \ 58 | -lpthread \ 59 | -lnsl \ 60 | -ldl \ 61 | -o bin/mbgl-render-stripped \ 62 | 63 | -------------------------------------------------------------------------------- /mbgl/c/include/auto_cpu_timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct auto_cpu_timer { 7 | std::chrono::time_point start; 8 | auto_cpu_timer() : start(std::chrono::high_resolution_clock::now()) { 9 | } 10 | ~auto_cpu_timer() { 11 | auto end = std::chrono::high_resolution_clock::now(); 12 | std::chrono::microseconds elapsed = 13 | std::chrono::duration_cast(end - start); 14 | std::cerr << elapsed.count() << "us" << std::endl; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /mbgl/c/include/include/jni/string_conversion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This file replaces the default implementation in jni.hpp. 4 | 5 | #include 6 | 7 | namespace jni { 8 | 9 | inline std::u16string convertUTF8ToUTF16(const std::string& str) { 10 | return mbgl::util::convertUTF8ToUTF16(str); 11 | } 12 | 13 | inline std::string convertUTF16ToUTF8(const std::u16string& str) { 14 | return mbgl::util::convertUTF16ToUTF8(str); 15 | } 16 | 17 | } // namespace jni 18 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/gl/headless_backend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class HeadlessBackend : public RendererBackend { 11 | public: 12 | HeadlessBackend(Size = { 256, 256 }); 13 | ~HeadlessBackend() override; 14 | 15 | void bind() override; 16 | Size getFramebufferSize() const override; 17 | void updateAssumedState() override; 18 | 19 | void setSize(Size); 20 | PremultipliedImage readStillImage(); 21 | 22 | class Impl { 23 | public: 24 | virtual ~Impl() = default; 25 | virtual gl::ProcAddress getExtensionFunctionPointer(const char*) = 0; 26 | virtual void activateContext() = 0; 27 | virtual void deactivateContext() {} 28 | }; 29 | 30 | private: 31 | // Implementation specific functions 32 | gl::ProcAddress getExtensionFunctionPointer(const char*) override; 33 | 34 | void activate() override; 35 | void deactivate() override; 36 | 37 | void createImpl(); 38 | 39 | private: 40 | std::unique_ptr impl; 41 | 42 | Size size; 43 | float pixelRatio; 44 | bool active = false; 45 | 46 | class View; 47 | std::unique_ptr view; 48 | }; 49 | 50 | } // namespace mbgl 51 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/gl/headless_frontend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | class FileSource; 15 | class Scheduler; 16 | class Renderer; 17 | class RendererBackend; 18 | class Map; 19 | class TransformState; 20 | 21 | class HeadlessFrontend : public RendererFrontend { 22 | public: 23 | HeadlessFrontend(float pixelRatio_, FileSource&, Scheduler&, const optional programCacheDir = {}, GLContextMode mode = GLContextMode::Unique, const optional localFontFamily = {}); 24 | HeadlessFrontend(Size, float pixelRatio_, FileSource&, Scheduler&, const optional programCacheDir = {}, GLContextMode mode = GLContextMode::Unique, const optional localFontFamily = {}); 25 | ~HeadlessFrontend() override; 26 | 27 | void reset() override; 28 | void update(std::shared_ptr) override; 29 | void setObserver(RendererObserver&) override; 30 | 31 | Size getSize() const; 32 | void setSize(Size); 33 | 34 | Renderer* getRenderer(); 35 | RendererBackend* getBackend(); 36 | CameraOptions getCameraOptions(); 37 | 38 | bool hasImage(const std::string&); 39 | bool hasLayer(const std::string&); 40 | bool hasSource(const std::string&); 41 | 42 | ScreenCoordinate pixelForLatLng(const LatLng&); 43 | LatLng latLngForPixel(const ScreenCoordinate&); 44 | 45 | PremultipliedImage readStillImage(); 46 | PremultipliedImage render(Map&); 47 | 48 | optional getTransformState() const; 49 | 50 | private: 51 | Size size; 52 | float pixelRatio; 53 | 54 | HeadlessBackend backend; 55 | util::AsyncTask asyncInvalidate; 56 | 57 | std::unique_ptr renderer; 58 | std::shared_ptr updateParameters; 59 | }; 60 | 61 | } // namespace mbgl 62 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/map/map_snapshotter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace mbgl { 15 | 16 | template class ActorRef; 17 | struct CameraOptions; 18 | class FileSource; 19 | class Size; 20 | class LatLngBounds; 21 | 22 | namespace style { 23 | class Style; 24 | } // namespace style 25 | 26 | class MapSnapshotter { 27 | public: 28 | MapSnapshotter(FileSource* fileSource, 29 | std::shared_ptr scheduler, 30 | const std::pair style, 31 | const Size&, 32 | const float pixelRatio, 33 | const optional cameraOptions, 34 | const optional region, 35 | const optional cacheDir = {}, 36 | const optional localFontFamily = {}); 37 | 38 | ~MapSnapshotter(); 39 | 40 | void setStyleURL(const std::string& styleURL); 41 | std::string getStyleURL() const; 42 | 43 | void setStyleJSON(const std::string& styleJSON); 44 | std::string getStyleJSON() const; 45 | 46 | void setSize(const Size&); 47 | Size getSize() const; 48 | 49 | void setCameraOptions(const CameraOptions&); 50 | CameraOptions getCameraOptions() const; 51 | 52 | void setRegion(const LatLngBounds&); 53 | LatLngBounds getRegion() const; 54 | 55 | using PointForFn = std::function; 56 | using LatLngForFn = std::function; 57 | using Attributions = std::vector; 58 | using Callback = std::function; 59 | void snapshot(ActorRef); 60 | 61 | private: 62 | class Impl; 63 | std::unique_ptr> impl; 64 | }; 65 | 66 | } // namespace mbgl 67 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/storage/file_source_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | 12 | class Mailbox; 13 | 14 | class FileSourceRequest : public AsyncRequest { 15 | public: 16 | FileSourceRequest(FileSource::Callback&& callback); 17 | ~FileSourceRequest() final; 18 | 19 | void onCancel(std::function&& callback); 20 | void setResponse(const Response& res); 21 | 22 | ActorRef actor(); 23 | 24 | private: 25 | FileSource::Callback responseCallback = nullptr; 26 | std::function cancelCallback = nullptr; 27 | 28 | std::shared_ptr mailbox; 29 | }; 30 | 31 | } // namespace mbgl 32 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/storage/local_file_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | class ActorRef; 9 | class FileSourceRequest; 10 | 11 | void requestLocalFile(const std::string&, ActorRef); 12 | 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/storage/offline_download.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | class OfflineDatabase; 15 | class FileSource; 16 | class AsyncRequest; 17 | class Response; 18 | class Tileset; 19 | 20 | namespace style { 21 | class Parser; 22 | } // namespace style 23 | 24 | /** 25 | * Coordinates the request and storage of all resources for an offline region. 26 | 27 | * @private 28 | */ 29 | class OfflineDownload { 30 | public: 31 | OfflineDownload(int64_t id, OfflineRegionDefinition&&, OfflineDatabase& offline, OnlineFileSource& online); 32 | ~OfflineDownload(); 33 | 34 | void setObserver(std::unique_ptr); 35 | void setState(OfflineRegionDownloadState); 36 | 37 | OfflineRegionStatus getStatus() const; 38 | 39 | private: 40 | void activateDownload(); 41 | void continueDownload(); 42 | void deactivateDownload(); 43 | 44 | /* 45 | * Ensure that the resource is stored in the database, requesting it if necessary. 46 | * While the request is in progress, it is recorded in `requests`. If the download 47 | * is deactivated, all in progress requests are cancelled. 48 | */ 49 | void ensureResource(const Resource&, std::function = {}); 50 | 51 | void onMapboxTileCountLimitExceeded(); 52 | 53 | int64_t id; 54 | OfflineRegionDefinition definition; 55 | OfflineDatabase& offlineDatabase; 56 | OnlineFileSource& onlineFileSource; 57 | OfflineRegionStatus status; 58 | std::unique_ptr observer; 59 | 60 | std::list> requests; 61 | std::unordered_set requiredSourceURLs; 62 | std::deque resourcesRemaining; 63 | std::list> buffer; 64 | 65 | void queueResource(Resource); 66 | void queueTiles(style::SourceType, uint16_t tileSize, const Tileset&); 67 | }; 68 | 69 | } // namespace mbgl 70 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/storage/offline_schema.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // THIS IS A GENERATED FILE; EDIT offline_schema.sql INSTEAD 4 | // To regenerate, run `node platform/default/mbgl/storage/offline_schema.js` 5 | 6 | namespace mbgl { 7 | 8 | static constexpr const char* offlineDatabaseSchema = 9 | "CREATE TABLE resources (\n" 10 | " id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" 11 | " url TEXT NOT NULL,\n" 12 | " kind INTEGER NOT NULL,\n" 13 | " expires INTEGER,\n" 14 | " modified INTEGER,\n" 15 | " etag TEXT,\n" 16 | " data BLOB,\n" 17 | " compressed INTEGER NOT NULL DEFAULT 0,\n" 18 | " accessed INTEGER NOT NULL,\n" 19 | " must_revalidate INTEGER NOT NULL DEFAULT 0,\n" 20 | " UNIQUE (url)\n" 21 | ");\n" 22 | "CREATE TABLE tiles (\n" 23 | " id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" 24 | " url_template TEXT NOT NULL,\n" 25 | " pixel_ratio INTEGER NOT NULL,\n" 26 | " z INTEGER NOT NULL,\n" 27 | " x INTEGER NOT NULL,\n" 28 | " y INTEGER NOT NULL,\n" 29 | " expires INTEGER,\n" 30 | " modified INTEGER,\n" 31 | " etag TEXT,\n" 32 | " data BLOB,\n" 33 | " compressed INTEGER NOT NULL DEFAULT 0,\n" 34 | " accessed INTEGER NOT NULL,\n" 35 | " must_revalidate INTEGER NOT NULL DEFAULT 0,\n" 36 | " UNIQUE (url_template, pixel_ratio, z, x, y)\n" 37 | ");\n" 38 | "CREATE TABLE regions (\n" 39 | " id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" 40 | " definition TEXT NOT NULL,\n" 41 | " description BLOB\n" 42 | ");\n" 43 | "CREATE TABLE region_resources (\n" 44 | " region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE,\n" 45 | " resource_id INTEGER NOT NULL REFERENCES resources(id),\n" 46 | " UNIQUE (region_id, resource_id)\n" 47 | ");\n" 48 | "CREATE TABLE region_tiles (\n" 49 | " region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE,\n" 50 | " tile_id INTEGER NOT NULL REFERENCES tiles(id),\n" 51 | " UNIQUE (region_id, tile_id)\n" 52 | ");\n" 53 | "CREATE INDEX resources_accessed\n" 54 | "ON resources (accessed);\n" 55 | "CREATE INDEX tiles_accessed\n" 56 | "ON tiles (accessed);\n" 57 | "CREATE INDEX region_resources_resource_id\n" 58 | "ON region_resources (resource_id);\n" 59 | "CREATE INDEX region_tiles_tile_id\n" 60 | "ON region_tiles (tile_id);\n" 61 | ; 62 | 63 | } // namespace mbgl 64 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/text/unaccent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace platform { 7 | 8 | // Non-locale-aware diacritic folding based on nunicode 9 | // Used as a fallback when locale-aware comparisons aren't available 10 | std::string unaccent(const std::string &string); 11 | 12 | } // namespace platform 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/util/default_styles.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace util { 8 | namespace default_styles { 9 | 10 | struct DefaultStyle { 11 | const char* url; 12 | const char* name; 13 | const unsigned currentVersion; 14 | }; 15 | 16 | constexpr const DefaultStyle streets = { "mapbox://styles/mapbox/streets-v11", "Streets", 11 }; 17 | constexpr const DefaultStyle outdoors = { "mapbox://styles/mapbox/outdoors-v11", "Outdoors", 11 }; 18 | constexpr const DefaultStyle light = { "mapbox://styles/mapbox/light-v10", "Light", 10 }; 19 | constexpr const DefaultStyle dark = { "mapbox://styles/mapbox/dark-v10", "Dark", 10 }; 20 | constexpr const DefaultStyle satellite = { "mapbox://styles/mapbox/satellite-v9", "Satellite", 9 }; 21 | constexpr const DefaultStyle satelliteStreets = { "mapbox://styles/mapbox/satellite-streets-v11", "Satellite Streets", 11 }; 22 | 23 | const DefaultStyle orderedStyles[] = { 24 | streets, outdoors, light, dark, satellite, satelliteStreets, 25 | }; 26 | const size_t numOrderedStyles = sizeof(orderedStyles) / sizeof(DefaultStyle); 27 | 28 | } // end namespace default_styles 29 | } // end namespace util 30 | } // end namespace mbgl 31 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/util/default_thread_pool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | 12 | class ThreadPool : public Scheduler { 13 | public: 14 | ThreadPool(std::size_t count); 15 | ~ThreadPool() override; 16 | 17 | void schedule(std::weak_ptr) override; 18 | 19 | private: 20 | std::vector threads; 21 | std::queue> queue; 22 | std::mutex mutex; 23 | std::condition_variable cv; 24 | bool terminate { false }; 25 | }; 26 | 27 | } // namespace mbgl 28 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/util/shared_thread_pool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | std::shared_ptr sharedThreadPool(); 8 | 9 | } // namespace mbgl 10 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/box.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mapbox { 6 | namespace geometry { 7 | 8 | template 9 | struct box 10 | { 11 | using coordinate_type = T; 12 | using point_type = point; 13 | 14 | constexpr box(point_type const& min_, point_type const& max_) 15 | : min(min_), max(max_) 16 | { 17 | } 18 | 19 | point_type min; 20 | point_type max; 21 | }; 22 | 23 | template 24 | constexpr bool operator==(box const& lhs, box const& rhs) 25 | { 26 | return lhs.min == rhs.min && lhs.max == rhs.max; 27 | } 28 | 29 | template 30 | constexpr bool operator!=(box const& lhs, box const& rhs) 31 | { 32 | return lhs.min != rhs.min || lhs.max != rhs.max; 33 | } 34 | 35 | } // namespace geometry 36 | } // namespace mapbox 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/empty.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mapbox { 4 | namespace geometry { 5 | 6 | struct empty 7 | { 8 | }; // this Geometry type represents the empty point set, ∅, for the coordinate space (OGC Simple Features). 9 | 10 | constexpr bool operator==(empty, empty) { return true; } 11 | constexpr bool operator!=(empty, empty) { return false; } 12 | constexpr bool operator<(empty, empty) { return false; } 13 | constexpr bool operator>(empty, empty) { return false; } 14 | constexpr bool operator<=(empty, empty) { return true; } 15 | constexpr bool operator>=(empty, empty) { return true; } 16 | 17 | } // namespace geometry 18 | } // namespace mapbox 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/envelope.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template 12 | box envelope(G const& geometry) 13 | { 14 | using limits = std::numeric_limits; 15 | 16 | T min_t = limits::has_infinity ? -limits::infinity() : limits::min(); 17 | T max_t = limits::has_infinity ? limits::infinity() : limits::max(); 18 | 19 | point min(max_t, max_t); 20 | point max(min_t, min_t); 21 | 22 | for_each_point(geometry, [&](point const& point) { 23 | if (min.x > point.x) min.x = point.x; 24 | if (min.y > point.y) min.y = point.y; 25 | if (max.x < point.x) max.x = point.x; 26 | if (max.y < point.y) max.y = point.y; 27 | }); 28 | 29 | return box(min, max); 30 | } 31 | 32 | } // namespace geometry 33 | } // namespace mapbox 34 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/for_each_point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mapbox { 6 | namespace geometry { 7 | 8 | template 9 | void for_each_point(mapbox::geometry::empty const&, F&&) 10 | { 11 | } 12 | 13 | template 14 | auto for_each_point(Point&& point, F&& f) 15 | -> decltype(point.x, point.y, void()) 16 | { 17 | f(std::forward(point)); 18 | } 19 | 20 | template 21 | auto for_each_point(Container&& container, F&& f) 22 | -> decltype(container.begin(), container.end(), void()); 23 | 24 | template 25 | void for_each_point(mapbox::util::variant const& geom, F&& f) 26 | { 27 | mapbox::util::variant::visit(geom, [&](auto const& g) { 28 | for_each_point(g, f); 29 | }); 30 | } 31 | 32 | template 33 | void for_each_point(mapbox::util::variant& geom, F&& f) 34 | { 35 | mapbox::util::variant::visit(geom, [&](auto& g) { 36 | for_each_point(g, f); 37 | }); 38 | } 39 | 40 | template 41 | auto for_each_point(Container&& container, F&& f) 42 | -> decltype(container.begin(), container.end(), void()) 43 | { 44 | for (auto& e : container) 45 | { 46 | for_each_point(e, f); 47 | } 48 | } 49 | 50 | } // namespace geometry 51 | } // namespace mapbox 52 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/geometry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | // stl 14 | #include 15 | 16 | namespace mapbox { 17 | namespace geometry { 18 | 19 | template class Cont = std::vector> 20 | struct geometry_collection; 21 | 22 | template class Cont = std::vector> 23 | using geometry_base = mapbox::util::variant, 25 | line_string, 26 | polygon, 27 | multi_point, 28 | multi_line_string, 29 | multi_polygon, 30 | geometry_collection>; 31 | 32 | template class Cont = std::vector> 33 | struct geometry : geometry_base 34 | { 35 | using coordinate_type = T; 36 | using geometry_base::geometry_base; 37 | }; 38 | 39 | template class Cont> 40 | struct geometry_collection : Cont> 41 | { 42 | using coordinate_type = T; 43 | using geometry_type = geometry; 44 | using container_type = Cont; 45 | using size_type = typename container_type::size_type; 46 | 47 | template 48 | geometry_collection(Args&&... args) : container_type(std::forward(args)...) 49 | { 50 | } 51 | geometry_collection(std::initializer_list args) 52 | : container_type(std::move(args)) {} 53 | }; 54 | 55 | } // namespace geometry 56 | } // namespace mapbox 57 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/line_string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct line_string : Cont> 13 | { 14 | using coordinate_type = T; 15 | using point_type = point; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | line_string(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | line_string(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/multi_line_string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct multi_line_string : Cont> 13 | { 14 | using coordinate_type = T; 15 | using line_string_type = line_string; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | multi_line_string(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | multi_line_string(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/multi_point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct multi_point : Cont> 13 | { 14 | using coordinate_type = T; 15 | using point_type = point; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | multi_point(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | multi_point(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/multi_polygon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct multi_polygon : Cont> 13 | { 14 | using coordinate_type = T; 15 | using polygon_type = polygon; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | multi_polygon(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | multi_polygon(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mapbox { 4 | namespace geometry { 5 | 6 | template 7 | struct point 8 | { 9 | using coordinate_type = T; 10 | 11 | constexpr point() 12 | : x(), y() 13 | { 14 | } 15 | constexpr point(T x_, T y_) 16 | : x(x_), y(y_) 17 | { 18 | } 19 | 20 | T x; 21 | T y; 22 | }; 23 | 24 | #pragma GCC diagnostic push 25 | #pragma GCC diagnostic ignored "-Wfloat-equal" 26 | 27 | template 28 | constexpr bool operator==(point const& lhs, point const& rhs) 29 | { 30 | return lhs.x == rhs.x && lhs.y == rhs.y; 31 | } 32 | 33 | #pragma GCC diagnostic pop 34 | 35 | template 36 | constexpr bool operator!=(point const& lhs, point const& rhs) 37 | { 38 | return !(lhs == rhs); 39 | } 40 | 41 | } // namespace geometry 42 | } // namespace mapbox 43 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/polygon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | 6 | // stl 7 | #include 8 | 9 | namespace mapbox { 10 | namespace geometry { 11 | 12 | template class Cont = std::vector> 13 | struct linear_ring : Cont> 14 | { 15 | using coordinate_type = T; 16 | using point_type = point; 17 | using container_type = Cont; 18 | using size_type = typename container_type::size_type; 19 | 20 | template 21 | linear_ring(Args&&... args) : container_type(std::forward(args)...) 22 | { 23 | } 24 | linear_ring(std::initializer_list args) 25 | : container_type(std::move(args)) {} 26 | }; 27 | 28 | template class Cont = std::vector> 29 | struct polygon : Cont> 30 | { 31 | using coordinate_type = T; 32 | using linear_ring_type = linear_ring; 33 | using container_type = Cont; 34 | using size_type = typename container_type::size_type; 35 | 36 | template 37 | polygon(Args&&... args) : container_type(std::forward(args)...) 38 | { 39 | } 40 | polygon(std::initializer_list args) 41 | : container_type(std::move(args)) {} 42 | }; 43 | 44 | } // namespace geometry 45 | } // namespace mapbox 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/optional.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAPBOX_UTIL_OPTIONAL_HPP 2 | #define MAPBOX_UTIL_OPTIONAL_HPP 3 | 4 | #pragma message("This implementation of optional is deprecated. See https://github.com/mapbox/variant/issues/64.") 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace mapbox { 12 | namespace util { 13 | 14 | template 15 | class optional 16 | { 17 | static_assert(!std::is_reference::value, "optional doesn't support references"); 18 | 19 | struct none_type 20 | { 21 | }; 22 | 23 | variant variant_; 24 | 25 | public: 26 | optional() = default; 27 | 28 | optional(optional const& rhs) 29 | { 30 | if (this != &rhs) 31 | { // protect against invalid self-assignment 32 | variant_ = rhs.variant_; 33 | } 34 | } 35 | 36 | optional(T const& v) { variant_ = v; } 37 | 38 | explicit operator bool() const noexcept { return variant_.template is(); } 39 | 40 | T const& get() const { return variant_.template get(); } 41 | T& get() { return variant_.template get(); } 42 | 43 | T const& operator*() const { return this->get(); } 44 | T operator*() { return this->get(); } 45 | 46 | optional& operator=(T const& v) 47 | { 48 | variant_ = v; 49 | return *this; 50 | } 51 | 52 | optional& operator=(optional const& rhs) 53 | { 54 | if (this != &rhs) 55 | { 56 | variant_ = rhs.variant_; 57 | } 58 | return *this; 59 | } 60 | 61 | template 62 | void emplace(Args&&... args) 63 | { 64 | variant_ = T{std::forward(args)...}; 65 | } 66 | 67 | void reset() { variant_ = none_type{}; } 68 | 69 | }; // class optional 70 | 71 | } // namespace util 72 | } // namespace mapbox 73 | 74 | #endif // MAPBOX_UTIL_OPTIONAL_HPP 75 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/variant_io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAPBOX_UTIL_VARIANT_IO_HPP 2 | #define MAPBOX_UTIL_VARIANT_IO_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace mapbox { 9 | namespace util { 10 | 11 | namespace detail { 12 | // operator<< helper 13 | template 14 | class printer 15 | { 16 | public: 17 | explicit printer(Out& out) 18 | : out_(out) {} 19 | printer& operator=(printer const&) = delete; 20 | 21 | // visitor 22 | template 23 | void operator()(T const& operand) const 24 | { 25 | out_ << operand; 26 | } 27 | 28 | private: 29 | Out& out_; 30 | }; 31 | } 32 | 33 | // operator<< 34 | template 35 | VARIANT_INLINE std::basic_ostream& 36 | operator<<(std::basic_ostream& out, variant const& rhs) 37 | { 38 | detail::printer> visitor(out); 39 | apply_visitor(visitor, rhs); 40 | return out; 41 | } 42 | } // namespace util 43 | } // namespace mapbox 44 | 45 | #endif // MAPBOX_UTIL_VARIANT_IO_HPP 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/variant_visitor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAPBOX_UTIL_VARIANT_VISITOR_HPP 2 | #define MAPBOX_UTIL_VARIANT_VISITOR_HPP 3 | 4 | namespace mapbox { 5 | namespace util { 6 | 7 | template 8 | struct visitor; 9 | 10 | template 11 | struct visitor : Fn 12 | { 13 | using type = Fn; 14 | using Fn::operator(); 15 | 16 | visitor(Fn fn) : Fn(fn) {} 17 | }; 18 | 19 | template 20 | struct visitor : Fn, visitor 21 | { 22 | using type = visitor; 23 | using Fn::operator(); 24 | using visitor::operator(); 25 | 26 | visitor(Fn fn, Fns... fns) : Fn(fn), visitor(fns...) {} 27 | }; 28 | 29 | template 30 | visitor make_visitor(Fns... fns) 31 | { 32 | return visitor(fns...); 33 | } 34 | 35 | } // namespace util 36 | } // namespace mapbox 37 | 38 | #endif // MAPBOX_UTIL_VARIANT_VISITOR_HPP 39 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/actor/aspiring_actor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | template 15 | class EstablishedActor; 16 | 17 | template 18 | class Actor; 19 | 20 | /* 21 | An `AspiringActor` is one half of the pair of types that comprise an actor (see `Actor`), 22 | the other half being `EstablishedActor`. It is responsible for: 23 | - ownership of the actor's `Mailbox` 24 | - allocating the memory for (but *not* constructing) the target object `O` 25 | 26 | Using these two pieces--the mailbox and a stable address for `O`--an `AspiringActor` can 27 | accept messages for the target object, or provide `ActorRef`s that do so, before the object 28 | has actually been constructed by the corresponding `EstablishedActor`. (Such messages are 29 | queued in the mailbox until after the object is constructed.) 30 | 31 | This allows for an `AspiringActor` to be created and safely used by a thread other than the 32 | one on which the target object will (eventually) live. 33 | */ 34 | template 35 | class AspiringActor { 36 | public: 37 | AspiringActor() : mailbox(std::make_shared()) { 38 | // mailbox starts closed because the `Object` hasn't yet been constructed 39 | assert(!mailbox->isOpen()); 40 | } 41 | 42 | AspiringActor(const AspiringActor&) = delete; 43 | 44 | ActorRef> self() { 45 | return ActorRef>(object(), mailbox); 46 | } 47 | 48 | private: 49 | std::shared_ptr mailbox; 50 | std::aligned_storage_t objectStorage; 51 | 52 | Object& object() { 53 | return *reinterpret_cast(&objectStorage); 54 | } 55 | 56 | friend class EstablishedActor; 57 | friend class Actor; 58 | }; 59 | 60 | } // namespace mbgl 61 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/actor/mailbox.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class Scheduler; 12 | class Message; 13 | 14 | class Mailbox : public std::enable_shared_from_this { 15 | public: 16 | 17 | // Create a "holding" mailbox, messages to which will remain queued, 18 | // unconsumed, until the mailbox is associated with a Scheduler using 19 | // start(). This allows a Mailbox object to be created on one thread and 20 | // later transferred to a different target thread that may not yet exist. 21 | Mailbox(); 22 | 23 | Mailbox(Scheduler&); 24 | 25 | // Attach the given scheduler to this mailbox and begin processing messages 26 | // sent to it. The mailbox must be a "holding" mailbox, as created by the 27 | // default constructor Mailbox(). 28 | void open(Scheduler& scheduler_); 29 | void close(); 30 | 31 | bool isOpen() const; 32 | 33 | void push(std::unique_ptr); 34 | void receive(); 35 | 36 | static void maybeReceive(std::weak_ptr); 37 | 38 | private: 39 | optional scheduler; 40 | 41 | std::recursive_mutex receivingMutex; 42 | std::mutex pushingMutex; 43 | 44 | bool closed { false }; 45 | 46 | std::mutex queueMutex; 47 | std::queue> queue; 48 | }; 49 | 50 | } // namespace mbgl 51 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/actor/scheduler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class Mailbox; 8 | 9 | /* 10 | A `Scheduler` is responsible for coordinating the processing of messages by 11 | one or more actors via their mailboxes. It's an abstract interface. Currently, 12 | the following concrete implementations exist: 13 | 14 | * `ThreadPool` can coordinate an unlimited number of actors over any number of 15 | threads via a pool, preserving the following behaviors: 16 | 17 | - Messages from each individual mailbox are processed in order 18 | - Only a single message from a mailbox is processed at a time; there is no 19 | concurrency within a mailbox 20 | 21 | Subject to these constraints, processing can happen on whatever thread in the 22 | pool is available. 23 | 24 | * `Scheduler::GetCurrent()` is typically used to create a mailbox and `ActorRef` 25 | for an object that lives on the main thread and is not itself wrapped an 26 | `Actor`. The underlying implementation of this Scheduler should usually be 27 | a `RunLoop` 28 | auto mailbox = std::make_shared(*Scheduler::Get()); 29 | Actor worker(threadPool, ActorRef(*this, mailbox)); 30 | */ 31 | class Scheduler { 32 | public: 33 | virtual ~Scheduler() = default; 34 | 35 | // Used by a Mailbox when it has a message in its queue to request that it 36 | // be scheduled. Specifically, the scheduler is expected to asynchronously 37 | // call `receive() on the given mailbox, provided it still exists at that 38 | // time. 39 | virtual void schedule(std::weak_ptr) = 0; 40 | 41 | // Set/Get the current Scheduler for this thread 42 | static Scheduler* GetCurrent(); 43 | static void SetCurrent(Scheduler*); 44 | }; 45 | 46 | } // namespace mbgl 47 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/background_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class BackgroundLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/circle_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class CircleLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/custom_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class CustomLayerFactory : public LayerFactory { 11 | protected: 12 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 13 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 14 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 15 | }; 16 | 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/fill_extrusion_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class FillExtrusionLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/fill_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class FillLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/heatmap_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class HeatmapLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/hillshade_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class HillshadeLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RenderLayer; 8 | 9 | /** 10 | * @brief The LayerFactory abstract class 11 | * 12 | * This class is responsible for creation of the layer objects that belong to a concrete layer type. 13 | */ 14 | class LayerFactory { 15 | public: 16 | virtual ~LayerFactory() = default; 17 | /// Returns the layer type data. 18 | virtual const style::LayerTypeInfo* getTypeInfo() const noexcept = 0; 19 | /// Returns a new Layer instance on success call; returns `nulltptr` otherwise. 20 | virtual std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept = 0; 21 | /// Returns a new RenderLayer instance on success call; returns `nulltptr` otherwise. 22 | virtual std::unique_ptr createRenderLayer(Immutable) noexcept = 0; 23 | 24 | protected: 25 | optional getSource(const style::conversion::Convertible& value) const noexcept; 26 | bool initSourceLayerAndFilter(style::Layer*, const style::conversion::Convertible& value) const noexcept; 27 | }; 28 | 29 | } // namespace mbgl 30 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/line_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class LineLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/raster_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RasterLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/symbol_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class SymbolLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/map/change.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | enum MapChange : uint8_t { 8 | MapChangeRegionWillChange = 0, 9 | MapChangeRegionWillChangeAnimated = 1, 10 | MapChangeRegionIsChanging = 2, 11 | MapChangeRegionDidChange = 3, 12 | MapChangeRegionDidChangeAnimated = 4, 13 | MapChangeWillStartLoadingMap = 5, 14 | MapChangeDidFinishLoadingMap = 6, 15 | MapChangeDidFailLoadingMap = 7, 16 | MapChangeWillStartRenderingFrame = 8, 17 | MapChangeDidFinishRenderingFrame = 9, 18 | MapChangeDidFinishRenderingFrameFullyRendered = 10, 19 | MapChangeWillStartRenderingMap = 11, 20 | MapChangeDidFinishRenderingMap = 12, 21 | MapChangeDidFinishRenderingMapFullyRendered = 13, 22 | MapChangeDidFinishLoadingStyle = 14, 23 | MapChangeSourceDidChange = 15 24 | }; 25 | 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/map/map_observer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class MapObserver { 12 | public: 13 | virtual ~MapObserver() = default; 14 | 15 | static MapObserver& nullObserver() { 16 | static MapObserver mapObserver; 17 | return mapObserver; 18 | } 19 | 20 | enum class CameraChangeMode : uint32_t { 21 | Immediate, 22 | Animated 23 | }; 24 | 25 | enum class RenderMode : uint32_t { 26 | Partial, 27 | Full 28 | }; 29 | 30 | virtual void onCameraWillChange(CameraChangeMode) {} 31 | virtual void onCameraIsChanging() {} 32 | virtual void onCameraDidChange(CameraChangeMode) {} 33 | virtual void onWillStartLoadingMap() {} 34 | virtual void onDidFinishLoadingMap() {} 35 | virtual void onDidFailLoadingMap(std::exception_ptr) {} 36 | virtual void onWillStartRenderingFrame() {} 37 | virtual void onDidFinishRenderingFrame(RenderMode) {} 38 | virtual void onWillStartRenderingMap() {} 39 | virtual void onDidFinishRenderingMap(RenderMode) {} 40 | virtual void onDidFinishLoadingStyle() {} 41 | virtual void onSourceChanged(style::Source&) {} 42 | virtual void onDidBecomeIdle() {} 43 | }; 44 | 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/map/mode.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | using EnumType = uint32_t; 11 | 12 | enum class MapMode : EnumType { 13 | Continuous, // continually updating map 14 | Static, // a once-off still image of an arbitrary viewport 15 | Tile // a once-off still image of a single tile 16 | }; 17 | 18 | // We can choose to constrain the map both horizontally or vertically, or only 19 | // vertically e.g. while panning. 20 | enum class ConstrainMode : EnumType { 21 | None, 22 | HeightOnly, 23 | WidthAndHeight, 24 | }; 25 | 26 | // Satisfies embedding platforms that requires the viewport coordinate systems 27 | // to be set according to its standards. 28 | enum class ViewportMode : EnumType { 29 | Default, 30 | FlippedY, 31 | }; 32 | 33 | enum class MapDebugOptions : EnumType { 34 | NoDebug = 0, 35 | TileBorders = 1 << 1, 36 | ParseStatus = 1 << 2, 37 | Timestamps = 1 << 3, 38 | Collision = 1 << 4, 39 | Overdraw = 1 << 5, 40 | // FIXME: https://github.com/mapbox/mapbox-gl-native/issues/5117 41 | #if not MBGL_USE_GLES2 42 | StencilClip = 1 << 6, 43 | DepthBuffer = 1 << 7, 44 | #endif // MBGL_USE_GLES2 45 | }; 46 | 47 | MBGL_CONSTEXPR MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) { 48 | return MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)); 49 | } 50 | 51 | MBGL_CONSTEXPR MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) { 52 | return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs))); 53 | } 54 | 55 | MBGL_CONSTEXPR bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) { 56 | return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs); 57 | } 58 | 59 | MBGL_CONSTEXPR MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) { 60 | return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs))); 61 | } 62 | 63 | MBGL_CONSTEXPR MapDebugOptions operator~(MapDebugOptions value) { 64 | return MapDebugOptions(~mbgl::underlying_type(value)); 65 | } 66 | 67 | } // namespace mbgl 68 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/clamp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | template 9 | T clamp(T value, T min_, T max_) { 10 | return max(min_, min(max_, value)); 11 | } 12 | 13 | } // namespace util 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/log2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #if defined(__ANDROID__) 8 | #include 9 | #endif 10 | 11 | namespace mbgl { 12 | namespace util { 13 | 14 | // Computes the log2(x) rounded up to the next integer. 15 | // (== number of bits required to store x) 16 | uint32_t ceil_log2(uint64_t x); 17 | 18 | template 19 | T log2(T x) { 20 | // log2() is producing wrong results on ARMv5 binaries 21 | // running on ARMv7+ CPUs. 22 | #if defined(__ANDROID__) 23 | return ::log(x) / M_LN2; 24 | #else 25 | return ::log2(x); 26 | #endif 27 | } 28 | 29 | } // namespace util 30 | } // namespace mbgl 31 | 32 | // log2 is not available on Android before API 18. 33 | #if defined(__ANDROID__) && defined(__GNUC__) && \ 34 | defined(__ANDROID_API__) && __ANDROID_API__ < 18 35 | 36 | template 37 | typename std::enable_if_t::value, T> log2(T x) { 38 | return ::log(x) / M_LN2; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/minmax.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace util { 9 | 10 | template 11 | typename std::enable_if_t::value, T> max(T a, T b) { 12 | return std::max(a, b); 13 | } 14 | 15 | template 16 | typename std::enable_if_t::value, T> max(T a, T b) { 17 | return ::fmax(a, b); 18 | } 19 | 20 | template 21 | typename std::enable_if_t::value, T> max(T a, T b, Ts... args) { 22 | return max(a, max(b, args...)); 23 | } 24 | 25 | template 26 | typename std::enable_if_t::value, T> min(T a, T b) { 27 | return std::min(a, b); 28 | } 29 | 30 | template 31 | typename std::enable_if_t::value, T> min(T a, T b) { 32 | return ::fmin(a, b); 33 | } 34 | 35 | template 36 | typename std::enable_if_t::value, T> min(T a, T b, Ts... args) { 37 | return min(a, min(b, args...)); 38 | } 39 | 40 | } // namespace util 41 | } // namespace mbgl 42 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/wrap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | // Constrains n to the given range (including min, excluding max) via modular 9 | // arithmetic. 10 | template 11 | T wrap(T value, T min, T max) { 12 | T d = max - min; 13 | return std::fmod((std::fmod((value - min), d) + d), d) + min; 14 | } 15 | 16 | } // namespace util 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/backend_scope.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { 4 | 5 | class RendererBackend; 6 | 7 | class BackendScope { 8 | public: 9 | // There are two types of scopes: Creating an "Implicit" scope tells Mapbox GL that the 10 | // supporting windowing system has already activated the GL Backend and that no further actions 11 | // are required. Creating an "Explicit" scope actually enables the GL Backend, and disables it 12 | // when the BackendScope is destroyed. 13 | enum class ScopeType : bool { 14 | Implicit, 15 | Explicit, 16 | }; 17 | 18 | BackendScope(RendererBackend&, ScopeType = ScopeType::Explicit); 19 | ~BackendScope(); 20 | 21 | // Returns true when there is currently a BackendScope active in this thread. 22 | static bool exists(); 23 | 24 | private: 25 | void activate(); 26 | void deactivate(); 27 | 28 | BackendScope* priorScope; 29 | BackendScope* nextScope; 30 | RendererBackend& backend; 31 | const ScopeType scopeType; 32 | bool activated = false; 33 | }; 34 | 35 | } // namespace mbgl 36 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/mode.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | using EnumType = uint32_t; 8 | 9 | // We can avoid redundant GL calls when it is known that the GL context is not 10 | // being shared. In a shared GL context case, we need to make sure that the 11 | // correct GL configurations are in use - they might have changed between render 12 | // calls. 13 | enum class GLContextMode : EnumType { 14 | Unique, 15 | Shared, 16 | }; 17 | 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/query.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | /** 12 | * Options for query rendered features. 13 | */ 14 | class RenderedQueryOptions { 15 | public: 16 | RenderedQueryOptions(optional> layerIDs_ = {}, 17 | optional filter_ = {}) 18 | : layerIDs(std::move(layerIDs_)), 19 | filter(std::move(filter_)) {} 20 | 21 | /** layerIDs to include in the query */ 22 | optional> layerIDs; 23 | 24 | optional filter; 25 | }; 26 | 27 | /** 28 | * Options for query source features 29 | */ 30 | class SourceQueryOptions { 31 | public: 32 | SourceQueryOptions(optional> sourceLayers_ = {}, 33 | optional filter_ = {}) 34 | : sourceLayers(std::move(sourceLayers_)), 35 | filter(std::move(filter_)) {} 36 | 37 | // Required for VectorSource, ignored for GeoJSONSource 38 | optional> sourceLayers; 39 | 40 | optional filter; 41 | }; 42 | 43 | } // namespace mbgl 44 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/renderer_frontend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RendererObserver; 8 | class UpdateParameters; 9 | 10 | // The RenderFrontend is the bridge between the Map and 11 | // platform used to update and observer the Renderer 12 | // 13 | // It hides any threading specifics and always replies on 14 | // the original thread. 15 | class RendererFrontend { 16 | public: 17 | 18 | virtual ~RendererFrontend() = default; 19 | 20 | // Must synchronously clean up the Renderer if set 21 | virtual void reset() = 0; 22 | 23 | // Implementer must bind the renderer observer to the renderer in a 24 | // appropriate manner so that the callbacks occur on the main thread 25 | virtual void setObserver(RendererObserver&) = 0; 26 | 27 | // Coalescing updates is up to the implementer 28 | virtual void update(std::shared_ptr) = 0; 29 | }; 30 | 31 | } // namespace mbgl 32 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/renderer_observer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RendererObserver { 8 | public: 9 | virtual ~RendererObserver() = default; 10 | 11 | enum class RenderMode : uint32_t { 12 | Partial, 13 | Full 14 | }; 15 | 16 | // Signals that a repaint is required 17 | virtual void onInvalidate() {} 18 | 19 | // Resource failed to download / parse 20 | virtual void onResourceError(std::exception_ptr) {} 21 | 22 | // First frame 23 | virtual void onWillStartRenderingMap() {} 24 | 25 | // Start of frame, initial is the first frame for this map 26 | virtual void onWillStartRenderingFrame() {} 27 | 28 | // End of frame, boolean flags that a repaint is required 29 | virtual void onDidFinishRenderingFrame(RenderMode, bool) {} 30 | 31 | // Final frame 32 | virtual void onDidFinishRenderingMap() {} 33 | }; 34 | 35 | } // namespace mbgl 36 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/renderer_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | class UpdateParameters; 9 | 10 | /** 11 | * RendererState acts as a Memento object that is able to extract data out of UpdateParameters (an opaque object 12 | * from the public API perspective). 13 | */ 14 | class RendererState { 15 | public: 16 | 17 | // Obtains a CameraOptions out of a given UpdateParameters object. 18 | static CameraOptions getCameraOptions(const UpdateParameters&, const EdgeInsets& = {}); 19 | 20 | // Returns whether an image with the given ID exists from a given UpdateParamters object. 21 | static bool hasImage(const UpdateParameters&, const std::string& id); 22 | 23 | // Returns whether a layer with the given ID exists from a given UpdateParamters object. 24 | static bool hasLayer(const UpdateParameters&, const std::string& id); 25 | 26 | // Returns whether a source with the given ID exists from a given UpdateParamters object. 27 | static bool hasSource(const UpdateParameters&, const std::string& id); 28 | 29 | // Obtains the geographical coordinate out of a given screen coordinate. 30 | static ScreenCoordinate pixelForLatLng(const UpdateParameters&, const LatLng&); 31 | 32 | // Obtains the screen coordinate out of a given geographical coordinate. 33 | static LatLng latLngForPixel(const UpdateParameters&, const ScreenCoordinate&); 34 | }; 35 | 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/file_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | class FileSource : private util::noncopyable { 15 | public: 16 | virtual ~FileSource() = default; 17 | 18 | using Callback = std::function; 19 | 20 | // Request a resource. The callback will be called asynchronously, in the same 21 | // thread as the request was made. This thread must have an active RunLoop. The 22 | // request may be cancelled before completion by releasing the returned AsyncRequest. 23 | // If the request is cancelled before the callback is executed, the callback will 24 | // not be executed. 25 | virtual std::unique_ptr request(const Resource&, Callback) = 0; 26 | 27 | // When a file source supports consulting a local cache only, it must return true. 28 | // Cache-only requests are requests that aren't as urgent, but could be useful, e.g. 29 | // to cover part of the map while loading. The FileSource should only do cheap actions to 30 | // retrieve the data, e.g. load it from a cache, but not from the internet. 31 | virtual bool supportsCacheOnlyRequests() const { 32 | return false; 33 | } 34 | }; 35 | 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/network_status.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | namespace util { 10 | class AsyncTask; 11 | } // namespace util 12 | 13 | class NetworkStatus { 14 | public: 15 | enum class Status : uint8_t { 16 | Online, 17 | Offline, 18 | }; 19 | 20 | static Status Get(); 21 | static void Set(Status); 22 | 23 | static void Reachable(); 24 | 25 | static void Subscribe(util::AsyncTask* async); 26 | static void Unsubscribe(util::AsyncTask* async); 27 | 28 | private: 29 | static std::atomic online; 30 | static std::mutex mtx; 31 | static std::unordered_set observers; 32 | }; 33 | 34 | } // namespace mbgl 35 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/online_file_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class ResourceTransform; 11 | 12 | class OnlineFileSource : public FileSource { 13 | public: 14 | OnlineFileSource(); 15 | ~OnlineFileSource() override; 16 | 17 | void setAPIBaseURL(const std::string& t) { apiBaseURL = t; } 18 | std::string getAPIBaseURL() const { return apiBaseURL; } 19 | 20 | void setAccessToken(const std::string& t) { accessToken = t; } 21 | std::string getAccessToken() const { return accessToken; } 22 | 23 | void setResourceTransform(optional>&&); 24 | 25 | std::unique_ptr request(const Resource&, Callback) override; 26 | 27 | void setMaximumConcurrentRequests(uint32_t); 28 | uint32_t getMaximumConcurrentRequests() const; 29 | 30 | // For testing only. 31 | void setOnlineStatus(bool); 32 | 33 | private: 34 | friend class OnlineFileRequest; 35 | 36 | class Impl; 37 | const std::unique_ptr impl; 38 | std::string accessToken; 39 | std::string apiBaseURL = mbgl::util::API_BASE_URL; 40 | }; 41 | 42 | } // namespace mbgl 43 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/resource_transform.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class Mailbox; 12 | 13 | class ResourceTransform { 14 | public: 15 | using TransformCallback = std::function; 16 | using FinishedCallback = std::function; 17 | 18 | ResourceTransform(ActorRef, TransformCallback&&); 19 | 20 | void transform(Resource::Kind, const std::string&& url, FinishedCallback&&); 21 | 22 | private: 23 | TransformCallback transformCallback; 24 | }; 25 | 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/response.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class Response { 12 | public: 13 | Response() = default; 14 | Response(const Response&); 15 | Response& operator=(const Response&); 16 | 17 | public: 18 | class Error; 19 | // When this object is empty, the response was successful. 20 | std::unique_ptr error; 21 | 22 | // This is set to true for 204 Not Modified responses, and, for backward compatibility, 23 | // for 404 Not Found responses for tiles. 24 | bool noContent = false; 25 | 26 | // This is set to true for 304 Not Modified responses. 27 | bool notModified = false; 28 | 29 | // This is set to true when the server requested that no expired resources be used by 30 | // specifying "Cache-Control: must-revalidate". 31 | bool mustRevalidate = false; 32 | 33 | // The actual data of the response. Present only for non-error, non-notModified responses. 34 | std::shared_ptr data; 35 | 36 | optional modified; 37 | optional expires; 38 | optional etag; 39 | 40 | bool isFresh() const { 41 | return expires ? *expires > util::now() : !error; 42 | } 43 | 44 | // Indicates whether we are allowed to use this response according to HTTP caching rules. 45 | // It may or may not be stale. 46 | bool isUsable() const { 47 | return !mustRevalidate || (expires && *expires > util::now()); 48 | } 49 | }; 50 | 51 | class Response::Error { 52 | public: 53 | enum class Reason : uint8_t { 54 | Success = 1, 55 | NotFound = 2, 56 | Server = 3, 57 | Connection = 4, 58 | RateLimit = 5, 59 | Other = 6, 60 | } reason = Reason::Other; 61 | 62 | // An error message from the request handler, e.g. a server message or a system message 63 | // informing the user about the reason for the failure. 64 | std::string message; 65 | 66 | optional retryAfter; 67 | 68 | public: 69 | Error(Reason, std::string = "", optional = {}); 70 | }; 71 | 72 | } // namespace mbgl 73 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/color_ramp_property_value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | 10 | /* 11 | * Special-case implementation of (a subset of) the PropertyValue interface 12 | * used for building the HeatmapColor paint property traits class. 13 | */ 14 | class ColorRampPropertyValue { 15 | private: 16 | std::shared_ptr value; 17 | 18 | friend bool operator==(const ColorRampPropertyValue& lhs, const ColorRampPropertyValue& rhs) { 19 | return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value)); 20 | } 21 | 22 | friend bool operator!=(const ColorRampPropertyValue& lhs, const ColorRampPropertyValue& rhs) { 23 | return !(lhs == rhs); 24 | } 25 | 26 | public: 27 | ColorRampPropertyValue() : value(nullptr) {} 28 | ColorRampPropertyValue(std::shared_ptr value_) : value(std::move(value_)) {} 29 | 30 | bool isUndefined() const { return value.get() == nullptr; } 31 | 32 | // noop, needed for batch evaluation of paint property values to compile 33 | template 34 | Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; } 35 | 36 | Color evaluate(double rampEvaluationParameter) const { 37 | const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {rampEvaluationParameter})); 38 | return *expression::fromExpressionValue(*result); 39 | } 40 | 41 | bool isDataDriven() const { return false; } 42 | bool hasDataDrivenPropertyDifference(const ColorRampPropertyValue&) const { return false; } 43 | 44 | const expression::Expression& getExpression() const { return *value; } 45 | }; 46 | 47 | 48 | } // namespace style 49 | } // namespace mbgl 50 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace style { 7 | namespace conversion { 8 | 9 | // This is a forward-declaration only header intended to minimize dependencies and to improve 10 | // compilation speed. In order to specialize implementations and get access to the actual 11 | // implementation, include . 12 | 13 | struct Error { std::string message; }; 14 | 15 | template 16 | class ConversionTraits; 17 | 18 | class Convertible; 19 | 20 | template 21 | struct Converter; 22 | 23 | } // namespace conversion 24 | } // namespace style 25 | } // namespace mbgl 26 | 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/color_ramp_property_value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | namespace conversion { 9 | 10 | template <> 11 | struct Converter { 12 | optional operator()(const Convertible& value, Error& error, bool /* allowDataExpressions */ = false, bool /* convertTokens */ = false) const; 13 | }; 14 | 15 | } // namespace conversion 16 | } // namespace style 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/constant.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace mbgl { 14 | namespace style { 15 | namespace conversion { 16 | 17 | template <> 18 | struct Converter { 19 | optional operator()(const Convertible& value, Error& error) const; 20 | }; 21 | 22 | template <> 23 | struct Converter { 24 | optional operator()(const Convertible& value, Error& error) const; 25 | }; 26 | 27 | template <> 28 | struct Converter { 29 | optional operator()(const Convertible& value, Error& error) const; 30 | }; 31 | 32 | template 33 | struct Converter::value>> { 34 | optional operator()(const Convertible& value, Error& error) const; 35 | }; 36 | 37 | template <> 38 | struct Converter { 39 | optional operator()(const Convertible& value, Error& error) const; 40 | }; 41 | 42 | template 43 | struct Converter> { 44 | optional> operator()(const Convertible& value, Error& error) const; 45 | }; 46 | 47 | template <> 48 | struct Converter> { 49 | optional> operator()(const Convertible& value, Error& error) const; 50 | }; 51 | 52 | template <> 53 | struct Converter> { 54 | optional> operator()(const Convertible& value, Error& error) const; 55 | }; 56 | 57 | } // namespace conversion 58 | } // namespace style 59 | } // namespace mbgl 60 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/coordinate.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template<> 12 | struct Converter { 13 | public: 14 | optional operator() (const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/custom_geometry_source_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | optional operator()(const Convertible& value, Error& error) const; 14 | }; 15 | 16 | } // namespace conversion 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/filter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/function.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace conversion { 12 | 13 | bool hasTokens(const std::string&); 14 | std::unique_ptr convertTokenStringToFormatExpression(const std::string&); 15 | std::unique_ptr convertTokenStringToExpression(const std::string&); 16 | 17 | optional> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens); 18 | 19 | template 20 | optional> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens); 21 | 22 | } // namespace conversion 23 | } // namespace style 24 | } // namespace mbgl 25 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/geojson.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | // Workaround until https://github.com/mapbox/mapbox-gl-native/issues/5623 is done. 12 | optional parseGeoJSON(const std::string&, Error&); 13 | 14 | template <> 15 | struct Converter { 16 | public: 17 | optional operator()(const Convertible&, Error&) const; 18 | }; 19 | 20 | } // namespace conversion 21 | } // namespace style 22 | } // namespace mbgl 23 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/geojson_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | optional operator()(const Convertible& value, Error& error) const; 14 | }; 15 | 16 | } // namespace conversion 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/get_json_type.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | namespace conversion { 9 | 10 | std::string getJSONType(const Convertible& value); 11 | 12 | } // namespace conversion 13 | } // namespace style 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/layer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace conversion { 12 | 13 | template <> 14 | struct Converter> { 15 | public: 16 | optional> operator()(const Convertible& value, Error& error) const; 17 | }; 18 | 19 | optional setPaintProperties(Layer& layer, const Convertible& value); 20 | 21 | } // namespace conversion 22 | } // namespace style 23 | } // namespace mbgl 24 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/light.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/position.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | optional operator()(const Convertible& value, Error& error) const; 14 | }; 15 | 16 | } // namespace conversion 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/property_value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace mbgl { 14 | namespace style { 15 | namespace conversion { 16 | 17 | template 18 | struct Converter> { 19 | optional> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const; 20 | 21 | template 22 | PropertyValue maybeConvertTokens(const S& t) const { 23 | return PropertyValue(t); 24 | }; 25 | 26 | PropertyValue maybeConvertTokens(const std::string& t) const { 27 | return hasTokens(t) 28 | ? PropertyValue(PropertyExpression(convertTokenStringToExpression(t))) 29 | : PropertyValue(t); 30 | } 31 | 32 | PropertyValue maybeConvertTokens(const expression::Formatted& t) const { 33 | // This only works with a single-section `Formatted` created automatically 34 | // by parsing a plain-text `text-field` property. 35 | // Token conversion happens later than the initial string->Formatted conversion 36 | // General purpose `format` expressions with embedded tokens are not supported 37 | const std::string& firstUnformattedSection = t.sections[0].text; 38 | return hasTokens(firstUnformattedSection) 39 | ? PropertyValue(PropertyExpression(convertTokenStringToFormatExpression(firstUnformattedSection))) 40 | : PropertyValue(t); 41 | } 42 | }; 43 | 44 | } // namespace conversion 45 | } // namespace style 46 | } // namespace mbgl 47 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace conversion { 12 | 13 | template <> 14 | struct Converter> { 15 | public: 16 | optional> operator()(const Convertible& value, Error& error, const std::string& id) const; 17 | }; 18 | 19 | } // namespace conversion 20 | } // namespace style 21 | } // namespace mbgl 22 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/tileset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/transition_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/assertion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Assertion : public Expression { 15 | public: 16 | Assertion(type::Type type_, std::vector> inputs_); 17 | 18 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 19 | 20 | EvaluationResult evaluate(const EvaluationContext& params) const override; 21 | void eachChild(const std::function& visit) const override; 22 | 23 | bool operator==(const Expression& e) const override; 24 | 25 | std::vector> possibleOutputs() const override; 26 | 27 | mbgl::Value serialize() const override; 28 | std::string getOperator() const override; 29 | 30 | private: 31 | std::vector> inputs; 32 | }; 33 | 34 | } // namespace expression 35 | } // namespace style 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/at.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | 11 | class At : public Expression { 12 | public: 13 | At(std::unique_ptr index_, std::unique_ptr input_) : 14 | Expression(Kind::At, input_->getType().get().itemType), 15 | index(std::move(index_)), 16 | input(std::move(input_)) 17 | {} 18 | 19 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 20 | 21 | EvaluationResult evaluate(const EvaluationContext& params) const override; 22 | void eachChild(const std::function&) const override; 23 | 24 | bool operator==(const Expression& e) const override { 25 | if (e.getKind() == Kind::At) { 26 | auto rhs = static_cast(&e); 27 | return *index == *(rhs->index) && *input == *(rhs->input); 28 | } 29 | return false; 30 | } 31 | 32 | std::vector> possibleOutputs() const override { 33 | return { nullopt }; 34 | } 35 | 36 | std::string getOperator() const override { return "at"; } 37 | 38 | private: 39 | std::unique_ptr index; 40 | std::unique_ptr input; 41 | }; 42 | 43 | } // namespace expression 44 | } // namespace style 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/boolean_operator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mbgl { 9 | namespace style { 10 | namespace expression { 11 | 12 | class Any : public Expression { 13 | public: 14 | Any(std::vector> inputs_) : 15 | Expression(Kind::Any, type::Boolean), 16 | inputs(std::move(inputs_)) 17 | {} 18 | 19 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 20 | 21 | EvaluationResult evaluate(const EvaluationContext& params) const override; 22 | void eachChild(const std::function& visit) const override; 23 | bool operator==(const Expression& e) const override; 24 | std::vector> possibleOutputs() const override; 25 | 26 | std::string getOperator() const override { return "any"; } 27 | private: 28 | std::vector> inputs; 29 | }; 30 | 31 | class All : public Expression { 32 | public: 33 | All(std::vector> inputs_) : 34 | Expression(Kind::All, type::Boolean), 35 | inputs(std::move(inputs_)) 36 | {} 37 | 38 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 39 | 40 | EvaluationResult evaluate(const EvaluationContext& params) const override; 41 | void eachChild(const std::function& visit) const override; 42 | bool operator==(const Expression& e) const override; 43 | std::vector> possibleOutputs() const override; 44 | 45 | std::string getOperator() const override { return "all"; } 46 | private: 47 | std::vector> inputs; 48 | }; 49 | 50 | } // namespace expression 51 | } // namespace style 52 | } // namespace mbgl 53 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/case.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Case : public Expression { 15 | public: 16 | using Branch = std::pair, std::unique_ptr>; 17 | 18 | Case(type::Type type_, std::vector branches_, std::unique_ptr otherwise_) 19 | : Expression(Kind::Case, type_), branches(std::move(branches_)), otherwise(std::move(otherwise_)) { 20 | } 21 | 22 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 23 | 24 | EvaluationResult evaluate(const EvaluationContext& params) const override; 25 | void eachChild(const std::function& visit) const override; 26 | 27 | bool operator==(const Expression& e) const override; 28 | 29 | std::vector> possibleOutputs() const override; 30 | 31 | std::string getOperator() const override { return "case"; } 32 | private: 33 | std::vector branches; 34 | std::unique_ptr otherwise; 35 | }; 36 | 37 | } // namespace expression 38 | } // namespace style 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/check_subtype.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | namespace type { 11 | 12 | optional checkSubtype(const Type& expected, const Type& t); 13 | 14 | } // namespace type 15 | } // namespace expression 16 | } // namespace style 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/coalesce.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Coalesce : public Expression { 15 | public: 16 | using Args = std::vector>; 17 | Coalesce(const type::Type& type_, Args args_) : 18 | Expression(Kind::Coalesce, type_), 19 | args(std::move(args_)) 20 | {} 21 | 22 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 23 | 24 | 25 | EvaluationResult evaluate(const EvaluationContext& params) const override; 26 | 27 | void eachChild(const std::function& visit) const override; 28 | 29 | bool operator==(const Expression& e) const override; 30 | 31 | std::vector> possibleOutputs() const override; 32 | 33 | std::size_t getLength() const { 34 | return args.size(); 35 | } 36 | 37 | Expression* getChild(std::size_t i) const { 38 | return args.at(i).get(); 39 | } 40 | 41 | std::string getOperator() const override { return "coalesce"; } 42 | private: 43 | Args args; 44 | }; 45 | 46 | } // namespace expression 47 | } // namespace style 48 | } // namespace mbgl 49 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/coercion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class Coercion : public Expression { 14 | public: 15 | Coercion(type::Type type_, std::vector> inputs_); 16 | 17 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 18 | 19 | EvaluationResult evaluate(const EvaluationContext& params) const override; 20 | void eachChild(const std::function& visit) const override; 21 | 22 | mbgl::Value serialize() const override; 23 | 24 | bool operator==(const Expression& e) const override; 25 | 26 | std::vector> possibleOutputs() const override; 27 | 28 | std::string getOperator() const override; 29 | private: 30 | EvaluationResult (*coerceSingleValue) (const Value& v); 31 | std::vector> inputs; 32 | }; 33 | 34 | } // namespace expression 35 | } // namespace style 36 | } // namespace mbgl 37 | 38 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/collator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class Collator { 14 | public: 15 | Collator(bool caseSensitive, bool diacriticSensitive, optional locale = {}); 16 | 17 | bool operator==(const Collator& other) const; 18 | 19 | int compare(const std::string& lhs, const std::string& rhs) const; 20 | 21 | std::string resolvedLocale() const; 22 | private: 23 | class Impl; 24 | std::shared_ptr impl; 25 | }; 26 | 27 | } // namespace expression 28 | } // namespace style 29 | } // namespace mbgl 30 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/collator_expression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class CollatorExpression : public Expression { 14 | public: 15 | CollatorExpression(std::unique_ptr caseSensitive, 16 | std::unique_ptr diacriticSensitive, 17 | optional> locale); 18 | 19 | EvaluationResult evaluate(const EvaluationContext&) const override; 20 | static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); 21 | 22 | void eachChild(const std::function&) const override; 23 | 24 | bool operator==(const Expression& e) const override; 25 | 26 | std::vector> possibleOutputs() const override { 27 | // Technically the set of possible outputs is the combinatoric set of Collators produced 28 | // by all possibleOutputs of locale/caseSensitive/diacriticSensitive 29 | // But for the primary use of Collators in comparison operators, we ignore the Collator's 30 | // possibleOutputs anyway, so we can get away with leaving this undefined for now. 31 | return { nullopt }; 32 | } 33 | 34 | mbgl::Value serialize() const override; 35 | std::string getOperator() const override { return "collator"; } 36 | private: 37 | std::unique_ptr caseSensitive; 38 | std::unique_ptr diacriticSensitive; 39 | optional> locale; 40 | }; 41 | 42 | } // namespace expression 43 | } // namespace style 44 | } // namespace mbgl 45 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | 11 | class Error : public Expression { 12 | public: 13 | Error(std::string message_) 14 | : Expression(Kind::Error, type::Error), 15 | message(std::move(message_)) {} 16 | 17 | void eachChild(const std::function&) const override {} 18 | 19 | bool operator==(const Expression& e) const override { 20 | return e.getKind() == Kind::Error; 21 | } 22 | 23 | EvaluationResult evaluate(const EvaluationContext&) const override { 24 | return EvaluationError{message}; 25 | } 26 | 27 | std::vector> possibleOutputs() const override { 28 | return {}; 29 | } 30 | 31 | std::string getOperator() const override { return "error"; } 32 | 33 | private: 34 | std::string message; 35 | }; 36 | 37 | } // namespace expression 38 | } // namespace style 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/find_zoom_curve.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | optional> findZoomCurve(const expression::Expression* e); 15 | 16 | variant findZoomCurveChecked(const expression::Expression* e); 17 | 18 | } // namespace expression 19 | } // namespace style 20 | } // namespace mbgl 21 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/format_expression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | struct FormatExpressionSection { 15 | FormatExpressionSection(std::unique_ptr text_, 16 | optional> fontScale_, 17 | optional> textFont_); 18 | 19 | std::shared_ptr text; 20 | optional> fontScale; 21 | optional> textFont; 22 | }; 23 | 24 | class FormatExpression : public Expression { 25 | public: 26 | FormatExpression(std::vector sections); 27 | 28 | EvaluationResult evaluate(const EvaluationContext&) const override; 29 | static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); 30 | 31 | void eachChild(const std::function&) const override; 32 | 33 | bool operator==(const Expression& e) const override; 34 | 35 | std::vector> possibleOutputs() const override { 36 | // Technically the combinatoric set of all children 37 | // Usually, this.text will be undefined anyway 38 | return { nullopt }; 39 | } 40 | 41 | mbgl::Value serialize() const override; 42 | std::string getOperator() const override { return "format"; } 43 | private: 44 | std::vector sections; 45 | std::unique_ptr text; 46 | optional> fontScale; 47 | optional> textFont; 48 | }; 49 | 50 | } // namespace expression 51 | } // namespace style 52 | } // namespace mbgl 53 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/formatted.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace mbgl { 12 | namespace style { 13 | namespace expression { 14 | 15 | struct FormattedSection { 16 | FormattedSection(std::string text_, optional fontScale_, optional fontStack_) 17 | : text(std::move(text_)) 18 | , fontScale(std::move(fontScale_)) 19 | , fontStack(std::move(fontStack_)) 20 | {} 21 | std::string text; 22 | optional fontScale; 23 | optional fontStack; 24 | }; 25 | 26 | class Formatted { 27 | public: 28 | Formatted() = default; 29 | 30 | Formatted(const char* plainU8String) { 31 | sections.emplace_back(std::string(plainU8String), nullopt, nullopt); 32 | } 33 | 34 | Formatted(std::vector sections_) 35 | : sections(std::move(sections_)) 36 | {} 37 | 38 | bool operator==(const Formatted& ) const; 39 | 40 | std::string toString() const; 41 | 42 | bool empty() const { 43 | return sections.empty() || sections.at(0).text.empty(); 44 | } 45 | 46 | std::vector sections; 47 | }; 48 | 49 | } // namespace expression 50 | 51 | namespace conversion { 52 | 53 | template <> 54 | struct Converter { 55 | public: 56 | optional operator()(const Convertible& value, Error& error) const; 57 | }; 58 | 59 | } // namespace conversion 60 | 61 | } // namespace style 62 | } // namespace mbgl 63 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/get_covering_stops.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | namespace style { 10 | namespace expression { 11 | 12 | // Return the smallest range of stops that covers the interval [lower, upper] 13 | Range getCoveringStops(const std::map>& stops, 14 | const double lower, const double upper); 15 | 16 | } // namespace expression 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/interpolator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | 11 | class ExponentialInterpolator { 12 | public: 13 | ExponentialInterpolator(double base_) : base(base_) {} 14 | 15 | double base; 16 | 17 | double interpolationFactor(const Range& inputLevels, const double input) const { 18 | return util::interpolationFactor(base, 19 | Range { 20 | static_cast(inputLevels.min), 21 | static_cast(inputLevels.max) 22 | }, 23 | input); 24 | } 25 | 26 | bool operator==(const ExponentialInterpolator& rhs) const { 27 | return base == rhs.base; 28 | } 29 | }; 30 | 31 | class CubicBezierInterpolator { 32 | public: 33 | CubicBezierInterpolator(double x1_, double y1_, double x2_, double y2_) : ub(x1_, y1_, x2_, y2_) {} 34 | 35 | double interpolationFactor(const Range& inputLevels, const double input) const { 36 | return ub.solve(util::interpolationFactor(1.0, 37 | Range { 38 | static_cast(inputLevels.min), 39 | static_cast(inputLevels.max) 40 | }, 41 | input), 42 | 1e-6); 43 | } 44 | 45 | bool operator==(const CubicBezierInterpolator& rhs) const { 46 | return ub == rhs.ub; 47 | } 48 | 49 | util::UnitBezier ub; 50 | }; 51 | 52 | using Interpolator = variant; 53 | 54 | } // namespace expression 55 | } // namespace style 56 | } // namespace mbgl 57 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/is_constant.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | namespace expression { 9 | 10 | template 11 | bool isGlobalPropertyConstant(const Expression& expression, const T& properties) { 12 | if (expression.getKind() == Kind::CompoundExpression) { 13 | auto e = static_cast(&expression); 14 | for (const std::string& property : properties) { 15 | if (e->getOperator() == property) { 16 | return false; 17 | } 18 | } 19 | } 20 | 21 | bool isConstant = true; 22 | expression.eachChild([&](const Expression& e) { 23 | if (isConstant && !isGlobalPropertyConstant(e, properties)) { 24 | isConstant = false; 25 | } 26 | }); 27 | return isConstant; 28 | }; 29 | 30 | bool isFeatureConstant(const Expression& expression); 31 | bool isZoomConstant(const Expression& e); 32 | 33 | 34 | } // namespace expression 35 | } // namespace style 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/is_expression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace style { 7 | namespace expression { 8 | 9 | bool isExpression(const conversion::Convertible& value); 10 | 11 | } // namespace expression 12 | } // namespace style 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/length.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Length : public Expression { 15 | public: 16 | Length(std::unique_ptr input); 17 | 18 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 19 | 20 | EvaluationResult evaluate(const EvaluationContext& params) const override; 21 | void eachChild(const std::function& visit) const override; 22 | bool operator==(const Expression& e) const override; 23 | std::vector> possibleOutputs() const override; 24 | std::string getOperator() const override { return "length"; } 25 | 26 | private: 27 | std::unique_ptr input; 28 | }; 29 | 30 | } // namespace expression 31 | } // namespace style 32 | } // namespace mbgl 33 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/literal.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class Literal : public Expression { 14 | public: 15 | Literal(Value value_) 16 | : Expression(Kind::Literal, typeOf(value_)) 17 | , value(value_) 18 | {} 19 | 20 | Literal(type::Array type_, std::vector value_) 21 | : Expression(Kind::Literal, type_) 22 | , value(value_) 23 | {} 24 | 25 | EvaluationResult evaluate(const EvaluationContext&) const override { 26 | return value; 27 | } 28 | 29 | static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); 30 | 31 | void eachChild(const std::function&) const override {} 32 | 33 | bool operator==(const Expression& e) const override { 34 | if (e.getKind() == Kind::Literal) { 35 | auto rhs = static_cast(&e); 36 | return value == rhs->value; 37 | } 38 | return false; 39 | } 40 | 41 | std::vector> possibleOutputs() const override { 42 | return {{ value }}; 43 | } 44 | 45 | Value getValue() const { 46 | return value; 47 | } 48 | 49 | mbgl::Value serialize() const override; 50 | std::string getOperator() const override { return "literal"; } 51 | 52 | private: 53 | Value value; 54 | }; 55 | 56 | } // namespace expression 57 | } // namespace style 58 | } // namespace mbgl 59 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/match.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | template 14 | class Match : public Expression { 15 | public: 16 | using Branches = std::unordered_map>; 17 | 18 | Match(type::Type type_, 19 | std::unique_ptr input_, 20 | Branches branches_, 21 | std::unique_ptr otherwise_ 22 | ) : Expression(Kind::Match, type_), 23 | input(std::move(input_)), 24 | branches(std::move(branches_)), 25 | otherwise(std::move(otherwise_)) 26 | {} 27 | 28 | EvaluationResult evaluate(const EvaluationContext& params) const override; 29 | 30 | void eachChild(const std::function& visit) const override; 31 | 32 | bool operator==(const Expression& e) const override; 33 | 34 | std::vector> possibleOutputs() const override; 35 | 36 | mbgl::Value serialize() const override; 37 | std::string getOperator() const override { return "match"; } 38 | private: 39 | std::unique_ptr input; 40 | Branches branches; 41 | std::unique_ptr otherwise; 42 | }; 43 | 44 | ParseResult parseMatch(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 45 | 46 | } // namespace expression 47 | } // namespace style 48 | } // namespace mbgl 49 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/step.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | namespace style { 14 | namespace expression { 15 | 16 | class Step : public Expression { 17 | public: 18 | Step(const type::Type& type_, 19 | std::unique_ptr input_, 20 | std::map> stops_); 21 | 22 | EvaluationResult evaluate(const EvaluationContext& params) const override; 23 | void eachChild(const std::function& visit) const override; 24 | void eachStop(const std::function& visit) const; 25 | 26 | const std::unique_ptr& getInput() const { return input; } 27 | Range getCoveringStops(const double lower, const double upper) const; 28 | 29 | bool operator==(const Expression& e) const override; 30 | 31 | std::vector> possibleOutputs() const override; 32 | 33 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 34 | 35 | mbgl::Value serialize() const override; 36 | std::string getOperator() const override { return "step"; } 37 | 38 | private: 39 | const std::unique_ptr input; 40 | const std::map> stops; 41 | }; 42 | 43 | } // namespace expression 44 | } // namespace style 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/filter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | namespace style { 14 | 15 | class Filter { 16 | public: 17 | optional> expression; 18 | private: 19 | optional legacyFilter; 20 | public: 21 | Filter() : expression() {} 22 | 23 | Filter(expression::ParseResult _expression, optional _filter = {}) 24 | : expression(std::move(*_expression)), 25 | legacyFilter(std::move(_filter)){ 26 | assert(!expression || *expression != nullptr); 27 | } 28 | 29 | bool operator()(const expression::EvaluationContext& context) const; 30 | 31 | friend bool operator==(const Filter& lhs, const Filter& rhs) { 32 | if (!lhs.expression || !rhs.expression) { 33 | return lhs.expression == rhs.expression; 34 | } else { 35 | return *(lhs.expression) == *(rhs.expression); 36 | } 37 | } 38 | 39 | friend bool operator!=(const Filter& lhs, const Filter& rhs) { 40 | return !(lhs == rhs); 41 | } 42 | 43 | mbgl::Value serialize() const { 44 | if (legacyFilter) { 45 | return *legacyFilter; 46 | } 47 | else if (expression) { 48 | return (**expression).serialize(); 49 | } 50 | return NullValue(); 51 | } 52 | }; 53 | 54 | } // namespace style 55 | } // namespace mbgl 56 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/image.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mbgl { 9 | namespace style { 10 | 11 | class Image { 12 | public: 13 | Image(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false); 14 | Image(const Image&); 15 | 16 | std::string getID() const; 17 | 18 | const PremultipliedImage& getImage() const; 19 | 20 | // Pixel ratio of the sprite image. 21 | float getPixelRatio() const; 22 | 23 | // Whether this image should be interpreted as a signed distance field icon. 24 | bool isSdf() const; 25 | 26 | class Impl; 27 | Immutable baseImpl; 28 | }; 29 | 30 | } // namespace style 31 | } // namespace mbgl 32 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/layers/background_layer.hpp: -------------------------------------------------------------------------------- 1 | // This file is generated. Do not edit. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace mbgl { 12 | namespace style { 13 | 14 | class TransitionOptions; 15 | 16 | class BackgroundLayer : public Layer { 17 | public: 18 | BackgroundLayer(const std::string& layerID); 19 | ~BackgroundLayer() final; 20 | 21 | // Dynamic properties 22 | optional setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; 23 | optional setPaintProperty(const std::string& name, const conversion::Convertible& value) final; 24 | 25 | // Paint properties 26 | 27 | static PropertyValue getDefaultBackgroundColor(); 28 | PropertyValue getBackgroundColor() const; 29 | void setBackgroundColor(PropertyValue); 30 | void setBackgroundColorTransition(const TransitionOptions&); 31 | TransitionOptions getBackgroundColorTransition() const; 32 | 33 | static PropertyValue getDefaultBackgroundPattern(); 34 | PropertyValue getBackgroundPattern() const; 35 | void setBackgroundPattern(PropertyValue); 36 | void setBackgroundPatternTransition(const TransitionOptions&); 37 | TransitionOptions getBackgroundPatternTransition() const; 38 | 39 | static PropertyValue getDefaultBackgroundOpacity(); 40 | PropertyValue getBackgroundOpacity() const; 41 | void setBackgroundOpacity(PropertyValue); 42 | void setBackgroundOpacityTransition(const TransitionOptions&); 43 | TransitionOptions getBackgroundOpacityTransition() const; 44 | 45 | // Private implementation 46 | 47 | class Impl; 48 | const Impl& impl() const; 49 | 50 | Mutable mutableImpl() const; 51 | BackgroundLayer(Immutable); 52 | std::unique_ptr cloneRef(const std::string& id) const final; 53 | 54 | protected: 55 | Mutable mutableBaseImpl() const final; 56 | }; 57 | 58 | } // namespace style 59 | } // namespace mbgl 60 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/light.hpp: -------------------------------------------------------------------------------- 1 | // This file is generated. Do not edit. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | 13 | class LightObserver; 14 | 15 | class Light { 16 | public: 17 | Light(); 18 | ~Light(); 19 | 20 | static LightAnchorType getDefaultAnchor(); 21 | PropertyValue getAnchor() const; 22 | void setAnchor(PropertyValue); 23 | void setAnchorTransition(const TransitionOptions&); 24 | TransitionOptions getAnchorTransition() const; 25 | 26 | static Position getDefaultPosition(); 27 | PropertyValue getPosition() const; 28 | void setPosition(PropertyValue); 29 | void setPositionTransition(const TransitionOptions&); 30 | TransitionOptions getPositionTransition() const; 31 | 32 | static Color getDefaultColor(); 33 | PropertyValue getColor() const; 34 | void setColor(PropertyValue); 35 | void setColorTransition(const TransitionOptions&); 36 | TransitionOptions getColorTransition() const; 37 | 38 | static float getDefaultIntensity(); 39 | PropertyValue getIntensity() const; 40 | void setIntensity(PropertyValue); 41 | void setIntensityTransition(const TransitionOptions&); 42 | TransitionOptions getIntensityTransition() const; 43 | 44 | class Impl; 45 | Immutable impl; 46 | Mutable mutableImpl() const; 47 | 48 | LightObserver* observer = nullptr; 49 | void setObserver(LightObserver*); 50 | }; 51 | 52 | } // namespace style 53 | } // namespace mbgl 54 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/light.hpp.ejs: -------------------------------------------------------------------------------- 1 | <% 2 | const properties = locals.properties; 3 | -%> 4 | // This file is generated. Do not edit. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace mbgl { 14 | namespace style { 15 | 16 | class LightObserver; 17 | 18 | class Light { 19 | public: 20 | Light(); 21 | ~Light(); 22 | 23 | <% for (const property of properties) { -%> 24 | static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>(); 25 | <%- propertyValueType(property) %> get<%- camelize(property.name) %>() const; 26 | void set<%- camelize(property.name) %>(<%- propertyValueType(property) %>); 27 | void set<%- camelize(property.name) %>Transition(const TransitionOptions&); 28 | TransitionOptions get<%- camelize(property.name) %>Transition() const; 29 | 30 | <% } -%> 31 | class Impl; 32 | Immutable impl; 33 | Mutable mutableImpl() const; 34 | 35 | LightObserver* observer = nullptr; 36 | void setObserver(LightObserver*); 37 | }; 38 | 39 | } // namespace style 40 | } // namespace mbgl 41 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/position.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | class Position { 10 | public: 11 | Position() = default; 12 | Position(std::array& position_) 13 | : radial(position_[0]), azimuthal(position_[1]), polar(position_[2]) { 14 | calculateCartesian(); 15 | }; 16 | 17 | friend bool operator==(const Position& lhs, const Position& rhs) { 18 | return lhs.radial == rhs.radial && lhs.azimuthal == rhs.azimuthal && lhs.polar == rhs.polar; 19 | // TODO this doesn't address wrapping, which would be better addressed by comparing cartesian coordinates but being calculated floats are ont to be trusted. 20 | } 21 | 22 | friend bool operator!=(const Position& lhs, const Position& rhs) { 23 | return !(lhs == rhs); 24 | } 25 | 26 | const std::array getCartesian() const { 27 | return { { x, y, z } }; 28 | }; 29 | 30 | const std::array getSpherical() const { 31 | return { { radial, azimuthal, polar } }; 32 | }; 33 | 34 | void set(std::array& position_) { 35 | radial = position_[0]; 36 | azimuthal = position_[1]; 37 | polar = position_[2]; 38 | calculateCartesian(); 39 | }; 40 | 41 | // Utility function to be used only during interpolation; this leaves spherical coordinates undefined. 42 | void setCartesian(std::array& position_) { 43 | x = position_[0]; 44 | y = position_[1]; 45 | z = position_[2]; 46 | } 47 | 48 | private: 49 | float radial; 50 | float azimuthal; 51 | float polar; 52 | float x; 53 | float y; 54 | float z; 55 | 56 | void calculateCartesian() { 57 | // We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2): we 58 | // correct for that here 59 | const float _a = (azimuthal + 90) * util::DEG2RAD; 60 | const float _p = polar * util::DEG2RAD; 61 | 62 | x = radial * std::cos(_a) * std::sin(_p); 63 | y = radial * std::sin(_a) * std::sin(_p); 64 | z = radial * std::cos(_p); 65 | }; 66 | }; 67 | } // namespace style 68 | } // namespace mbgl 69 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/custom_geometry_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class OverscaledTileID; 12 | class CanonicalTileID; 13 | template 14 | class Actor; 15 | 16 | namespace style { 17 | 18 | using TileFunction = std::function; 19 | 20 | class CustomTileLoader; 21 | 22 | class CustomGeometrySource : public Source { 23 | public: 24 | struct TileOptions { 25 | double tolerance = 0.375; 26 | uint16_t tileSize = util::tileSize; 27 | uint16_t buffer = 128; 28 | bool clip = false; 29 | bool wrap = false; 30 | }; 31 | 32 | struct Options { 33 | TileFunction fetchTileFunction; 34 | TileFunction cancelTileFunction; 35 | Range zoomRange = { 0, 18}; 36 | TileOptions tileOptions; 37 | }; 38 | public: 39 | CustomGeometrySource(std::string id, CustomGeometrySource::Options options); 40 | ~CustomGeometrySource() final; 41 | void loadDescription(FileSource&) final; 42 | void setTileData(const CanonicalTileID&, const GeoJSON&); 43 | void invalidateTile(const CanonicalTileID&); 44 | void invalidateRegion(const LatLngBounds&); 45 | // Private implementation 46 | class Impl; 47 | const Impl& impl() const; 48 | private: 49 | std::unique_ptr> loader; 50 | }; 51 | 52 | template <> 53 | inline bool Source::is() const { 54 | return getType() == SourceType::CustomVector; 55 | } 56 | 57 | } // namespace style 58 | } // namespace mbgl 59 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/geojson_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class AsyncRequest; 11 | 12 | namespace style { 13 | 14 | struct GeoJSONOptions { 15 | // GeoJSON-VT options 16 | uint8_t minzoom = 0; 17 | uint8_t maxzoom = 18; 18 | uint16_t tileSize = util::tileSize; 19 | uint16_t buffer = 128; 20 | double tolerance = 0.375; 21 | bool lineMetrics = false; 22 | 23 | // Supercluster options 24 | bool cluster = false; 25 | uint16_t clusterRadius = 50; 26 | uint8_t clusterMaxZoom = 17; 27 | }; 28 | 29 | class GeoJSONSource : public Source { 30 | public: 31 | GeoJSONSource(const std::string& id, const GeoJSONOptions& = {}); 32 | ~GeoJSONSource() final; 33 | 34 | void setURL(const std::string& url); 35 | void setGeoJSON(const GeoJSON&); 36 | 37 | optional getURL() const; 38 | 39 | class Impl; 40 | const Impl& impl() const; 41 | 42 | void loadDescription(FileSource&) final; 43 | 44 | private: 45 | optional url; 46 | std::unique_ptr req; 47 | }; 48 | 49 | template <> 50 | inline bool Source::is() const { 51 | return getType() == SourceType::GeoJSON; 52 | } 53 | 54 | } // namespace style 55 | } // namespace mbgl 56 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/image_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | class LatLng; 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class ImageSource : public Source { 14 | public: 15 | ImageSource(std::string id, const std::array); 16 | ~ImageSource() override; 17 | 18 | optional getURL() const; 19 | void setURL(const std::string& url); 20 | 21 | void setImage(PremultipliedImage&&); 22 | 23 | void setCoordinates(const std::array&); 24 | std::array getCoordinates() const; 25 | 26 | class Impl; 27 | const Impl& impl() const; 28 | 29 | void loadDescription(FileSource&) final; 30 | private: 31 | optional url; 32 | std::unique_ptr req; 33 | }; 34 | 35 | template <> 36 | inline bool Source::is() const { 37 | return getType() == SourceType::Image; 38 | } 39 | 40 | } // namespace style 41 | } // namespace mbgl 42 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/raster_dem_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class RasterDEMSource : public RasterSource { 14 | public: 15 | RasterDEMSource(std::string id, variant urlOrTileset, uint16_t tileSize); 16 | 17 | }; 18 | 19 | template <> 20 | inline bool Source::is() const { 21 | return getType() == SourceType::RasterDEM; 22 | } 23 | 24 | } // namespace style 25 | } // namespace mbgl 26 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/raster_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class RasterSource : public Source { 14 | public: 15 | RasterSource(std::string id, variant urlOrTileset, uint16_t tileSize, SourceType sourceType = SourceType::Raster); 16 | ~RasterSource() override; 17 | 18 | const variant& getURLOrTileset() const; 19 | optional getURL() const; 20 | 21 | uint16_t getTileSize() const; 22 | 23 | class Impl; 24 | const Impl& impl() const; 25 | 26 | void loadDescription(FileSource&) final; 27 | 28 | private: 29 | const variant urlOrTileset; 30 | std::unique_ptr req; 31 | }; 32 | 33 | template <> 34 | inline bool Source::is() const { 35 | return getType() == SourceType::Raster; 36 | } 37 | 38 | } // namespace style 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/vector_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class VectorSource : public Source { 14 | public: 15 | VectorSource(std::string id, variant urlOrTileset); 16 | ~VectorSource() final; 17 | 18 | const variant& getURLOrTileset() const; 19 | optional getURL() const; 20 | 21 | class Impl; 22 | const Impl& impl() const; 23 | 24 | void loadDescription(FileSource&) final; 25 | 26 | private: 27 | const variant urlOrTileset; 28 | std::unique_ptr req; 29 | }; 30 | 31 | template <> 32 | inline bool Source::is() const { 33 | return getType() == SourceType::Vector; 34 | } 35 | 36 | } // namespace style 37 | } // namespace mbgl 38 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/style.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace mbgl { 12 | 13 | class FileSource; 14 | class Scheduler; 15 | 16 | namespace style { 17 | 18 | class Light; 19 | class Image; 20 | class Source; 21 | class Layer; 22 | 23 | class Style { 24 | public: 25 | Style(Scheduler&, FileSource&, float pixelRatio); 26 | ~Style(); 27 | 28 | void loadJSON(const std::string&); 29 | void loadURL(const std::string&); 30 | 31 | std::string getJSON() const; 32 | std::string getURL() const; 33 | 34 | // Defaults 35 | std::string getName() const; 36 | CameraOptions getDefaultCamera() const; 37 | 38 | // TransitionOptions 39 | TransitionOptions getTransitionOptions() const; 40 | void setTransitionOptions(const TransitionOptions&); 41 | 42 | // Light 43 | Light* getLight(); 44 | const Light* getLight() const; 45 | 46 | void setLight(std::unique_ptr); 47 | 48 | // Images 49 | const Image* getImage(const std::string&) const; 50 | void addImage(std::unique_ptr); 51 | void removeImage(const std::string&); 52 | 53 | // Sources 54 | std::vector< Source*> getSources(); 55 | std::vector getSources() const; 56 | 57 | Source* getSource(const std::string&); 58 | const Source* getSource(const std::string&) const; 59 | 60 | void addSource(std::unique_ptr); 61 | std::unique_ptr removeSource(const std::string& sourceID); 62 | 63 | // Layers 64 | std::vector< Layer*> getLayers(); 65 | std::vector getLayers() const; 66 | 67 | Layer* getLayer(const std::string&); 68 | const Layer* getLayer(const std::string&) const; 69 | 70 | void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); 71 | std::unique_ptr removeLayer(const std::string& layerID); 72 | 73 | // Private implementation 74 | class Impl; 75 | const std::unique_ptr impl; 76 | }; 77 | 78 | } // namespace style 79 | } // namespace mbgl 80 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/transition_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | 9 | class TransitionOptions { 10 | public: 11 | optional duration; 12 | optional delay; 13 | bool enablePlacementTransitions; 14 | 15 | TransitionOptions(optional duration_ = {}, 16 | optional delay_ = {}, 17 | bool enablePlacementTransitions_ = true) 18 | : duration(std::move(duration_)), 19 | delay(std::move(delay_)), 20 | enablePlacementTransitions(enablePlacementTransitions_) {} 21 | 22 | TransitionOptions reverseMerge(const TransitionOptions& defaults) const { 23 | return { 24 | duration ? duration : defaults.duration, 25 | delay ? delay : defaults.delay, 26 | enablePlacementTransitions 27 | }; 28 | } 29 | 30 | bool isDefined() const { 31 | return duration || delay; 32 | } 33 | }; 34 | 35 | } // namespace style 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/undefined.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { 4 | namespace style { 5 | 6 | class Undefined {}; 7 | 8 | inline bool operator==(const Undefined&, const Undefined&) { return true; } 9 | inline bool operator!=(const Undefined&, const Undefined&) { return false; } 10 | 11 | } // namespace style 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/tile/tile_necessity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { 4 | 5 | // Tiles can have two states: optional or required. 6 | // - optional means that only low-cost actions should be taken to obtain the data 7 | // (e.g. load from cache, but accept stale data) 8 | // - required means that every effort should be taken to obtain the data (e.g. load 9 | // from internet and keep the data fresh if it expires) 10 | enum class TileNecessity : bool { 11 | Optional = false, 12 | Required = true, 13 | }; 14 | 15 | } // namespace mbgl 16 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/async_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class AsyncRequest : private util::noncopyable { 8 | public: 9 | virtual ~AsyncRequest() = default; 10 | }; 11 | 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/async_task.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | namespace util { 10 | 11 | class AsyncTask : private util::noncopyable { 12 | public: 13 | AsyncTask(std::function&&); 14 | ~AsyncTask(); 15 | 16 | void send(); 17 | 18 | private: 19 | class Impl; 20 | std::unique_ptr impl; 21 | }; 22 | 23 | } // namespace util 24 | } // namespace mbgl 25 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/char_array_buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | // ref https://artofcode.wordpress.com/2010/12/12/deriving-from-stdstreambuf/ 9 | 10 | class CharArrayBuffer : public std::streambuf 11 | { 12 | public: 13 | CharArrayBuffer(char const* data, std::size_t size) 14 | : begin_(data), end_(data + size), current_(data) {} 15 | 16 | private: 17 | int_type underflow() final { 18 | if (current_ == end_) { 19 | return traits_type::eof(); 20 | } 21 | return traits_type::to_int_type(*current_); 22 | } 23 | 24 | int_type uflow() final { 25 | if (current_ == end_) { 26 | return traits_type::eof(); 27 | } 28 | return traits_type::to_int_type(*current_++); 29 | } 30 | 31 | int_type pbackfail(int_type ch) final { 32 | if (current_ == begin_ || (ch != traits_type::eof() && ch != current_[-1])) { 33 | return traits_type::eof(); 34 | } 35 | return traits_type::to_int_type(*--current_); 36 | } 37 | 38 | std::streamsize showmanyc() final { 39 | return end_ - current_; 40 | } 41 | 42 | pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode) final { 43 | if (dir == std::ios_base::beg) current_ = std::min(begin_ + off, end_); 44 | else if (dir == std::ios_base::cur) current_ = std::min(current_ + off, end_); 45 | else current_ = std::max(end_ - off, begin_); // dir == std::ios_base::end 46 | return pos_type(off_type(current_ - begin_)); 47 | } 48 | 49 | char const * const begin_; 50 | char const * const end_; 51 | char const * current_; 52 | }; 53 | 54 | } // namespace util 55 | } // namespace mbgl 56 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/chrono.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | using Clock = std::chrono::steady_clock; 9 | 10 | using Seconds = std::chrono::seconds; 11 | using Milliseconds = std::chrono::milliseconds; 12 | 13 | using TimePoint = Clock::time_point; 14 | using Duration = Clock::duration; 15 | 16 | // Used to measure second-precision times, such as times gathered from HTTP responses. 17 | using Timestamp = std::chrono::time_point; 18 | 19 | namespace util { 20 | 21 | inline Timestamp now() { 22 | return std::chrono::time_point_cast(std::chrono::system_clock::now()); 23 | } 24 | 25 | // Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT" 26 | std::string rfc1123(Timestamp); 27 | 28 | // YYYY-mm-dd HH:MM:SS e.g. "2015-11-26 16:11:23" 29 | std::string iso8601(Timestamp); 30 | 31 | Timestamp parseTimestamp(const char *); 32 | 33 | Timestamp parseTimestamp(const int32_t timestamp); 34 | 35 | // C++17 polyfill 36 | template ::min() < std::chrono::duration::zero()>> 38 | constexpr std::chrono::duration abs(std::chrono::duration d) 39 | { 40 | return d >= d.zero() ? d : -d; 41 | } 42 | 43 | } // namespace util 44 | 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | // Stores a premultiplied color, with all four channels ranging from 0..1 12 | class Color { 13 | public: 14 | Color() = default; 15 | Color(float r_, float g_, float b_, float a_) 16 | : r(r_), g(g_), b(b_), a(a_) { 17 | assert(r_ >= 0.0f); 18 | assert(r_ <= 1.0f); 19 | assert(g_ >= 0.0f); 20 | assert(g_ <= 1.0f); 21 | assert(b_ >= 0.0f); 22 | assert(b_ <= 1.0f); 23 | assert(a_ >= 0.0f); 24 | assert(a_ <= 1.0f); 25 | } 26 | 27 | float r = 0.0f; 28 | float g = 0.0f; 29 | float b = 0.0f; 30 | float a = 0.0f; 31 | 32 | static Color black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; }; 33 | static Color white() { return { 1.0f, 1.0f, 1.0f, 1.0f }; }; 34 | 35 | static Color red() { return { 1.0f, 0.0f, 0.0f, 1.0f }; }; 36 | static Color green() { return { 0.0f, 1.0f, 0.0f, 1.0f }; }; 37 | static Color blue() { return { 0.0f, 0.0f, 1.0f, 1.0f }; }; 38 | 39 | static optional parse(const std::string&); 40 | std::string stringify() const; 41 | std::array toArray() const; 42 | }; 43 | 44 | inline bool operator==(const Color& colorA, const Color& colorB) { 45 | return colorA.r == colorB.r && colorA.g == colorB.g && colorA.b == colorB.b && colorA.a == colorB.a; 46 | } 47 | 48 | inline bool operator!=(const Color& colorA, const Color& colorB) { 49 | return !(colorA == colorB); 50 | } 51 | 52 | inline Color operator*(const Color& color, float alpha) { 53 | assert(alpha >= 0.0f); 54 | assert(alpha <= 1.0f); 55 | return { 56 | color.r * alpha, 57 | color.g * alpha, 58 | color.b * alpha, 59 | color.a * alpha 60 | }; 61 | } 62 | 63 | } // namespace mbgl 64 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/compression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | std::string compress(const std::string& raw); 9 | std::string decompress(const std::string& raw); 10 | 11 | } // namespace util 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/convert.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace util { 9 | 10 | template::value>> 12 | MBGL_CONSTEXPR std::array convert(const std::array&from) { 13 | std::array to {{}}; 14 | std::copy(std::begin(from), std::end(from), std::begin(to)); 15 | return to; 16 | } 17 | 18 | } // namespace util 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/enum.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | template 12 | class Enum { 13 | public: 14 | using Type = T; 15 | static const char * toString(T); 16 | static optional toEnum(const std::string&); 17 | }; 18 | 19 | #define MBGL_DEFINE_ENUM(T, values...) \ 20 | \ 21 | static const constexpr std::pair T##_names[] = values; \ 22 | \ 23 | template <> \ 24 | const char * Enum::toString(T t) { \ 25 | auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ 26 | [&] (const auto& v) { return t == v.first; }); \ 27 | assert(it != std::end(T##_names)); return it->second; \ 28 | } \ 29 | \ 30 | template <> \ 31 | optional Enum::toEnum(const std::string& s) { \ 32 | auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ 33 | [&] (const auto& v) { return s == v.second; }); \ 34 | return it == std::end(T##_names) ? optional() : it->first; \ 35 | } 36 | 37 | } // namespace mbgl 38 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/event.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | enum class EventSeverity : uint8_t { 8 | Debug, 9 | Info, 10 | Warning, 11 | Error, 12 | }; 13 | 14 | enum class Event : uint8_t { 15 | General, 16 | Setup, 17 | Shader, 18 | ParseStyle, 19 | ParseTile, 20 | Render, 21 | Style, 22 | Database, 23 | HttpRequest, 24 | Sprite, 25 | Image, 26 | OpenGL, 27 | JNI, 28 | Android, 29 | Crash, 30 | Glyph, 31 | Timing 32 | }; 33 | 34 | struct EventPermutation { 35 | const EventSeverity severity; 36 | const Event event; 37 | 38 | constexpr bool operator==(const EventPermutation &rhs) const { 39 | return severity == rhs.severity && event == rhs.event; 40 | } 41 | }; 42 | 43 | constexpr EventSeverity disabledEventSeverities[] = { 44 | #ifndef NDEBUG 45 | EventSeverity(-1) // Avoid zero size array 46 | #else 47 | EventSeverity::Debug 48 | #endif 49 | }; 50 | 51 | constexpr Event disabledEvents[] = { 52 | Event(-1) // Avoid zero size array 53 | }; 54 | 55 | constexpr EventPermutation disabledEventPermutations[] = { 56 | { EventSeverity::Debug, Event::Shader } 57 | }; 58 | 59 | } // namespace mbgl 60 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/exception.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | struct Exception : std::runtime_error { 9 | Exception(const char *msg) : std::runtime_error(msg) {} 10 | Exception(const std::string &msg) : std::runtime_error(msg) {} 11 | }; 12 | 13 | struct SpriteImageException : Exception { 14 | SpriteImageException(const char *msg) : Exception(msg) {} 15 | SpriteImageException(const std::string &msg) : Exception(msg) {} 16 | }; 17 | 18 | struct MisuseException : Exception { 19 | MisuseException(const char *msg) : Exception(msg) {} 20 | MisuseException(const std::string &msg) : Exception(msg) {} 21 | }; 22 | 23 | struct StyleParseException : Exception { 24 | StyleParseException(const char *msg) : Exception(msg) {} 25 | StyleParseException(const std::string &msg) : Exception(msg) {} 26 | }; 27 | 28 | struct StyleLoadException : Exception { 29 | StyleLoadException(const char *msg) : Exception(msg) {} 30 | StyleLoadException(const std::string &msg) : Exception(msg) {} 31 | }; 32 | 33 | struct NotFoundException : Exception { 34 | NotFoundException(const char *msg) : Exception(msg) {} 35 | NotFoundException(const std::string &msg) : Exception(msg) {} 36 | }; 37 | 38 | } // namespace util 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/expected.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | using expected = nonstd::expected; 9 | 10 | template 11 | using unexpected = nonstd::unexpected_type; 12 | 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/feature.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | using Value = mapbox::feature::value; 10 | using NullValue = mapbox::feature::null_value_t; 11 | using PropertyMap = mapbox::feature::property_map; 12 | using FeatureIdentifier = mapbox::feature::identifier; 13 | using Feature = mapbox::feature::feature; 14 | 15 | template 16 | optional numericValue(const Value& value) { 17 | return value.match( 18 | [] (uint64_t t) { 19 | return optional(t); 20 | }, 21 | [] (int64_t t) { 22 | return optional(t); 23 | }, 24 | [] (double t) { 25 | return optional(t); 26 | }, 27 | [] (auto) { 28 | return optional(); 29 | }); 30 | } 31 | 32 | } // namespace mbgl 33 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/font_stack.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | 12 | // An array of font names 13 | using FontStack = std::vector; 14 | using FontStackHash = std::size_t; 15 | 16 | std::string fontStackToString(const FontStack&); 17 | 18 | struct FontStackHasher { 19 | FontStackHash operator()(const FontStack&) const; 20 | }; 21 | 22 | // Statically evaluate layer properties to determine what font stacks are used. 23 | std::set fontStacks(const std::vector>&); 24 | 25 | } // namespace mbgl 26 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/geojson.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | using GeoJSON = mapbox::geojson::geojson; 9 | using FeatureCollection = mapbox::geojson::feature_collection; 10 | using FeatureExtensionValue = mapbox::util::variant; 11 | 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/ignore.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | // Accept any number of parameters of any types, and do nothing with them. 9 | // Useful for providing a context for parameter pack expansion where a legal 10 | // expansion context is not otherwise available. 11 | // 12 | // See https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md 13 | // for more details. 14 | // 15 | template void ignore(Ts&&...) {} 16 | 17 | // std::initializer_list overload, for situations where you need sequenced 18 | // modifications. 19 | // 20 | template void ignore(const std::initializer_list&) {} 21 | 22 | // Handle the zero-argument case. 23 | inline void ignore(const std::initializer_list&) {} 24 | 25 | } // namespace util 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/noncopyable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { namespace util { 4 | 5 | namespace non_copyable_ 6 | { 7 | 8 | class noncopyable 9 | { 10 | public: 11 | noncopyable( noncopyable const& ) = delete; 12 | noncopyable& operator=(noncopyable const& ) = delete; 13 | 14 | protected: 15 | constexpr noncopyable() = default; 16 | ~noncopyable() = default; 17 | }; 18 | } // namespace non_copyable_ 19 | 20 | using noncopyable = non_copyable_::noncopyable; 21 | 22 | } // namespace util 23 | } // namespace mbgl 24 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/optional.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | using optional = std::experimental::optional; 9 | 10 | using nullopt_t = std::experimental::nullopt_t; 11 | constexpr nullopt_t nullopt = std::experimental::nullopt; 12 | 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/platform.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace platform { 8 | 9 | class Request; 10 | 11 | // Uppercase a string, potentially using platform-specific routines. 12 | std::string uppercase(const std::string &string); 13 | 14 | // Lowercase a string, potentially using platform-specific routines. 15 | std::string lowercase(const std::string &string); 16 | 17 | // Gets the name of the current thread. 18 | std::string getCurrentThreadName(); 19 | 20 | // Set the name of the current thread, truncated at 15. 21 | void setCurrentThreadName(const std::string& name); 22 | 23 | // Makes the current thread low priority. 24 | void makeThreadLowPriority(); 25 | 26 | // Shows an alpha image with the specified dimensions in a named window. 27 | void showDebugImage(std::string name, const char *data, size_t width, size_t height); 28 | 29 | // Shows an alpha image with the specified dimensions in a named window. 30 | void showColorDebugImage(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height); 31 | } // namespace platform 32 | } // namespace mbgl 33 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/premultiply.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | PremultipliedImage premultiply(UnassociatedImage&&); 9 | UnassociatedImage unpremultiply(PremultipliedImage&&); 10 | 11 | } // namespace util 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/range.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #pragma once 4 | 5 | namespace mbgl { 6 | 7 | template 8 | class Range { 9 | public: 10 | constexpr Range(T min_, T max_) 11 | : min(std::move(min_)), max(std::move(max_)) {} 12 | 13 | T min; 14 | T max; 15 | }; 16 | 17 | template 18 | bool operator==(const Range& a, const Range& b) { 19 | return a.min == b.min && a.max == b.max; 20 | } 21 | 22 | template 23 | bool operator!=(const Range& a, const Range& b) { 24 | return !(a == b); 25 | } 26 | 27 | } // namespace mbgl 28 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/size.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | class Size { 9 | public: 10 | constexpr Size() = default; 11 | 12 | constexpr Size(const uint32_t width_, const uint32_t height_) : width(width_), height(height_) { 13 | } 14 | 15 | constexpr uint32_t area() const { 16 | return width * height; 17 | } 18 | 19 | constexpr float aspectRatio() const { 20 | return static_cast(width) / static_cast(height); 21 | } 22 | 23 | constexpr bool isEmpty() const { 24 | return width == 0 || height == 0; 25 | } 26 | 27 | uint32_t width = 0; 28 | uint32_t height = 0; 29 | }; 30 | 31 | constexpr inline bool operator==(const Size& a, const Size& b) { 32 | return a.width == b.width && a.height == b.height; 33 | } 34 | 35 | constexpr inline bool operator!=(const Size& a, const Size& b) { 36 | return !(a == b); 37 | } 38 | 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/tileset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | class Tileset { 15 | public: 16 | enum class Scheme : bool { XYZ, TMS }; 17 | enum class DEMEncoding : bool { Mapbox, Terrarium }; 18 | 19 | std::vector tiles; 20 | Range zoomRange; 21 | std::string attribution; 22 | Scheme scheme; 23 | // DEMEncoding is not supported by the TileJSON spec 24 | DEMEncoding encoding; 25 | optional bounds; 26 | 27 | 28 | Tileset(std::vector tiles_ = std::vector(), 29 | Range zoomRange_ = { 0, util::DEFAULT_MAX_ZOOM }, 30 | std::string attribution_ = {}, 31 | Scheme scheme_ = Scheme::XYZ, 32 | DEMEncoding encoding_ = DEMEncoding::Mapbox) 33 | : tiles(std::move(tiles_)), 34 | zoomRange(std::move(zoomRange_)), 35 | attribution(std::move(attribution_)), 36 | scheme(scheme_), 37 | encoding(encoding_), 38 | bounds() {}; 39 | 40 | // TileJSON also includes center and zoom but they are not used by mbgl. 41 | 42 | friend bool operator==(const Tileset& lhs, const Tileset& rhs) { 43 | return std::tie(lhs.tiles, lhs.zoomRange, lhs.attribution, lhs.scheme, lhs.bounds) 44 | == std::tie(rhs.tiles, rhs.zoomRange, rhs.attribution, rhs.scheme, rhs.bounds); 45 | } 46 | 47 | friend bool operator!=(const Tileset& lhs, const Tileset& rhs) { 48 | return !(lhs == rhs); 49 | } 50 | }; 51 | 52 | } // namespace mbgl 53 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace util { 11 | 12 | class Timer : private util::noncopyable { 13 | public: 14 | Timer(); 15 | ~Timer(); 16 | 17 | void start(Duration timeout, Duration repeat, std::function&&); 18 | void stop(); 19 | 20 | private: 21 | class Impl; 22 | std::unique_ptr impl; 23 | }; 24 | 25 | } // namespace util 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/traits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | template 9 | constexpr auto underlying_type(T t) -> typename std::underlying_type_t { 10 | return typename std::underlying_type_t(t); 11 | } 12 | 13 | template struct is_utf16char_like: std::false_type {}; 14 | template struct is_utf16char_like: is_utf16char_like {}; 15 | template <> struct is_utf16char_like: std::true_type {}; 16 | template <> struct is_utf16char_like: std::true_type {}; 17 | template <> struct is_utf16char_like: std::true_type {}; 18 | 19 | template using is_utf16char_like_pointer = std::integral_constant::value 20 | && is_utf16char_like::type>::value>; 21 | 22 | template 23 | typename std::enable_if::value && is_utf16char_like_pointer::value, OutPointer>::type utf16char_cast(InChar *in) 24 | { 25 | return reinterpret_cast(in); 26 | } 27 | 28 | } // namespace mbgl 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/type_list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | template 9 | struct TypeList { 10 | template