more doxygen documentation, modules added

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@347 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-11-02 20:01:11 +00:00
parent cff0fad314
commit 76309d2b5c
4 changed files with 196 additions and 121 deletions

View file

@ -30,6 +30,12 @@
#define LOKI_C_CALLING_CONVENTION_QUALIFIER
#endif
/// \defgroup SingletonGroup Singleton
/// \defgroup CreationGroup Creation policies
/// \ingroup SingletonGroup
/// \defgroup LifetimeGroup Lifetime policies
/// \ingroup SingletonGroup
namespace Loki
{
@ -101,11 +107,11 @@ namespace Loki
} // namespace Private
////////////////////////////////////////////////////////////////////////////////
// function template SetLongevity
// Assigns an object a longevity; ensures ordered destructions of objects
// registered thusly during the exit sequence of the application
/// \ingroup LifetimeGroup
///
/// Assigns an object a longevity; ensures ordered destructions of objects
/// registered thusly during the exit sequence of the application
////////////////////////////////////////////////////////////////////////////////
template <typename T, typename Destroyer>
void SetLongevity(T* pDynObject, unsigned int longevity,
Destroyer d)
@ -146,13 +152,14 @@ namespace Loki
{
SetLongevity<T, typename Private::Deleter<T>::Type>(pDynObject, longevity, d);
}
////////////////////////////////////////////////////////////////////////////////
// class template CreateUsingNew
// Implementation of the CreationPolicy used by SingletonHolder
// Creates objects using a straight call to the new operator
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// \struct CreateUsingNew
///
/// \ingroup CreationGroup
/// Implementation of the CreationPolicy used by SingletonHolder
/// Creates objects using a straight call to the new operator
////////////////////////////////////////////////////////////////////////////////
template <class T> struct CreateUsingNew
{
static T* Create()
@ -162,13 +169,15 @@ namespace Loki
{ delete p; }
};
////////////////////////////////////////////////////////////////////////////////
// class template CreateUsingNew
// Implementation of the CreationPolicy used by SingletonHolder
// Creates objects using a call to std::malloc, followed by a call to the
// placement new operator
/// \struct CreateUsingMalloc
///
/// \ingroup CreationGroup
/// Implementation of the CreationPolicy used by SingletonHolder
/// Creates objects using a call to std::malloc, followed by a call to the
/// placement new operator
////////////////////////////////////////////////////////////////////////////////
template <class T> struct CreateUsingMalloc
{
static T* Create()
@ -185,15 +194,17 @@ namespace Loki
}
};
////////////////////////////////////////////////////////////////////////////////
// class template CreateStatic
// Implementation of the CreationPolicy used by SingletonHolder
// Creates an object in static memory
// Implementation is slightly nonportable because it uses the MaxAlign trick
// (an union of all types to ensure proper memory alignment). This trick is
// nonportable in theory but highly portable in practice.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// \struct CreateStatic
///
/// \ingroup CreationGroup
/// Implementation of the CreationPolicy used by SingletonHolder
/// Creates an object in static memory
/// Implementation is slightly nonportable because it uses the MaxAlign trick
/// (an union of all types to ensure proper memory alignment). This trick is
/// nonportable in theory but highly portable in practice.
////////////////////////////////////////////////////////////////////////////////
template <class T> struct CreateStatic
{
@ -232,14 +243,15 @@ namespace Loki
p->~T();
}
};
////////////////////////////////////////////////////////////////////////////////
// class template DefaultLifetime
// Implementation of the LifetimePolicy used by SingletonHolder
// Schedules an object's destruction as per C++ rules
// Forwards to std::atexit
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// \struct DefaultLifetime
///
/// \ingroup LifetimeGroup
/// Implementation of the LifetimePolicy used by SingletonHolder
/// Schedules an object's destruction as per C++ rules
/// Forwards to std::atexit
////////////////////////////////////////////////////////////////////////////////
template <class T>
struct DefaultLifetime
{
@ -251,12 +263,13 @@ namespace Loki
};
////////////////////////////////////////////////////////////////////////////////
// class template PhoenixSingleton
// Implementation of the LifetimePolicy used by SingletonHolder
// Schedules an object's destruction as per C++ rules, and it allows object
// recreation by not throwing an exception from OnDeadReference
/// \struct PhoenixSingleton
///
/// \ingroup LifetimeGroup
/// Implementation of the LifetimePolicy used by SingletonHolder
/// Schedules an object's destruction as per C++ rules, and it allows object
/// recreation by not throwing an exception from OnDeadReference
////////////////////////////////////////////////////////////////////////////////
template <class T>
class PhoenixSingleton
{
@ -287,19 +300,23 @@ namespace Loki
#endif
////////////////////////////////////////////////////////////////////////////////
// class template DeletableSingleton
// Copyright (c) 2004 by Curtis Krauskopf - curtis@decompile.com
//
// A DeletableSingleton allows the instantiated singleton to be
// destroyed at any time. The singleton can be reinstantiated at
// any time, even during program termination.
// If the singleton exists when the program terminates, it will
// be automatically deleted.
//
// The singleton can be deleted manually:
// DeletableSingleton<MyClass>::GracefulDelete();
/// Copyright (c) 2004 by Curtis Krauskopf - curtis\decompile.com
///
/// \struct DeletableSingleton
///
/// \ingroup LifetimeGroup
///
/// A DeletableSingleton allows the instantiated singleton to be
/// destroyed at any time. The singleton can be reinstantiated at
/// any time, even during program termination.
/// If the singleton exists when the program terminates, it will
/// be automatically deleted.
///
/// \par Usage:
/// The singleton can be deleted manually:
///
/// DeletableSingleton<MyClass>::GracefulDelete();
////////////////////////////////////////////////////////////////////////////////
template <class T>
class DeletableSingleton
{
@ -321,7 +338,7 @@ namespace Loki
static void OnDeadReference()
{
}
/// delete singleton object manually
static void GracefulDelete()
{
if (isDead)
@ -371,13 +388,14 @@ namespace Loki
}
////////////////////////////////////////////////////////////////////////////////
// class template SingletonWithLongevity
// Implementation of the LifetimePolicy used by SingletonHolder
// Schedules an object's destruction in order of their longevities
// Assumes a visible function GetLongevity(T*) that returns the longevity of the
// object
/// \struct SingletonWithLongevity
///
/// \ingroup LifetimeGroup
/// Implementation of the LifetimePolicy used by SingletonHolder
/// Schedules an object's destruction in order of their longevities
/// Assumes a visible function GetLongevity(T*) that returns the longevity of the
/// object.
////////////////////////////////////////////////////////////////////////////////
template <class T>
class SingletonWithLongevity
{
@ -393,11 +411,12 @@ namespace Loki
};
////////////////////////////////////////////////////////////////////////////////
// class template NoDestroy
// Implementation of the LifetimePolicy used by SingletonHolder
// Never destroys the object
/// \struct NoDestroy
///
/// \ingroup LifetimeGroup
/// Implementation of the LifetimePolicy used by SingletonHolder
/// Never destroys the object
////////////////////////////////////////////////////////////////////////////////
template <class T>
struct NoDestroy
{
@ -408,12 +427,6 @@ namespace Loki
{}
};
////////////////////////////////////////////////////////////////////////////////
// DieOrder lifetime policy:
// Policy to handle lifetime dependencies
////////////////////////////////////////////////////////////////////////////////
template <unsigned int Longevity, class T>
class SingletonFixedLongevity
{
@ -427,40 +440,50 @@ namespace Loki
static void OnDeadReference()
{ throw std::logic_error("Dead Reference Detected"); }
};
////////////////////////////////////////////////////////////////////////////////
/// \struct DieOrder
///
/// \ingroup LifetimeGroup
/// Lifetime policy to handle lifetime dependencies
////////////////////////////////////////////////////////////////////////////////
struct DieOrder
{
/// \struct Last
/// Die after the singleton with the DieOrder::First lifetime
template <class T>
struct Last : public SingletonFixedLongevity<0xFFFFFFFF ,T>
{};
/// \struct First
/// Die before the singleton with the DieOrder::Last lifetime
template <class T>
struct First : public SingletonFixedLongevity<0xFFFFFFFF-1,T>
{};
};
////////////////////////////////////////////////////////////////////////////////
// FollowIntoDeath lifetime policy: followers will die after the master dies
// Followers will not die, if
// - master never dies (NoDestroy policy)
// - master never created
// - master dies not in the function registered with atexit
// - master dies not by a call of a the atexit registerd function
// (DeletableSingleton::GreathFullDeath)
//
// Usage:
// Lifetime of the master singleton e.g. with a Master class:
// SingletonHolder<Master,
// FollowIntoDeath::With<DefaultLifetime>::AsMasterLifetime>
// MasterSingleton;
//
// Lifetime of the follower singleton e.g. with a Follower class:
// SingletonHolder<Follower,CreateUsingNew,
// FollowIntoDeath::AfterMaster<MasterSingleton>::IsDestroyed>
// FollowerSingleton
/// \struct FollowIntoDeath
///
/// \ingroup LifetimeGroup
///
/// Lifetime policyfor the SingletonHolder tempalte.
/// Followers will die after the master dies Followers will not die, if
/// - master never dies (NoDestroy policy)
/// - master never created
/// - master dies not in the function registered with atexit
/// - master dies not by a call of a the atexit registerd function (DeletableSingleton::GreathFullDeath)
///
/// \par Usage:
///
/// Lifetime of the master singleton, e.g. with a M class:
/// SingletonHolder<M,FollowIntoDeath::With<DefaultLifetime>::AsMasterLifetime> MasterSingleton;
///
/// Lifetime of the follower singleton, e.g. with a F class:
///
/// SingletonHolder<F,CreateUsingNew,FollowIntoDeath::AfterMaster<MasterSingleton>::IsDestroyed>FollowerSingleton
////////////////////////////////////////////////////////////////////////////////
struct FollowIntoDeath
class FollowIntoDeath
{
template<class T>
class Followers
@ -494,11 +517,17 @@ namespace Loki
delete followers_;
}
};
public:
/// \struct With
/// Template for the master
/// \param Lifetime Lifetime policy for the master
template<template <class> class Lifetime>
struct With
{
/// \struct AsMasterLifetime
/// Policy for master
template<class Master>
struct AsMasterLifetime
{
@ -513,7 +542,7 @@ namespace Loki
// the lifetime with the GetLongevity function.
Lifetime<Followers<Master> >::ScheduleDestruction(0,Followers<Master>::DestroyFollowers);
}
static void OnDeadReference()
{
throw std::logic_error("Dead Reference Detected");
@ -521,9 +550,14 @@ namespace Loki
};
};
/// \struct AfterMaster
/// Template for the follower
/// \param Master Master to follow into death
template<class Master>
struct AfterMaster
{
/// \struct IsDestroyed
/// Policy for followers
template<class F>
struct IsDestroyed
{
@ -531,7 +565,7 @@ namespace Loki
{
Followers<Master>::AddFollower(pFun);
}
static void OnDeadReference()
{
throw std::logic_error("Dead Reference Detected");
@ -543,15 +577,23 @@ namespace Loki
template<class T>
typename FollowIntoDeath::Followers<T>::Container*
FollowIntoDeath::Followers<T>::followers_ = 0;
////////////////////////////////////////////////////////////////////////////////
// class template SingletonHolder
// Provides Singleton amenities for a type T
// To protect that type from spurious instantiations, you have to protect it
// yourself.
/// \class SingletonHolder
///
/// \ingroup SingletonGroup
///
/// Provides Singleton amenities for a type T
/// To protect that type from spurious instantiations,
/// you have to protect it yourself.
///
/// \param CreationPolicy Creation policy, default: CreateUsingNew
/// \param LifetimePolicy Lifetime policy, default: DefaultLifetime,
/// \param ThreadingModel Threading policy,
/// default: LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL
////////////////////////////////////////////////////////////////////////////////
template
<
typename T,
@ -562,6 +604,8 @@ namespace Loki
class SingletonHolder
{
public:
/// Returns a reference to singleton object
static T& Instance();
private:

View file

@ -51,11 +51,17 @@
#undef LOKI_SMALL_OBJECT_USE_NEW_ARRAY
#endif
/// \defgroup SmallObjectGroup Small objects
///
/// \defgroup SmallObjectGroupInternal Internals
/// \ingroup SmallObjectGroup
namespace Loki
{
class FixedAllocator;
/** @class SmallObjAllocator
@ingroup SmallObjectGroupInternal
Manages pool of fixed-size allocators.
Designed to be a non-templated base class of AllocatorSingleton so that
implementation details can be safely hidden in the source code file.
@ -161,6 +167,7 @@ namespace Loki
/** @class AllocatorSingleton
@ingroup SmallObjectGroupInternal
This template class is derived from
SmallObjAllocator in order to pass template arguments into it, and still
have a default constructor for the singleton. Each instance is a unique
@ -172,7 +179,7 @@ namespace Loki
clients to use the new_handler without having the name of the new_handler
function show up in classes derived from SmallObject or SmallValueObject.
Thus, the only functions in the allocator which show up in SmallObject or
SmallValueObject inheritance heierarchies are the new and delete
SmallValueObject inheritance hierarchies are the new and delete
operators.
*/
template
@ -274,6 +281,7 @@ namespace Loki
/** @class SmallObjectBase
@ingroup SmallObjectGroupInternal
Base class for small object allocation classes.
The shared implementation of the new and delete operators are here instead
of being duplicated in both SmallObject or SmallValueObject. This class
@ -457,7 +465,8 @@ namespace Loki
}; // end class SmallObjectBase
/** @class
/** @class SmallObject
@ingroup SmallObjectGroup
SmallObject Base class for polymorphic small objects, offers fast
allocations & deallocations. Destructor is virtual and public. Default
constructor is trivial. Copy-constructor and copy-assignment operator are
@ -490,7 +499,8 @@ namespace Loki
}; // end class SmallObject
/** @class
/** @class SmallValueObject
@ingroup SmallObjectGroup
SmallValueObject Base class for small objects with value-type
semantics - offers fast allocations & deallocations. Destructor is
non-virtual, inline, and protected to prevent unintentional destruction
@ -525,6 +535,9 @@ namespace Loki
// Nov. 26, 2004: re-implemented by Rich Sposato.
//
// $Log$
// Revision 1.20 2005/11/02 20:01:10 syntheticpp
// more doxygen documentation, modules added
//
// Revision 1.19 2005/11/01 11:11:52 syntheticpp
// add lifetime policies to manage singleton lifetime dependencies: FollowIntoDeath and DieOrder. Change SmallObject.h to avoid memory leaks by default
//

View file

@ -11,6 +11,9 @@
// $Header$
/*!
@defgroup ThreadingGroup Threading
*/
#if defined(LOKI_CLASS_LEVEL_THREADING) || defined(LOKI_OBJECT_LEVEL_THREADING)
@ -39,12 +42,14 @@
namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
// class template SingleThreaded
// Implementation of the ThreadingModel policy used by various classes
// Implements a single-threaded model; no synchronization
////////////////////////////////////////////////////////////////////////////////
/*!
\class SingleThreaded
\ingroup ThreadingGroup
Implementation of the ThreadingModel policy used by various classes
Implements a single-threaded model; no synchronization
*/
template <class Host>
class SingleThreaded
{
@ -145,12 +150,14 @@ namespace Loki
#if defined(_WINDOWS_) || defined(_WINDOWS_H) || defined(_PTHREAD_H)
////////////////////////////////////////////////////////////////////////////////
// class template ObjectLevelLockable
// Implementation of the ThreadingModel policy used by various classes
// Implements a object-level locking scheme
////////////////////////////////////////////////////////////////////////////////
/*!
\class ObjectLevelLockable
\ingroup ThreadingGroup
class template ObjectLevelLockable
Implementation of the ThreadingModel policy used by various classes
Implements a object-level locking scheme
*/
template <class Host>
class ObjectLevelLockable
{
@ -214,13 +221,14 @@ namespace Loki
pthread_mutex_t ObjectLevelLockable<Host>::atomic_mutex_(PTHREAD_MUTEX_INITIALIZER);
#endif
////////////////////////////////////////////////////////////////////////////////
// class template ClassLevelLockable
// Implementation of the ThreadingModel policy used by various classes
// Implements a class-level locking scheme
////////////////////////////////////////////////////////////////////////////////
/*!
\class ClassLevelLockable
\ingroup ThreadingGroup
Implementation of the ThreadingModel policy used by various classes
Implements a class-level locking scheme
*/
template <class Host>
class ClassLevelLockable
{
@ -314,6 +322,9 @@ namespace Loki
#endif
// $Log$
// Revision 1.17 2005/11/02 20:01:10 syntheticpp
// more doxygen documentation, modules added
//
// Revision 1.16 2005/10/30 14:03:23 syntheticpp
// replace tabs space
//

View file

@ -36,6 +36,7 @@ namespace Loki
{
/** @struct Chunk
@ingroup SmallObjectGroupInternal
Contains info about each allocated Chunk - which is a collection of
contiguous blocks. Each block is the same size, as specified by the
FixedAllocator. The number of blocks in a Chunk depends upon page size.
@ -128,6 +129,7 @@ namespace Loki
};
/** @class FixedAllocator
@ingroup SmallObjectGroupInternal
Offers services for allocating fixed-sized objects. It has a container
of "containers" of fixed-size blocks. The outer container has all the
Chunks. The inner container is a Chunk which owns some blocks.
@ -697,8 +699,8 @@ void FixedAllocator::DoDeallocate(void* p)
}
// GetOffset ------------------------------------------------------------------
/// @ingroup SmallObjectGroupInternal
/// Calculates index into array where a FixedAllocator of numBytes is located.
inline std::size_t GetOffset( std::size_t numBytes, std::size_t alignment )
{
const std::size_t alignExtra = alignment-1;
@ -706,7 +708,8 @@ inline std::size_t GetOffset( std::size_t numBytes, std::size_t alignment )
}
// DefaultAllocator -----------------------------------------------------------
/** Calls the default allocator when SmallObjAllocator decides not to handle a
/** @ingroup SmallObjectGroupInternal
Calls the default allocator when SmallObjAllocator decides not to handle a
request. SmallObjAllocator calls this if the number of bytes is bigger than
the size which can be handled by any FixedAllocator.
@param doThrow True if this function should throw an exception, or false if it
@ -726,7 +729,8 @@ void * DefaultAllocator( std::size_t numBytes, bool doThrow )
}
// DefaultDeallocator ---------------------------------------------------------
/** Calls default deallocator when SmallObjAllocator decides not to handle a
/** @ingroup SmallObjectGroupInternal
Calls default deallocator when SmallObjAllocator decides not to handle a
request. The default deallocator could be the global delete operator or the
free function. The free function is the preferred default deallocator since
it matches malloc which is the preferred default allocator. SmallObjAllocator
@ -882,6 +886,9 @@ void SmallObjAllocator::Deallocate( void * p )
////////////////////////////////////////////////////////////////////////////////
// $Log$
// Revision 1.16 2005/11/02 20:01:11 syntheticpp
// more doxygen documentation, modules added
//
// Revision 1.15 2005/10/26 00:50:44 rich_sposato
// Minor changes to documentation comments.
//