Smart Pointers

sync_ptr Class Template Reference

Inheritance diagram for sync_ptr:

sync_ref_ptr List of all members.

Detailed Description

template<class T, class SYNC_T = sync_ctrl_default, class AX_TYPE = std::allocator<T>, class AX_SYNC_CTRL = std::allocator<SYNC_T>>
class sync_ptr< T, SYNC_T, AX_TYPE, AX_SYNC_CTRL >

sync_ptr is a portable synchronized smart pointer.

Pointer)

Author:
David Maisonave (Axter) (609-345-1007) (http://axter.com)
Copyright (C) 2005
Date:
06-Feb-2006

Description

sync_ptr is a thread safe pointer. sync_ref_ptr is a reference counting (shared_ptr) derived version of sync_ptr sync_ptr and sync_ref_ptr can be used with Windows or UNIX/Linux via, WIN32 API's or POSIX functions. They can turn any object into a thread safe object. sync_ptr destructor will automatically destroy the object, so the object can be create via new on sync_ptr constructor. This insures no other process has ownership of the object.

Example Usage

sync_ptr<vector<int> > MyThreadSafeVectorInt(new vector<int>, new sync_ctrl_default);
MyThreadSafeVectorInt->push_back(123);
cout << MyThreadSafeVectorInt->at(0) << endl;

An instance of RefLockPtr can be create to lock the object for the duration of a function.
Example Usage
sync_ptr<string> MyThreadSafeString(new string);

string SomeFunction()
{
sync_ptr<string>::RefLockPtr MyLockedString = MyThreadSafeString.get_locked_obj();
MyLockedString->operator=("Hello World");
return MyLockedString->substr(6);
}

The destructor for RefLockPtr automatically unlocks the object, so an explicit unlock call
is not required.

License

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies. David Maisonave (Axter) makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

Definition at line 52 of file sync_ptr.hpp.

Public Member Functions

 sync_ptr (T *type, SYNC_T *sync_ctrl_=new SYNC_T)
virtual ~sync_ptr ()
RefLockPtr operator-> ()
RefLockPtr operator * ()
RefLockPtr get_locked_obj (bool *trylock_stat=NULL)

Protected Member Functions

 sync_ptr (T *type, SYNC_T *sync_ctrl_, int *RefCount_)

Protected Attributes

T * m_type
SYNC_T * m_sync_ctrl
int * m_RefCount

Classes

class  RefLockPtr
 RefLockPtr is a helper class used by sync_ptr to perform an automatic lock when operator->() is called. More...


The documentation for this class was generated from the following file:
Generated on Wed Mar 29 21:58:59 2006 for Smart Pointers by  doxygen 1.4.6.Axter [Axter-Extended-Version]