ARMmbed / core-util

DEPRECATED: Mbed 3 utilities library
Other
12 stars 17 forks source link

Added referenced counted shared pointer class #26

Closed marcuschangarm closed 8 years ago

marcuschangarm commented 8 years ago

Class follows the shared_ptr API from C++11. Reference counts are updated when SharedPointer objects are passed around by value.

Usage:

class A;

SharedPointer<A> objectFactory()
{
    SharedPointer<A> result;

    result = SharedPointer<A>(new A(...));

    return result;
}

...

SharedPointer<A> object1;
SharedPointer<A> object2;

// assignment
object1 = objectFactory();
object2 = object1;

// invoke method in object pointed to
object1->doStuffWithObject();

// invoke method in container
object1.use_count();
marcuschangarm commented 8 years ago

@bogdanm I've added the changes you mentioned last time we spoke about this.

marcuschangarm commented 8 years ago

see https://github.com/ARMmbed/core-util/pull/30

hugovincent commented 8 years ago

Sorry if you've already discussed this but if it follows the std::shared_ptr API why not call it mbed:: shared_ptr or something?

marcuschangarm commented 8 years ago

I wanted to make it clear it is not the same thing. The constructor is different for example.

And the name resembles FunctionPointer.

hugovincent commented 8 years ago

Ah ok, similar but not the same API then.