- Pretty-indenting code
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
7aecc910ba
commit
6b27a8461b
94 changed files with 3073 additions and 3066 deletions
|
@ -29,22 +29,21 @@ using namespace sgpem;
|
|||
|
||||
template<typename T>
|
||||
PolicyParameters::Parameter<T>::Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value)
|
||||
:_name(name), _value(value), _lower_bound(lower_bound), _upper_bound(upper_bound), _is_required(required), _default(default_value)
|
||||
{
|
||||
}
|
||||
: _name(name), _value(value), _lower_bound(lower_bound), _upper_bound(upper_bound), _is_required(required), _default(default_value)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
Glib::ustring
|
||||
PolicyParameters::Parameter<T>::get_name() const
|
||||
{
|
||||
return _name;
|
||||
return _name;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_lower_bound() const
|
||||
{
|
||||
return _lower_bound;
|
||||
return _lower_bound;
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,39 +51,39 @@ template<typename T>
|
|||
T
|
||||
PolicyParameters::Parameter<T>::get_upper_bound() const
|
||||
{
|
||||
return _upper_bound;
|
||||
return _upper_bound;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool
|
||||
PolicyParameters::Parameter<T>::is_required() const
|
||||
{
|
||||
return _is_required;
|
||||
return _is_required;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_default() const
|
||||
{
|
||||
return _default;
|
||||
return _default;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
PolicyParameters::Parameter<T>::get_value() const
|
||||
{
|
||||
return _value;
|
||||
return _value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
PolicyParameters::Parameter<T>::set_value(const T& val)
|
||||
{
|
||||
_value = val;
|
||||
_value = val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,21 +22,21 @@
|
|||
#include <glibmm/thread.h>
|
||||
#include "config.h"
|
||||
|
||||
namespace sgpem
|
||||
namespace sgpem
|
||||
{
|
||||
|
||||
/** \brief An abstract implementation of the Singleton design pattern.
|
||||
|
||||
/** \brief An abstract implementation of the Singleton design pattern.
|
||||
*
|
||||
* Singleton implementers constuctor will have to declare friendliness
|
||||
* to Singleton::get_instance(). This also attempts to achieve
|
||||
* thread-safeness.
|
||||
*/
|
||||
template<typename Instantiated_class>
|
||||
class SG_DLLEXPORT Singleton
|
||||
class SG_DLLEXPORT Singleton
|
||||
{
|
||||
public:
|
||||
|
||||
/** \brief Ensures thread safety is respected, and returns the instantiated object
|
||||
|
||||
/** \brief Ensures thread safety is respected, and returns the instantiated object
|
||||
*
|
||||
* This is done by locking _instance via a mutex, before intantiating the
|
||||
* Instantiated_class attribute (if not done before).
|
||||
|
@ -48,7 +48,8 @@ namespace sgpem
|
|||
private:
|
||||
static Instantiated_class* _instance;
|
||||
static Glib::StaticMutex SG_DLLLOCAL _mutex;
|
||||
}; //~ class Singleton
|
||||
}
|
||||
; //~ class Singleton
|
||||
|
||||
} //~ namespace sgpem
|
||||
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
#include <new>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace memory {
|
||||
|
||||
namespace memory
|
||||
{
|
||||
|
||||
/** \brief A simple reference counted smart pointer
|
||||
*
|
||||
* \author Matteo Settenvini
|
||||
|
@ -36,21 +37,22 @@ namespace memory {
|
|||
*
|
||||
* \param T The type of the object to store
|
||||
* \param isArray a boolean value telling if we're
|
||||
* storing an array or a single object (the default)
|
||||
* storing an array or a single object (the default)
|
||||
*
|
||||
* \warning This class hasn't virtual methods
|
||||
* to ensure greater speed. Don't inherit
|
||||
* from it: its destructor isn't virtual, either.
|
||||
*/
|
||||
template<typename T, bool isArray = false>
|
||||
class smart_ptr {
|
||||
|
||||
class smart_ptr
|
||||
{
|
||||
|
||||
template<typename T2, bool isArray2>
|
||||
friend class smart_ptr;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** \brief An alias for the smart_ptr which contains null
|
||||
/** \brief An alias for the smart_ptr which contains null
|
||||
*
|
||||
* When you've to compare some smart pointer with another
|
||||
* to see if it points to nowhere, you can use this
|
||||
|
@ -75,7 +77,7 @@ namespace memory {
|
|||
* So you don't keep a potentially dangerous reference
|
||||
* around. */
|
||||
smart_ptr(T* ptr = 0) throw(std::bad_alloc);
|
||||
|
||||
|
||||
/** \brief Copy constructor.
|
||||
*
|
||||
* Always use this to obtain another reference
|
||||
|
@ -93,8 +95,8 @@ namespace memory {
|
|||
* Use this operator to access object
|
||||
* methods and data. */
|
||||
T* operator->() throw();
|
||||
|
||||
/** \brief Access to stored object's members
|
||||
|
||||
/** \brief Access to stored object's members
|
||||
*
|
||||
* Const version of the above operator. */
|
||||
const T* operator->() const throw();
|
||||
|
@ -108,7 +110,7 @@ namespace memory {
|
|||
*
|
||||
* \warning Use with care */
|
||||
const T& operator*() const throw();
|
||||
|
||||
|
||||
/** \brief Convenience operator for use in predicates
|
||||
*
|
||||
* \return true if the stored pointer is valid,
|
||||
|
@ -121,7 +123,7 @@ namespace memory {
|
|||
* \return The number of references */
|
||||
unsigned int alive_refs() const throw();
|
||||
|
||||
/** \brief Dynamic cast the stored pointer
|
||||
/** \brief Dynamic cast the stored pointer
|
||||
* to another type, returning a smart_ptr
|
||||
*
|
||||
* This functions tries to cast the stored
|
||||
|
@ -133,9 +135,9 @@ namespace memory {
|
|||
* the cast isn't successful or doable
|
||||
*/
|
||||
template<typename U>
|
||||
smart_ptr<U,isArray> cast_to() throw(std::bad_cast);
|
||||
smart_ptr<U, isArray> cast_to() throw(std::bad_cast);
|
||||
|
||||
/** \brief Dynamic cast the stored pointer
|
||||
/** \brief Dynamic cast the stored pointer
|
||||
* to another type, returning a smart_ptr
|
||||
*
|
||||
* This functions tries to cast the stored
|
||||
|
@ -147,16 +149,18 @@ namespace memory {
|
|||
* the cast isn't successful or doable
|
||||
*/
|
||||
template<typename U>
|
||||
const smart_ptr<U,isArray> cast_to() const throw(std::bad_cast);
|
||||
|
||||
const smart_ptr<U, isArray> cast_to() const throw(std::bad_cast);
|
||||
|
||||
private:
|
||||
template<typename U>
|
||||
smart_ptr(const smart_ptr<U,isArray>& sptr) throw(std::bad_cast);
|
||||
smart_ptr(const smart_ptr<U, isArray>& sptr) throw(std::bad_cast);
|
||||
|
||||
struct contents_type {
|
||||
struct contents_type
|
||||
{
|
||||
T* ptr;
|
||||
unsigned int rc;
|
||||
}* _contents;
|
||||
}
|
||||
* _contents;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,16 +19,17 @@
|
|||
|
||||
#include "smartp.hh"
|
||||
|
||||
namespace memory {
|
||||
namespace memory
|
||||
{
|
||||
|
||||
template<typename T, bool isArray>
|
||||
const smart_ptr<T, isArray> smart_ptr<T, isArray>::null = 0;
|
||||
|
||||
|
||||
// ------------------------------
|
||||
|
||||
template<typename T, bool isArray>
|
||||
smart_ptr<T, isArray>::smart_ptr( T* ptr ) throw(std::bad_alloc)
|
||||
: _contents(new contents_type())
|
||||
: _contents(new contents_type())
|
||||
{
|
||||
_contents->rc = 1;
|
||||
_contents->ptr = ptr;
|
||||
|
@ -37,7 +38,7 @@ namespace memory {
|
|||
|
||||
template<typename T, bool isArray>
|
||||
smart_ptr<T, isArray>::smart_ptr(const smart_ptr& sptr) throw()
|
||||
: _contents(sptr._contents)
|
||||
: _contents(sptr._contents)
|
||||
{
|
||||
(_contents->rc)++;
|
||||
}
|
||||
|
@ -46,40 +47,40 @@ namespace memory {
|
|||
template<typename T, bool isArray>
|
||||
smart_ptr<T, isArray>::~smart_ptr() throw()
|
||||
{
|
||||
if(--(_contents->rc) == 0)
|
||||
if(--(_contents->rc) == 0)
|
||||
{
|
||||
if(_contents->ptr != 0)
|
||||
!isArray ? delete _contents->ptr : delete [] _contents->ptr;
|
||||
!isArray ? delete _contents->ptr : delete [] _contents->ptr;
|
||||
delete _contents;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------
|
||||
|
||||
template<typename T, bool isArray>
|
||||
smart_ptr<T, isArray>&
|
||||
smart_ptr<T, isArray>::operator=(const smart_ptr& sptr) throw()
|
||||
{
|
||||
if(this != &sptr && _contents != sptr._contents)
|
||||
if(this != &sptr && _contents != sptr._contents)
|
||||
{
|
||||
if(--(_contents->rc) == 0)
|
||||
if(--(_contents->rc) == 0)
|
||||
{
|
||||
if(_contents->ptr != 0)
|
||||
!isArray ? delete _contents->ptr : delete [] _contents->ptr;
|
||||
delete _contents;
|
||||
if(_contents->ptr != 0)
|
||||
!isArray ? delete _contents->ptr : delete [] _contents->ptr;
|
||||
delete _contents;
|
||||
}
|
||||
|
||||
|
||||
_contents = sptr._contents;
|
||||
(_contents->rc)++;
|
||||
}
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, bool isArray>
|
||||
bool
|
||||
smart_ptr<T, isArray>::operator==( const smart_ptr& sptr ) const throw()
|
||||
smart_ptr<T, isArray>::operator==( const smart_ptr& sptr ) const throw()
|
||||
{
|
||||
return _contents->ptr == sptr._contents->ptr;
|
||||
}
|
||||
|
@ -91,8 +92,8 @@ namespace memory {
|
|||
{
|
||||
return _contents->ptr != sptr._contents->ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T, bool isArray>
|
||||
T&
|
||||
smart_ptr<T, isArray>::operator*() throw()
|
||||
|
@ -132,7 +133,7 @@ namespace memory {
|
|||
}
|
||||
|
||||
// ------------------------------
|
||||
|
||||
|
||||
template<typename T, bool isArray>
|
||||
unsigned int
|
||||
smart_ptr<T, isArray>::alive_refs() const throw()
|
||||
|
@ -144,7 +145,7 @@ namespace memory {
|
|||
template<typename T, bool isArray>
|
||||
template<typename U>
|
||||
smart_ptr<U, isArray>
|
||||
smart_ptr<T, isArray>::cast_to() throw(std::bad_cast)
|
||||
smart_ptr<T, isArray>::cast_to() throw(std::bad_cast)
|
||||
{
|
||||
return smart_ptr<U, isArray>(*this);
|
||||
}
|
||||
|
@ -161,14 +162,14 @@ namespace memory {
|
|||
|
||||
template<typename T, bool isArray>
|
||||
template<typename U>
|
||||
smart_ptr<T,isArray>::smart_ptr(const smart_ptr<U,isArray>& sptr)
|
||||
throw(std::bad_cast)
|
||||
smart_ptr<T, isArray>::smart_ptr(const smart_ptr<U, isArray>& sptr)
|
||||
throw(std::bad_cast)
|
||||
{
|
||||
if(!sptr._contents->ptr || dynamic_cast<T*>(sptr._contents->ptr) == 0)
|
||||
throw std::bad_cast();
|
||||
|
||||
|
||||
// I know, I know... this is Evil(TM):
|
||||
_contents = reinterpret_cast<typename smart_ptr<T,isArray>::contents_type*>(sptr._contents);
|
||||
_contents = reinterpret_cast<typename smart_ptr<T, isArray>::contents_type*>(sptr._contents);
|
||||
(_contents->rc)++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue