Task #3349
closed
Change the ownership model of Pib and its related entities
Added by Yingdi Yu about 9 years ago.
Updated over 8 years ago.
Description
Current Pib Implementation simply creates an instance whenever returning an identity (similarly, an identity creates an instance when returning a key). As a result, multiple instances may corresponds the same identity or key. Changing the status of one instance may not affect the other instances.
A desired solution could be to create only one instance for an identity (or key) and give the shared pointer (const) to others, const reference could be another option, but it may have some problem in initialization.
Therefore, we plan to change the ownership as, each identity is maintained in the PIB's IdentityContainer, which provides shared pointer to the identity instance as handle for others. Similar for key and KeyContainer.
each identity is maintained in the PIB's IdentityContainer, which provides shared pointer to the identity instance as handle for others
It's unnecessary to expose shared_ptr
in public API.
Instead:
class Identity // copyable
{
public:
explicit operator bool() const; ///< valid (not deleted)
bool operator!() const; ///< deleted
const Name& getName() const; ///< identity name
// (other getters)
private:
weak_ptr<detail::IdentityImpl> m_impl;
};
namespace detail {
class IdentityImpl;
} // namespace detail
class IdentityContainer : noncopyable
{
public:
Identity getIdentity(..) const;
private:
std::container<shared_ptr<detail::IdentityImpl>> m_container;
};
I think you are right, weak_pointer is a better approach. actually shared_ptr does not address the issue completely. I will use weak_ptr in implementation.
- Status changed from New to Code review
- Target version set to v0.5
- Status changed from Code review to Closed
- % Done changed from 0 to 100
Also available in: Atom
PDF