Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memory>
- namespace std
- {
- namespace sr1
- {
- template <typename T>
- class shared_ptr_lock
- {
- protected:
- std::shared_ptr<T> data;
- public:
- shared_ptr_lock(std::shared_ptr<T> data)
- {
- this->data = data;
- }
- };
- template <typename T>
- class shared_ptr_lock_ptr : public shared_ptr_lock<T>
- {
- public:
- shared_ptr_lock_ptr(std::shared_ptr<T> data) : shared_ptr_lock(data) { }
- operator T*()
- {
- return data.get();
- }
- T& operator*()
- {
- return *data;
- }
- T* operator->()
- {
- return data.get();
- }
- };
- template <typename T>
- class shared_ptr_lock_ref : public shared_ptr_lock<T>
- {
- public:
- shared_ptr_lock_ref(std::shared_ptr<T> data) : shared_ptr_lock(data) { }
- operator T&()
- {
- return *data;
- }
- };
- template <typename T>
- class shared_ptr
- {
- public: // TODO: make_shared friend class?
- std::shared_ptr<T> data;
- public:
- void reset()
- {
- data.reset();
- }
- shared_ptr_lock_ptr<T> operator->()
- {
- return shared_ptr_lock_ptr<T>(data);
- }
- shared_ptr_lock_ptr<T> get()
- {
- return shared_ptr_lock_ptr<T>(data);
- }
- shared_ptr_lock_ref<T> operator*()
- {
- return shared_ptr_lock_ref<T>(data);
- }
- };
- template <typename T, typename A>
- shared_ptr<T> make_shared(A& a)
- {
- shared_ptr<T> rtn;
- rtn.data = std::make_shared<T>(a);
- return rtn;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement