Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit f56be601 authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Adding shared pointers, will move the creation of plugins to shared objects only.

parent e3ac738c
/* Define a counter class. This class should not be used by any other part of
* ALTA code.
*/
struct ptr_counter
{
ptr_counter() : _count(1) { }
inline void increment()
{
++_count;
}
inline void decrement()
{
--_count;
}
inline unsigned int value() const
{
return _count;
}
unsigned int _count;
};
/*! \brief Define a shared pointer class.
*/
template<class T> class ptr
{
public:
//! Empty constructor
ptr(T* ptr) : _ptr(ptr)
{
_counter = new ptr_counter();
}
//! Copy constructor
ptr(const ptr<T>& p) : _ptr(p._ptr), _counter(p._counter)
{
_counter->increment();
}
//! Destructor, should free memory when the counter goes
//! to zero.
~ptr()
{
_counter->decrement();
if(_counter->value() == 0)
{
delete _ptr;
delete _counter;
}
}
//! Evaluation operator. This operator should be inlined for
//! performance reasons.
inline T* operator-> ()
{
return _ptr;
}
private:
T* _ptr;
ptr_counter* _counter;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment