
I have created a pimpl library that I use on a regular basis which sits on top of boost and was wondering if there was any interest in my providing it to the community. It is quite simple, but has been extremely useful personally. The library has two basic components. For starters, it uses a boost::shared_ptr to hide the implementation in the cpp file. The forwarding of the public interface is accomplished through some simple macros. The macros declare each public method, with an appropriate signature, and forward the call onto the implementation class. It would be easier to show an example of it in action: my_object.hpp class my_object : public boost::pimpl<class my_object_impl> { public: my_object() {} void do_something(); int do_other_thing( double ) const; void lots_of_args( int, int, int, int ); }; my_object.cpp class my_object_impl { public: void do_something() {...} int do_other_thing( double a1 ) const {...} void lots_of_args( int, int, int, int ) {...} private: ... }; BOOST_PIMPL_CTOR( my_object ); BOOST_PIMPL_METHOD( 0, my_object, do_something ); BOOST_PIMPL_METHOD( 1, my_object, do_other_thing, const ); BOOST_PIMPL_METHOD( 4, my_object, lots_of_args ); If this seems like it would be of any use to others, let me know. I'd be happy to share.

On 03/12/10 04:54, Michael Bailey wrote:
In case you are not aware of it, there have been a few proposals and even reviews in the past: * Review Request: pimpl http://lists.boost.org/Archives/boost/2005/10/95366.php * [review][pimpl_ptr] Pimpl Pointer review begins http://lists.boost.org/Archives/boost/2006/05/104757.php * [pimpl] Proposal. Determining interest. http://lists.boost.org/Archives/boost/2007/10/128740.php Cheers, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org Member of ACCU, http://accu.org

Michael Bailey wrote:
I would write: my_object.hpp class my_object_impl; class my_object { my_object_impl* pimpl; public: my_object() {} ~my_object(); void do_something(); int do_other_thing( double ) const; void lots_of_args( int, int, int, int ); }; my_object.cpp class my_object_impl { public: void do_something() {...} int do_other_thing( double a1 ) const {...} void lots_of_args( int, int, int, int ) {...} private: ... }; my_object::my_object(): pimpl(new my_object_impl) {} my_object::~my_object() { delete pimpl; } void my_object::do_something() { pimpl->do_something(); } int my_object::do_other_thing(double d) const { return pimpl->do_other_thing(d); } void my_object::lots_of_args(int a, int b, int c, int d) { pimpl->lots_of_args(a,b,c,d); } which really isn't much different in terms of the amount of typing, except for the forwarding. Can you show what your BOOST_PIMPL_METHOD expands to? I can't immediately guess how you manage to not tell it all the argument and return types. Re using the shared_ptr, this mainly gains the safety of otherwise forgetting to implement the dtor, and has speed and space disadvantages. I'm not convinced that is really useful, and so I would decouple it from the concise forwarding feature. Generally, I think that implementing pimpls falls more into the category of stuff that's best done with some sort of tool, e.g. a "pimpl wizzard" in your IDE, rather than a library. Regards, Phil.
participants (3)
-
Mateusz Loskot
-
Michael Bailey
-
Phil Endecott