-
Notifications
You must be signed in to change notification settings - Fork 1.3k
private-implementation pattern #3254
Comments
Here's a second option, without an include/mbgl/map.hpp
src/mbgl/map.cpp
src/mbgl/map_impl.hpp
|
Bleah... this is going to be a drag no matter how it's implemented: c510c68. |
@jfirebaugh approaching the pimpl idiom by means of
The item is too many pages to repeat here in detail; please look it up in your local Effective Modern C++ copy or get one asap :) The tl;dr is this: you have to declare the special member functions like copy ctor and copy assign operator in the interface, and then define them appropriately in the implementation file. Default behavior is not what you want. Sidenote: for implementations that have to live in header files, the idiomatic way to to this is to have a |
@jfirebaugh I like the |
With the styles API, a lot more API surface area will be publicly exposed:
Style
Source
and future subclasses for specific source typesStyleLayer
and subclasses for specific layer typesSo far, we've been using the following technique for separating public APIs from private implementation:
include
, private headers live insrc
For the styles API, I don't think this is going to be enough. For example, I don't think we want to simply make
style_layer.hpp
a public include file -- it would cascade into making other headers public as well, and expose implementation details we want to be free to change. The currentStyleLayer
and subclasses depend on rapidjson headers (not easily forward declared) and have methods that are conceptually public to other mbgl internal classes, but private to API consumers (e.g.cascade
,recalculate
,createBucket
).Therefore we need to use more heavy-duty techniques to separate the public API from private implementation. I propose we adopt a particular implementation of the opaque pointer pattern, and follow this convention throughout portions of the codebase exposed to the public API:
mbgl
namespace. (Already doing this.)mbgl::impl
namespace.mbgl::impl
namespace andsrc/mbgl/impl
directory tree.Example:
include/mbgl/map.hpp
src/mbgl/map.cpp
src/mbgl/impl/map.hpp
In this example I've shown implementing
mbgl::Map::doSomething
insrc/mbgl/map.cpp
. Another option is to forward tombgl::impl::Map::doSomething
and put the real implementation insrc/mbgl/impl/map.cpp
. But that's another level of indirection and I don't know if there's any benefit.Thoughts?
The text was updated successfully, but these errors were encountered: