Added text of MIT License.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1115 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
199f8bcade
commit
d2ca522cca
43 changed files with 1541 additions and 1021 deletions
|
@ -4,16 +4,26 @@
|
|||
//
|
||||
// Code covered by the MIT License
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), 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 authors make no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is" without express or implied warranty.
|
||||
// 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.
|
||||
//
|
||||
// This code DOES NOT accompany the book:
|
||||
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
|
||||
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
|
||||
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -29,8 +39,8 @@
|
|||
* It as been defined in a separate file because of the many introduced
|
||||
* dependencies (SmartPtr.h would depend on Functor.h and CachedFactory.h
|
||||
* would depend on SmartPtr.h). By defining another header you pay for those
|
||||
* extra dependencies only if you need it.
|
||||
*
|
||||
* extra dependencies only if you need it.
|
||||
*
|
||||
* This file defines FunctionStorage a new SmartPointer storage policy and
|
||||
* SmartPointer a new CachedFactory encapsulation policy.
|
||||
*/
|
||||
|
@ -45,7 +55,7 @@ namespace Loki
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \class FunctionStorage
|
||||
///
|
||||
/// \ingroup SmartPointerStorageGroup
|
||||
/// \ingroup SmartPointerStorageGroup
|
||||
/// \brief Implementation of the StoragePolicy used by SmartPtr.
|
||||
///
|
||||
/// This storage policy is used by SmartPointer CachedFactory's encapsulation
|
||||
|
@ -76,7 +86,7 @@ namespace Loki
|
|||
FunctionStorage() : pointee_(Default()), functor_()
|
||||
{}
|
||||
|
||||
// The storage policy doesn't initialize the stored pointer
|
||||
// The storage policy doesn't initialize the stored pointer
|
||||
// which will be initialized by the OwnershipPolicy's Clone fn
|
||||
FunctionStorage(const FunctionStorage& rsh) : pointee_(0), functor_(rsh.functor_)
|
||||
{}
|
||||
|
@ -84,26 +94,26 @@ namespace Loki
|
|||
template <class U>
|
||||
FunctionStorage(const FunctionStorage<U>& rsh) : pointee_(0), functor_(rsh.functor_)
|
||||
{}
|
||||
|
||||
|
||||
FunctionStorage(const StoredType& p) : pointee_(p), functor_() {}
|
||||
|
||||
|
||||
PointerType operator->() const { return pointee_; }
|
||||
|
||||
|
||||
ReferenceType operator*() const { return *pointee_; }
|
||||
|
||||
|
||||
void Swap(FunctionStorage& rhs)
|
||||
{
|
||||
{
|
||||
std::swap(pointee_, rhs.pointee_);
|
||||
std::swap(functor_, rhs.functor_);
|
||||
}
|
||||
|
||||
|
||||
/// Sets the callback function to call. You have to specify it or
|
||||
/// the smartPtr will throw a bad_function_call exception.
|
||||
void SetCallBackFunction(const FunctorType &functor)
|
||||
{
|
||||
functor_ = functor;
|
||||
}
|
||||
|
||||
|
||||
// Accessors
|
||||
template <class F>
|
||||
friend typename FunctionStorage<F>::PointerType GetImpl(const FunctionStorage<F>& sp);
|
||||
|
@ -125,7 +135,7 @@ namespace Loki
|
|||
// Default value to initialize the pointer
|
||||
static StoredType Default()
|
||||
{ return 0; }
|
||||
|
||||
|
||||
private:
|
||||
// Data
|
||||
StoredType pointee_;
|
||||
|
@ -148,7 +158,7 @@ namespace Loki
|
|||
* \class SmartPointer
|
||||
* \ingroup EncapsulationPolicyCachedFactoryGroup
|
||||
* \brief Encapsulate the object in a SmartPtr with FunctionStorage policy.
|
||||
*
|
||||
*
|
||||
* The object will come back to the Cache as soon as no more SmartPtr are
|
||||
* referencing this object. You can customize the SmartPointer with the standard
|
||||
* SmartPtr policies (OwnershipPolicy, ConversionPolicy, CheckingPolicy,
|
||||
|
@ -160,31 +170,31 @@ namespace Loki
|
|||
template <class> class OwnershipPolicy = RefCounted,
|
||||
class ConversionPolicy = DisallowConversion,
|
||||
template <class> class CheckingPolicy = AssertCheck,
|
||||
template<class> class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS
|
||||
>
|
||||
template<class> class ConstnessPolicy = LOKI_DEFAULT_CONSTNESS
|
||||
>
|
||||
class SmartPointer
|
||||
{
|
||||
private:
|
||||
typedef SmartPtr< AbstractProduct,OwnershipPolicy,
|
||||
ConversionPolicy, CheckingPolicy,
|
||||
FunctionStorage, ConstnessPolicy > CallBackSP;
|
||||
protected:
|
||||
protected:
|
||||
typedef CallBackSP ProductReturn;
|
||||
SmartPointer() : fun(this, &SmartPointer::smartPointerCallbackFunction) {}
|
||||
virtual ~SmartPointer(){}
|
||||
|
||||
|
||||
ProductReturn encapsulate(AbstractProduct* pProduct)
|
||||
{
|
||||
CallBackSP SP(pProduct);
|
||||
SP.SetCallBackFunction(fun);
|
||||
return SP;
|
||||
}
|
||||
|
||||
|
||||
AbstractProduct* release(ProductReturn &pProduct)
|
||||
{
|
||||
return GetImpl(pProduct);
|
||||
}
|
||||
|
||||
|
||||
const char* name(){return "smart pointer";}
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue