Skip to content
Snippets Groups Projects
Commit ac1519c9 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6655: removed more unused files

parent e6fba892
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 577 deletions
/*
* Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (cURLpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CREATION_STATIC_HPP
#define CREATION_STATIC_HPP
/**
* This class is a creation policy for the utilspp::singleton_holder. The
* policy is creating the singleton by a static memory. The constructor is
* called the first time we call the utilspp::creation_static::create()
* function.
*
* Note don't use this class because it's not complete, and at this time it's
* not REALY complyant with the lifetime policy.
*/
namespace utilspp
{
template< typename T >
class CreationStatic
{
public:
static T* create();
static void destroy( T* obj );
};
};
#include "CreationStatic.inl"
#endif
/*
* Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (cURLpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CREATION_STATIC_INL
#define CREATION_STATIC_INL
template< typename T >
T*
utilspp::CreationStatic::create()
{
static T mObj;
return new(&mObj) T;
};
template< typename T >
void
utilspp::CreationStatic::destroy( T* obj )
{
obj->~T();
}
#endif
\ No newline at end of file
#include "SingletonHolder.hpp"
#include "LifetimeLibrary.hpp"
utilspp::LifetimeLibraryImpl::LifetimeLibraryImpl()
:
mTrackerArray (NULL),
mNbElements (0) {}
utilspp::LifetimeLibraryImpl::~LifetimeLibraryImpl() {
terminate();
}
void
utilspp::LifetimeLibraryImpl::add (utilspp::PrivateMembers::LifetimeTracker *tracker) {
utilspp::PrivateMembers::TrackerArray newArray = static_cast<
utilspp::PrivateMembers::TrackerArray > (std::realloc (mTrackerArray,
mNbElements + 1));
if (newArray == NULL) {
throw std::bad_alloc();
}
mTrackerArray = newArray;
utilspp::PrivateMembers::TrackerArray pos =
std::upper_bound (mTrackerArray,
mTrackerArray + mNbElements,
tracker,
&utilspp::PrivateMembers::LifetimeTracker::compare);
std::copy_backward (pos,
mTrackerArray + mNbElements,
mTrackerArray + mNbElements + 1);
*pos = tracker;
mNbElements++;
};
void
utilspp::LifetimeLibraryImpl::terminate() {
//The number of elements MUST always be equal or over zero.
assert (mNbElements >= 0);
while (mNbElements > 0) {
//At this point the mTrackerArray MUST not be NULL.
assert (mTrackerArray != NULL);
//Pick the element at the top of the stack.
utilspp::PrivateMembers::LifetimeTracker* top =
mTrackerArray[mNbElements - 1];
//Remove that object off the stack.
//Don't check errors-realloc with less memory, cause that can't fail.
mTrackerArray =
static_cast< utilspp::PrivateMembers::TrackerArray >
(std::realloc (mTrackerArray, --mNbElements));
//Destroy the element.
delete top;
}
}
unsigned int
utilspp::getLongevity (utilspp::LifetimeLibraryImpl *) {
return 0;
}
/*
* Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (cURLpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LIFETIME_LIBRARY_HPP
#define LIFETIME_LIBRARY_HPP
#include <cassert>
#include <algorithm>
#include "PrivateMembers.hpp"
#include "CreationUsingNew.hpp"
namespace utilspp
{
template< typename T >
unsigned int getLongevity( T *p );
/**
* Assigns an object a longevity. Ensures ordered destructions of objects
* registered thusly during the exit sequence of the application.
*/
template< typename T, typename TDestroyer >
void setLibraryLongevity(
T *obj,
unsigned int longevity,
TDestroyer d = utilspp::PrivateMembers::Deleter< T >::deleteObject
);
/**
* This class is a lifetime policy for the singleton. This
* class allow you to terminate the singleton explicitly.
* You can terminate by calling:
*
* LifetimeLibrarySingleton::instance().terminate()
*
* This singleton use the utilspp::LifetimeWithLongevity policy.
*/
template< typename T >
struct LifetimeLibrary
{
static void scheduleDestruction( T *obj, void (*func)() );
static void onDeadReference();
};
class LifetimeLibraryImpl
{
public:
LifetimeLibraryImpl();
~LifetimeLibraryImpl();
void add( utilspp::PrivateMembers::LifetimeTracker *tracker );
void terminate();
private:
utilspp::PrivateMembers::TrackerArray mTrackerArray;
int mNbElements;
};
unsigned int getLongevity( utilspp::LifetimeLibraryImpl *p );
typedef utilspp::SingletonHolder<
utilspp::LifetimeLibraryImpl,
utilspp::CreationUsingNew,
utilspp::LifetimeWithLongevity
> LifetimeLibrarySingleton;
/**
* This class will ensure that
*
* LifetimeLibraryImpl::terminate()
*
* is called.
*/
template< typename T = utilspp::LifetimeLibrarySingleton >
class LifetimeLibraryGuard
{
public:
~LifetimeLibraryGuard();
};
};
#include "LifetimeLibrary.inl"
#endif
template< typename T, typename TDestroyer >
void
utilspp::setLibraryLongevity( T *obj, unsigned int longevity, TDestroyer d )
{
using namespace utilspp::PrivateMembers;
LifetimeTracker *p = new ConcreteLifetimeTracker< T, TDestroyer >(
obj, longevity, d);
utilspp::LifetimeLibrarySingleton::instance().add( p );
};
template< typename T >
void
utilspp::LifetimeLibrary< T >::scheduleDestruction( T *obj, void (*func)() )
{
utilspp::PrivateMembers::adapter<T> adapter = { func };
utilspp::setLibraryLongevity( obj, getLongevity( obj ), adapter );
}
template< typename T >
void
utilspp::LifetimeLibrary< T >::onDeadReference()
{
throw std::logic_error("Dead reference detected");
}
template< typename T >
utilspp::LifetimeLibraryGuard< T >::~LifetimeLibraryGuard()
{
T::instance().terminate();
}
/*
* Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (cURLpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef LIFETIME_WITH_LONGEVITY_HPP
#define LIFETIME_WITH_LONGEVITY_HPP
#include <cassert>
#include "PrivateMembers.hpp"
#include <algorithm>
namespace utilspp
{
template< typename T >
unsigned int getLongevity( T *p );
/**
* Assigns an object a longevity. Ensures ordered destructions of objects
* registered thusly during the exit sequence of the application.
*/
template< typename T, typename TDestroyer >
void setLongevity(T *obj,
unsigned int longevity,
TDestroyer d = utilspp::PrivateMembers::Deleter< T >::deleteObject);
template< typename T >
struct LifetimeWithLongevity
{
static void scheduleDestruction( T *obj, void (*func)() );
static void onDeadReference();
};
}
#include "LifetimeWithLongevity.inl"
#endif
template< typename T, typename TDestroyer >
void
utilspp::setLongevity( T *obj, unsigned int longevity, TDestroyer d )
{
using namespace utilspp::PrivateMembers;
TrackerArray newArray = static_cast< TrackerArray >(
std::realloc(mTrackerArray, mNbElements + 1));
if( newArray == NULL )
{
throw std::bad_alloc();
}
LifetimeTracker *p =
new ConcreteLifetimeTracker< T, TDestroyer >(obj, longevity, d);
mTrackerArray = newArray;
TrackerArray pos = std::upper_bound(
mTrackerArray,
mTrackerArray + mNbElements,
p,
&LifetimeTracker::compare);
std::copy_backward(
pos,
mTrackerArray + mNbElements,
mTrackerArray + mNbElements + 1);
*pos = p;
mNbElements++;
std::atexit( &atExitFunc );
}
template< typename T >
void
utilspp::LifetimeWithLongevity< T >::scheduleDestruction( T *obj, void (*func)() )
{
utilspp::PrivateMembers::adapter<T> adapter = { func };
utilspp::setLongevity( obj, getLongevity( obj ), adapter );
}
template< typename T >
void
utilspp::LifetimeWithLongevity< T >::onDeadReference()
{
throw std::logic_error("Dead reference detected");
}
template< typename T >
unsigned int
utilspp::getLongevity( T * )
{
return 1000;
}
noinst_LTLIBRARIES = libsingleton.la
libsingleton_la_SOURCES = \
CreationStatic.hpp CreationStatic.inl \
CreationUsingNew.hpp CreationUsingNew.inl \
LifetimeDefault.hpp LifetimeDefault.inl \
LifetimeLibrary.cpp LifetimeLibrary.hpp LifetimeLibrary.inl \
LifetimeWithLongevity.hpp LifetimeWithLongevity.inl \
PrivateMembers.cpp PrivateMembers.hpp PrivateMembers.inl \
SingletonHolder.hpp SingletonHolder.inl
......
#include <cstdlib>
#include "PrivateMembers.hpp"
utilspp::PrivateMembers::TrackerArray
utilspp::PrivateMembers::mTrackerArray = NULL;
int utilspp::PrivateMembers::mNbElements = 0;
utilspp::PrivateMembers::LifetimeTracker::LifetimeTracker (unsigned int
longevity)
:
mLongevity (longevity) {}
utilspp::PrivateMembers::LifetimeTracker::~LifetimeTracker() {}
bool
utilspp::PrivateMembers::LifetimeTracker::compare (
const LifetimeTracker *l,
const LifetimeTracker *r
) {
return l->mLongevity < r->mLongevity;
}
void
utilspp::PrivateMembers::atExitFunc() {
assert ( (mTrackerArray != NULL) &&
(mNbElements > 0));
//Pick the element at the top of the stack.
LifetimeTracker* top = mTrackerArray[mNbElements - 1];
//Remove that object off the stack.
//Don't check errors-realloc with less memory, cause that can't fail.
mTrackerArray = static_cast<
utilspp::PrivateMembers::TrackerArray > (std::realloc (mTrackerArray,
--mNbElements));
//Destroy the element.
delete top;
}
/*
* Copyright (c) <2002-2004> <Jean-Philippe Barrette-LaPierre>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (cURLpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef PRIVATE_MEMBERS_HPP
#define PRIVATE_MEMBERS_HPP
#include <cassert>
namespace utilspp
{
namespace PrivateMembers
{
/**
* Helper class for utils::setLongevity
*/
class LifetimeTracker
{
public:
LifetimeTracker( unsigned int longevity );
virtual ~LifetimeTracker();
static bool compare(
const LifetimeTracker *l,
const LifetimeTracker *r
);
private:
unsigned int mLongevity;
};
typedef LifetimeTracker** TrackerArray;
extern TrackerArray mTrackerArray;
extern int mNbElements;
/**
* Helper class for Destroyer
*/
template< typename T >
struct Deleter
{
void deleteObject( T *obj );
};
/**
* Concrete lifetime tracker for objects of type T
*/
template< typename T, typename TDestroyer >
class ConcreteLifetimeTracker : public LifetimeTracker
{
public:
ConcreteLifetimeTracker(T *obj, unsigned int longevity, TDestroyer d);
~ConcreteLifetimeTracker();
private:
T* mTracked;
TDestroyer mDestroyer;
};
void atExitFunc();
template <class T>
struct adapter
{
void operator()(T*);
void (*mFunc)();
};
}
}
#include "PrivateMembers.inl"
#endif
template< typename T >
void
utilspp::PrivateMembers::Deleter< T >::deleteObject( T *obj )
{
delete obj;
}
template< typename T, typename TDestroyer >
utilspp::PrivateMembers::ConcreteLifetimeTracker< T, TDestroyer >::ConcreteLifetimeTracker(
T *obj, unsigned int longevity, TDestroyer d)
: LifetimeTracker( longevity )
, mTracked( obj )
, mDestroyer( d )
{}
template< typename T, typename TDestroyer >
utilspp::PrivateMembers::ConcreteLifetimeTracker< T, TDestroyer >::~ConcreteLifetimeTracker()
{
mDestroyer( mTracked );
}
template < typename T >
void
utilspp::PrivateMembers::adapter< T >::operator()(T*)
{
return (*mFunc)();
}
......@@ -28,7 +28,6 @@
#include "CreationUsingNew.hpp"
#include "LifetimeDefault.hpp"
#include "LifetimeWithLongevity.hpp"
#include "../ThreadingSingle.hpp"
namespace utilspp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment