esrille / escudo

The Escudo Web Browser
Apache License 2.0
68 stars 13 forks source link

[Object] Switch over to shared_ptr based implementation #90

Closed ShikiOkasaka closed 11 years ago

ShikiOkasaka commented 11 years ago

cf. http://www.boost.org/doc/libs/1_54_0/libs/smart_ptr/sp_techniques.html#pimpl cf. http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2011-Scott-Andrei-and-Herb-Ask-Us-Anything [04:34]

The Object class could be something simple like,

class Object
{
protected:
    std::shared_ptr<Impl> pimpl;
public:
    constexpr Object() = default;
    constexpr Object(std::nullptr_t) {}
    explicit Object(Imp* pimpl) : pimpl(pimpl) {}
    Object(const std::shared_ptr<Imp>& pimpl) : pimpl(pimpl) {}
    ~Object() = default;

    std::shared_ptr<Impl> self() const {
        return pimpl;
    }

    Any message_(uint32_t selector, const char* id, int argc, Any* argv);
};

and the implementation class can be like,

class Impl : public std::enable_shared_from_this<Impl>
{
public:
    virtual Any message_(uint32_t selector, const char* id, int argc, Any* argv);
    std::shared_ptr<Impl> self() {
        return shared_from_this();
    }
};

The required changes to esidl would be relatively minor. In the escudo code base, we'll need to do surgery.

With this changes, we can create a new instance like,

 Node node(std::make_shared<NodeImpl>());

and we can also use weak_ptr where needed.

ShikiOkasaka commented 11 years ago

This switch is going to be of about 4,000 lines of changes in escudo. We will increment the minor version by one, and it will be 0.4.

ShikiOkasaka commented 11 years ago

esidl is updated at https://github.com/esrille/esidl/commit/acb6b125c330b757e53594dfad259c6954b90319.

ShikiOkasaka commented 11 years ago

Done at 0c895cbe1d325d33a5e5b6d16a1bfc6f8b480bd7.