From: Thomas Geymayer Date: Wed, 4 Jun 2014 15:46:35 +0000 (+0200) Subject: cppbind::Ghost: improve compiler error message for wrong usage. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e5acc3f0482caea19e9c7873271758153d56aef8;p=simgear.git cppbind::Ghost: improve compiler error message for wrong usage. --- diff --git a/simgear/nasal/cppbind/Ghost.hxx b/simgear/nasal/cppbind/Ghost.hxx index bee615f1..25a0d875 100644 --- a/simgear/nasal/cppbind/Ghost.hxx +++ b/simgear/nasal/cppbind/Ghost.hxx @@ -201,6 +201,20 @@ namespace nasal typedef SGSharedPtr MethodHolderPtr; typedef SGWeakPtr MethodHolderWeakPtr; + // Dummy template to create shorter and easy to understand compile errors if + // trying to wrap the wrong type as a Ghost. + template + class Ghost + { + public: + BOOST_STATIC_ASSERT(("Ghost can only wrap shared pointer!" + && is_strong_ref::value + )); + + static Ghost& init(const std::string& name); + static bool isInit(); + }; + /** * Class for exposing C++ objects to Nasal * @@ -241,11 +255,11 @@ namespace nasal * @endcode */ template - class Ghost: + class Ghost >::type>: public internal::GhostMetadata { // Shared pointer required for Ghost (no weak pointer!) - BOOST_STATIC_ASSERT((shared_ptr_traits::is_strong::value)); + BOOST_STATIC_ASSERT((is_strong_ref::value)); public: typedef typename T::element_type raw_type; @@ -871,7 +885,7 @@ namespace nasal private: - template + template friend class Ghost; static naGhostType _ghost_type_strong, //!< Stored as shared pointer @@ -1283,9 +1297,14 @@ namespace nasal }; template - naGhostType Ghost::_ghost_type_strong; + naGhostType + Ghost >::type> + ::_ghost_type_strong; + template - naGhostType Ghost::_ghost_type_weak; + naGhostType + Ghost >::type> + ::_ghost_type_weak; } // namespace nasal