No message

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@40 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
tslettebo 2002-08-23 07:22:07 +00:00
parent 5ca0b883b1
commit b5d2cd3d11
23 changed files with 742 additions and 1184 deletions

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.04; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef ABSTRACTFACTORY_INC_
#define ABSTRACTFACTORY_INC_
@ -181,8 +159,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // ABSTRACTFACTORY_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.04; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,6 +13,8 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: August 9, 2002
#ifndef ASSOCVECTOR_INC_
#define ASSOCVECTOR_INC_
@ -94,258 +74,6 @@ namespace Loki
// * iterators are random
////////////////////////////////////////////////////////////////////////////////
#ifdef __BORLANDC__
template
<
class K,
class V,
class C = std::less<K>,
class A = std::allocator< std::pair<K, V> >
>
class AssocVector
: private std::vector< std::pair<K, V>, A >
, private Private::AssocVectorCompare<V, C>
{
typedef std::vector<std::pair<K, V>, A> Base;
typedef Private::AssocVectorCompare<V, C> MyCompare;
public:
typedef K key_type;
typedef V mapped_type;
typedef typename Base::value_type value_type;
typedef C key_compare;
typedef A allocator_type;
typedef typename A::reference reference;
typedef typename A::const_reference const_reference;
typedef typename Base::iterator iterator;
typedef typename Base::const_iterator const_iterator;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
typedef typename A::pointer pointer;
typedef typename A::const_pointer const_pointer;
typedef typename Base::reverse_iterator reverse_iterator;
typedef typename Base::const_reverse_iterator const_reverse_iterator;
class value_compare
: public std::binary_function<value_type, value_type, bool>
, private key_compare
{
friend class AssocVector;
protected:
value_compare(key_compare pred) : key_compare(pred)
{}
public:
bool operator()(const value_type& lhs, const value_type& rhs) const
{ return key_compare::operator()(lhs.first, rhs.first); }
};
// 23.3.1.1 construct/copy/destroy
explicit AssocVector(const key_compare& comp = key_compare(),
const A& alloc = A())
: std::vector< std::pair<K, V>, A >(alloc), MyCompare(comp)
{}
template <class InputIterator>
AssocVector(InputIterator first, InputIterator last,
const key_compare& comp = key_compare(),
const A& alloc = A())
: std::vector< std::pair<K, V>, A >(first, last, alloc), MyCompare(comp)
{
MyCompare& me = *this;
std::sort(begin(), end(), me);
}
AssocVector& operator=(const AssocVector& rhs)
{
AssocVector(rhs).swap(*this);
return *this;
}
// iterators:
// The following are here because MWCW gets 'using' wrong
iterator begin() { return std::vector< std::pair<K, V>, A >::begin(); }
const_iterator begin() const { return std::vector< std::pair<K, V>, A >::begin(); }
iterator end() { return std::vector< std::pair<K, V>, A >::end(); }
const_iterator end() const { return std::vector< std::pair<K, V>, A >::end(); }
reverse_iterator rbegin() { return std::vector< std::pair<K, V>, A >::rbegin(); }
const_reverse_iterator rbegin() const { return std::vector< std::pair<K, V>, A >::rbegin(); }
reverse_iterator rend() { return std::vector< std::pair<K, V>, A >::rend(); }
const_reverse_iterator rend() const { return std::vector< std::pair<K, V>, A >::rend(); }
// capacity:
bool empty() const { return std::vector< std::pair<K, V>, A >::empty(); }
size_type size() const { return std::vector< std::pair<K, V>, A >::size(); }
size_type max_size() { return std::vector< std::pair<K, V>, A >::max_size(); }
// 23.3.1.2 element access:
mapped_type& operator[](const key_type& key)
{ return insert(value_type(key, mapped_type())).first->second; }
// modifiers:
std::pair<iterator, bool> insert(const value_type& val)
{
bool found(true);
iterator i(lower_bound(val.first));
if (i == end() || operator()(val.first, i->first))
{
i = std::vector< std::pair<K, V>, A >::insert(i, val);
found = false;
}
return std::make_pair(i, !found);
}
iterator insert(iterator pos, const value_type& val)
{
if (pos != end() && operator()(*pos, val) &&
(pos == end() - 1 ||
!operator()(val, pos[1]) &&
operator()(pos[1], val)))
{
return std::vector< std::pair<K, V>, A >::insert(pos, val);
}
return insert(val).first;
}
template <class InputIterator>
iterator insert(InputIterator first, InputIterator last)
{ for (; first != last; ++first) insert(*first); }
void erase(iterator pos)
{ std::vector< std::pair<K, V>, A >::erase(pos); }
size_type erase(const key_type& k)
{
iterator i(find(k));
if (i == end()) return 0;
erase(i);
return 1;
}
void erase(iterator first, iterator last)
{ std::vector< std::pair<K, V>, A >::erase(first, last); }
void swap(AssocVector& other)
{
using namespace std;
std::vector< std::pair<K, V>, A >::swap(other);
MyCompare& me = *this;
MyCompare& rhs = other;
swap(me, rhs);
}
void clear()
{ std::vector< std::pair<K, V>, A >::clear(); }
// observers:
key_compare key_comp() const
{ return *this; }
value_compare value_comp() const
{
const key_compare& comp = *this;
return value_compare(comp);
}
// 23.3.1.3 map operations:
iterator find(const key_type& k)
{
iterator i(lower_bound(k));
if (i != end() && operator()(k, i->first))
{
i = end();
}
return i;
}
const_iterator find(const key_type& k) const
{
const_iterator i(lower_bound(k));
if (i != end() && operator()(k, i->first))
{
i = end();
}
return i;
}
size_type count(const key_type& k) const
{ return find(k) != end(); }
iterator lower_bound(const key_type& k)
{
MyCompare& me = *this;
return std::lower_bound(begin(), end(), k, me);
}
const_iterator lower_bound(const key_type& k) const
{
const MyCompare& me = *this;
return std::lower_bound(begin(), end(), k, me);
}
iterator upper_bound(const key_type& k)
{
MyCompare& me = *this;
return std::upper_bound(begin(), end(), k, me);
}
const_iterator upper_bound(const key_type& k) const
{
const MyCompare& me = *this;
return std::upper_bound(begin(), end(), k, me);
}
std::pair<iterator, iterator> equal_range(const key_type& k)
{
MyCompare& me = *this;
return std::equal_range(begin(), end(), k, me);
}
std::pair<const_iterator, const_iterator> equal_range(
const key_type& k) const
{
const MyCompare& me = *this;
return std::equal_range(begin(), end(), k, me);
}
friend bool operator==(const AssocVector& lhs, const AssocVector& rhs)
{
const std::vector< std::pair<K, V>, A >& me = lhs;
return me == rhs;
}
bool operator<(const AssocVector& rhs) const
{
const std::vector< std::pair<K, V>, A >& me = *this;
const std::vector< std::pair<K, V>, A >& yo = rhs;
return me < yo;
}
friend bool operator!=(const AssocVector& lhs, const AssocVector& rhs)
{ return !(lhs == rhs); }
friend bool operator>(const AssocVector& lhs, const AssocVector& rhs)
{ return rhs < lhs; }
friend bool operator>=(const AssocVector& lhs, const AssocVector& rhs)
{ return !(lhs < rhs); }
friend bool operator<=(const AssocVector& lhs, const AssocVector& rhs)
{ return !(rhs < lhs); }
};
// specialized algorithms:
template <class K, class V, class C, class A>
void swap(AssocVector<K, V, C, A>& lhs, AssocVector<K, V, C, A>& rhs)
{ lhs.swap(rhs); }
#else
template
<
class K,
@ -412,7 +140,7 @@ namespace Loki
AssocVector& operator=(const AssocVector& rhs)
{
AssocVector(rhs).swap(*this);
AssocVector<K, V, C, A>(rhs).swap(*this); // ### Borland fix: template params added to cast
return *this;
}
@ -463,7 +191,7 @@ namespace Loki
}
template <class InputIterator>
iterator insert(InputIterator first, InputIterator last)
void insert(InputIterator first, InputIterator last)
{ for (; first != last; ++first) insert(*first); }
void erase(iterator pos)
@ -482,7 +210,7 @@ namespace Loki
void swap(AssocVector& other)
{
using namespace std;
using std::swap;
Base::swap(other);
MyCompare& me = *this;
MyCompare& rhs = other;
@ -594,8 +322,6 @@ namespace Loki
void swap(AssocVector<K, V, C, A>& lhs, AssocVector<K, V, C, A>& rhs)
{ lhs.swap(rhs); }
#endif
} // namespace Loki
////////////////////////////////////////////////////////////////////////////////
@ -604,8 +330,9 @@ namespace Loki
// June 11, 2001: remove paren in equal_range - credit due to Cristoph Koegl
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// January 22, 2002: fixed operator= - credit due to Tom Hyer
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// June 25, 2002: fixed template insert() - credit due to Robert Minsk
// June 27, 2002: fixed member swap() - credit due to David Brookman
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // ASSOCVECTOR_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef EMPTYTYPE_INC_
#define EMPTYTYPE_INC_
@ -54,8 +32,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // EMPTYTYPE_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,12 +13,12 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef FACTORY_INC_
#define FACTORY_INC_
#include "TypeInfo.h"
#include "Loki_TypeInfo.h"
#include "AssocVector.h"
#include <exception>
@ -57,11 +35,7 @@ namespace Loki
{
struct Exception : public std::exception
{
#ifdef __BORLANDC__
const char* what() { return "Unknown Type"; }
#else
const char* what() const { return "Unknown Type"; }
#endif
const char* what() const throw() { return "Unknown Type"; }
};
static AbstractProduct* OnUnknownType(IdentifierType)
@ -87,6 +61,8 @@ namespace Loki
: public FactoryErrorPolicy<IdentifierType, AbstractProduct>
{
public:
typedef ProductCreator ProductCreator; //### added for convenience, Pavel
bool Register(const IdentifierType& id, ProductCreator creator)
{
return associations_.insert(
@ -100,7 +76,7 @@ namespace Loki
AbstractProduct* CreateObject(const IdentifierType& id)
{
typename IdToProductMap::const_iterator i = associations_.find(id);
typename IdToProductMap::iterator i = associations_.find(id);
if (i != associations_.end())
{
return (i->second)();
@ -130,6 +106,8 @@ namespace Loki
: public FactoryErrorPolicy<TypeInfo, AbstractProduct>
{
public:
typedef ProductCreator ProductCreator; //### added for convenience, Pavel
bool Register(const TypeInfo& ti, ProductCreator creator)
{
return associations_.insert(
@ -145,7 +123,7 @@ namespace Loki
{
if (model == 0) return 0;
typename IdToProductMap::const_iterator i =
typename IdToProductMap::iterator i =
associations_.find(typeid(*model));
if (i != associations_.end())
{
@ -163,8 +141,10 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// May 08, 2002: replaced const_iterator with iterator so that self-modifying
// ProductCreators are supported. Also, added a throw() spec to what().
// Credit due to Jason Fischl.
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // FACTORY_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef FUNCTOR_INC_
#define FUNCTOR_INC_
@ -738,7 +716,7 @@ namespace Loki
// A generalized functor implementation with value semantics
////////////////////////////////////////////////////////////////////////////////
template <typename R, class TList = NullType,
template <typename R = void, class TList = NullType,
template<class> class ThreadingModel = DEFAULT_THREADING>
class Functor
{
@ -1161,8 +1139,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // FUNCTOR_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: March 05, 2001
// Last update: August 9, 2002
#ifndef HIERARCHYGENERATORS_INC_
#define HIERARCHYGENERATORS_INC_
@ -102,13 +80,13 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
template <class T, class H>
typename H::Rebind<T>::Result& Field(H& obj)
typename H::template Rebind<T>::Result& Field(H& obj)
{
return obj;
}
template <class T, class H>
const typename H::Rebind<T>::Result& Field(const H& obj)
const typename H::template Rebind<T>::Result& Field(const H& obj)
{
return obj;
}
@ -132,17 +110,28 @@ namespace Loki
// access to them via the Field function (below)
////////////////////////////////////////////////////////////////////////////////
// template <class TList>
// struct Tuple : public GenScatterHierarchy<TList, TupleUnit>
// {
// };
template <class TList>
struct Tuple : public GenScatterHierarchy<TList, TupleUnit>
{
};
////////////////////////////////////////////////////////////////////////////////
// helper class template FieldHelper
// See Field below
////////////////////////////////////////////////////////////////////////////////
//### BCB: the problem of not treating enum as bool value, like in MultiMethods
template <int flag, typename T, typename U>
struct IntSelect
{
typedef T Result;
};
template <typename T, typename U>
struct IntSelect<0, T, U>
{
typedef U Result;
};
/*
template <class H, unsigned int i> struct FieldHelper;
@ -150,7 +139,7 @@ namespace Loki
struct FieldHelper<H, 0>
{
typedef typename H::TList::Head ElementType;
typedef typename H::Rebind<ElementType>::Result UnitType;
typedef typename H::template Rebind<ElementType>::Result UnitType;
enum
{
@ -160,13 +149,13 @@ namespace Loki
typedef const typename H::LeftBase ConstLeftBase;
typedef typename Select<isConst, ConstLeftBase,
typedef typename IntSelect<isConst, ConstLeftBase,
typename H::LeftBase>::Result LeftBase;
typedef typename Select<isTuple, ElementType,
typedef typename IntSelect<isTuple, ElementType,
UnitType>::Result UnqualifiedResultType;
typedef typename Select<isConst, const UnqualifiedResultType,
typedef typename IntSelect<isConst, const UnqualifiedResultType,
UnqualifiedResultType>::Result ResultType;
static ResultType& Do(H& obj)
@ -180,7 +169,7 @@ namespace Loki
struct FieldHelper
{
typedef typename TL::TypeAt<typename H::TList, i>::Result ElementType;
typedef typename H::Rebind<ElementType>::Result UnitType;
typedef typename H::template Rebind<ElementType>::Result UnitType;
enum
{
@ -190,13 +179,13 @@ namespace Loki
typedef const typename H::RightBase ConstRightBase;
typedef typename Select<isConst, ConstRightBase,
typedef typename IntSelect<isConst, ConstRightBase,
typename H::RightBase>::Result RightBase;
typedef typename Select<isTuple, ElementType,
typedef typename IntSelect<isTuple, ElementType,
UnitType>::Result UnqualifiedResultType;
typedef typename Select<isConst, const UnqualifiedResultType,
typedef typename IntSelect<isConst, const UnqualifiedResultType,
UnqualifiedResultType>::Result ResultType;
static ResultType& Do(H& obj)
@ -206,8 +195,6 @@ namespace Loki
}
};
*/
////////////////////////////////////////////////////////////////////////////////
// function template Field
// Accesses a field in an object of a type generated with GenScatterHierarchy
@ -218,8 +205,6 @@ namespace Loki
// and T is the i-th type in the typelist
////////////////////////////////////////////////////////////////////////////////
/*
template <int i, class H>
typename FieldHelper<H, i>::ResultType&
Field(H& obj)
@ -227,14 +212,12 @@ namespace Loki
return FieldHelper<H, i>::Do(obj);
}
template <int i, class H>
const typename FieldHelper<H, i>::ResultType&
Field(const H& obj)
{
return FieldHelper<H, i>::Do(obj);
}
*/
// template <int i, class H>
// const typename FieldHelper<H, i>::ResultType&
// Field(const H& obj)
// {
// return FieldHelper<H, i>::Do(obj);
// }
////////////////////////////////////////////////////////////////////////////////
// class template GenLinearHierarchy
@ -279,8 +262,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // HIERARCHYGENERATORS_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,15 +13,16 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef MULTIMETHODS_INC_
#define MULTIMETHODS_INC_
#include "Typelist.h"
#include "TypeInfo.h"
#include "Loki_TypeInfo.h" //### BCB
#include "Functor.h"
#include "AssocVector.h"
#include <iostream> // ***
////////////////////////////////////////////////////////////////////////////////
// IMPORTANT NOTE:
@ -60,6 +39,8 @@ namespace Loki
namespace Private
{
/* ### BCB checks existence Fire(rhs, lhs) even when this function is not
needed, fails to compile
template <class SomeLhs, class SomeRhs,
class Executor, typename ResultType>
struct InvocationTraits
@ -77,7 +58,30 @@ namespace Loki
return exec.Fire(rhs, lhs);
}
};
*/
template <class SomeLhs, class SomeRhs, class Executor, typename
ResultType>
struct NormalInvocation
{
static ResultType DoDispatch(SomeLhs& lhs, SomeRhs& rhs,
Executor& exec)
{
return exec.Fire(lhs, rhs);
}
};
template <class SomeLhs, class SomeRhs, class Executor, typename
ResultType>
struct SwappedInvocation
{
static ResultType DoDispatch(SomeLhs& lhs, SomeRhs& rhs,
Executor& exec)
{
return exec.Fire(rhs, lhs);
}
};
}
////////////////////////////////////////////////////////////////////////////////
// class template StaticDispatcher
@ -110,14 +114,18 @@ namespace Loki
if (Head* p2 = dynamic_cast<Head*>(&rhs))
{
Int2Type<(symmetric &&
int(TL::IndexOf<TypesRhs, Head>::value) <
int(TL::IndexOf<TypesLhs, SomeLhs>::value))> i2t;
//### BCB - original statement was too complex for this compiler
enum { val1 = int(TL::IndexOf<TypesRhs, Head>::value) };
enum { val2 = int(TL::IndexOf<TypesLhs, SomeLhs>::value) };
enum { val3 = symmetric && (val1 < val2) };
// BCB doesn't properly converts enum to bool
enum { val4 = val3 != 0 };
const bool val5 = (val4 == 0) ? false : true; // it must be so clumsy
typedef Private::InvocationTraits<
SomeLhs, Head, Executor, ResultType> CallTraits;
return CallTraits::DoDispatch(lhs, *p2, exec, i2t);
typedef Private::NormalInvocation<SomeLhs, Head, Executor, ResultType> t1;
typedef Private::SwappedInvocation<SomeLhs, Head, Executor, ResultType> t2;
typedef Select<val4, t1, t2>::Result invocation_t;
return invocation_t::DoDispatch(lhs, *p2, exec);
}
return DispatchRhs(lhs, rhs, exec, Tail());
}
@ -211,7 +219,9 @@ namespace Loki
typename MapType::iterator i = callbackMap_.find(k);
if (i == callbackMap_.end())
{
throw std::runtime_error("Function not found");
std::cout << "Function not found\n";
// throw std::runtime_error("Function not found");
}
return (i->second)(lhs, rhs);
}
@ -287,9 +297,11 @@ namespace Loki
public:
template <class SomeLhs, class SomeRhs>
void Add(ResultType (*pFun)(BaseLhs&, BaseRhs&))
//### BCB - here it was probably buggy
void Add(ResultType (*pFun)(SomeLhs&, SomeRhs&))
{
return backEnd_.Add<SomeLhs, SomeRhs>(pFun);
return backEnd_.Add<SomeLhs, SomeRhs>((ResultType (*)(BaseLhs&,
BaseRhs&))pFun);
}
template <class SomeLhs, class SomeRhs,
@ -386,9 +398,12 @@ namespace Loki
class FunctorDispatcher
{
typedef TYPELIST_2(BaseLhs&, BaseRhs&) ArgsList;
typedef Functor<ResultType, ArgsList, DEFAULT_THREADING> FunctorType;
//### BCB - this causes compiler crash (even when only one parameter is used)
typedef Functor<ResultType, ArgsList, DEFAULT_THREADING>
FunctorType;
DispatcherBackend<BaseLhs, BaseRhs, ResultType, FunctorType> backEnd_;
DispatcherBackend<BaseLhs, BaseRhs, ResultType, FunctorType>
backEnd_;
public:
template <class SomeLhs, class SomeRhs, class Fun>
@ -440,8 +455,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: November 22, 2001
// Last update: August 9, 2002
#ifndef NULLTYPE_INC_
#define NULLTYPE_INC_
@ -56,8 +34,7 @@ namespace Loki
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// November 22, 2001: minor change to support porting to boost
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // NULLTYPE_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @// @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#include "Singleton.h"
@ -58,7 +36,7 @@ void Loki::Private::AtExitFn()
// Don't check errors - realloc with less memory
// can't fail
pTrackerArray = static_cast<TrackerArray>(std::realloc(
pTrackerArray, sizeof(T) * --elements));
pTrackerArray, sizeof(*pTrackerArray) * --elements));
// Destroy the element
delete pTop;
}
@ -68,6 +46,6 @@ void Loki::Private::AtExitFn()
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// January 10, 2002: Fixed bug in call to realloc - credit due to Nigel Gent and
// Eike Petersen
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// May 08, 2002: Refixed bug in call to realloc
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,6 +13,8 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: August 9, 2002
#ifndef SINGLETON_INC_
#define SINGLETON_INC_
@ -44,6 +24,11 @@ text
#include <cassert>
#include <cstdlib>
#include <new>
#include <string>
#ifdef __BORLANDC__
# define ATEXIT_FIXED
#endif
namespace Loki
{
@ -65,7 +50,7 @@ namespace Loki
static bool Compare(const LifetimeTracker* lhs,
const LifetimeTracker* rhs)
{
return rhs->longevity_ > lhs->longevity_;
return lhs->longevity_ > rhs->longevity_;
}
private:
@ -125,7 +110,7 @@ namespace Loki
TrackerArray pNewArray = static_cast<TrackerArray>(
std::realloc(pTrackerArray,
sizeof(T) * (elements + 1)));
sizeof(*pTrackerArray) * (elements + 1)));
if (!pNewArray) throw std::bad_alloc();
// Delayed assignment for exception safety
@ -236,15 +221,11 @@ namespace Loki
template <class T>
struct DefaultLifetime
{
//#ifdef __BORLANDC__
// static void ScheduleDestruction(T*, void (cdecl *pFun)())
//#else
static void ScheduleDestruction(T*, void (*pFun)())
//#endif
{ std::atexit(pFun); }
static void OnDeadReference()
{ throw std::logic_error("Dead Reference Detected"); }
{ throw std::logic_error(std::string("Dead Reference Detected")); }
};
////////////////////////////////////////////////////////////////////////////////
@ -317,7 +298,7 @@ namespace Loki
}
static void OnDeadReference()
{ throw std::logic_error("Dead Reference Detected"); }
{ throw std::logic_error(std::string("Dead Reference Detected")); }
};
////////////////////////////////////////////////////////////////////////////////
@ -467,8 +448,9 @@ namespace Loki
// Eike Petersen
// March 08, 2002: moved the assignment to pTrackerArray in SetLongevity to fix
// exception safety issue. Credit due to Kari Hoijarvi
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// May 09, 2002: Fixed bug in Compare that caused longevities to act backwards.
// Credit due to Scott McDonald.
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // SINGLETON_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @// @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: March 20, 2001
// Last update: August 9, 2002
#include "SmallObj.h"
#include <cassert>
@ -43,6 +21,13 @@ text
using namespace Loki;
// Used by std::lower_bound in SmallObjAllocator
static bool operator <(const FixedAllocator& lhs, const FixedAllocator& rhs)
{
return lhs.BlockSize() < rhs.BlockSize();
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// FixedAllocator::Chunk::Init
// Initializes a chunk object
@ -53,7 +38,7 @@ void FixedAllocator::Chunk::Init(std::size_t blockSize, unsigned char blocks)
assert(blockSize > 0);
assert(blocks > 0);
// Overflow check
assert((blockSize * blocks) / blockSize == blocks);
assert((blockSize * blocks) / blockSize == (unsigned)blocks);
pData_ = new unsigned char[blockSize * blocks];
Reset(blockSize, blocks);
@ -69,7 +54,7 @@ void FixedAllocator::Chunk::Reset(std::size_t blockSize, unsigned char blocks)
assert(blockSize > 0);
assert(blocks > 0);
// Overflow check
assert((blockSize * blocks) / blockSize == blocks);
assert((blockSize * blocks) / blockSize == (unsigned)blocks);
firstAvailableBlock_ = 0;
blocksAvailable_ = blocks;
@ -102,7 +87,7 @@ void* FixedAllocator::Chunk::Allocate(std::size_t blockSize)
if (!blocksAvailable_) return 0;
assert((firstAvailableBlock_ * blockSize) / blockSize ==
firstAvailableBlock_);
(unsigned)firstAvailableBlock_);
unsigned char* pResult =
pData_ + (firstAvailableBlock_ * blockSize);
@ -129,7 +114,7 @@ void FixedAllocator::Chunk::Deallocate(void* p, std::size_t blockSize)
firstAvailableBlock_ = static_cast<unsigned char>(
(toRelease - pData_) / blockSize);
// Truncation check
assert(firstAvailableBlock_ == (toRelease - pData_) / blockSize);
assert((unsigned)firstAvailableBlock_ == (toRelease - pData_) / blockSize);
++blocksAvailable_;
}
@ -153,7 +138,7 @@ FixedAllocator::FixedAllocator(std::size_t blockSize)
else if (numBlocks == 0) numBlocks = 8 * blockSize;
numBlocks_ = static_cast<unsigned char>(numBlocks);
assert(numBlocks_ == numBlocks);
assert((unsigned)numBlocks_ == numBlocks);
}
////////////////////////////////////////////////////////////////////////////////
@ -316,6 +301,7 @@ FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p)
if (++hi == hiBound) hi = 0;
}
}
//#pragma warn -8066
assert(false);
return 0;
}
@ -398,7 +384,9 @@ void* SmallObjAllocator::Allocate(std::size_t numBytes)
{
return pLastAlloc_->Allocate();
}
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes);
FixedAllocator aux(numBytes);
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), aux);
if (i == pool_.end() || i->BlockSize() != numBytes)
{
i = pool_.insert(i, FixedAllocator(numBytes));
@ -423,7 +411,8 @@ void SmallObjAllocator::Deallocate(void* p, std::size_t numBytes)
pLastDealloc_->Deallocate(p);
return;
}
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes);
FixedAllocator aux(numBytes);
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), aux);
assert(i != pool_.end());
assert(i->BlockSize() == numBytes);
pLastDealloc_ = &*i;
@ -435,6 +424,5 @@ void SmallObjAllocator::Deallocate(void* p, std::size_t numBytes)
// March 20: fix exception safety issue in FixedAllocator::Allocate
// (thanks to Chris Udazvinis for pointing that out)
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef SMALLOBJ_INC_
#define SMALLOBJ_INC_
@ -45,6 +23,8 @@ text
#include <cstddef>
#include <vector>
#pragma warning(disable: 111 444 981)
#ifndef DEFAULT_CHUNK_SIZE
#define DEFAULT_CHUNK_SIZE 4096
#endif
@ -191,7 +171,7 @@ namespace Loki
SingletonHolder<MySmallObjAllocator, CreateStatic,
PhoenixSingleton>::Instance().Deallocate(p, size);
#else
::operator delete(p, size);
::operator delete(p); //### BCB doesn't like size parameter
#endif
}
virtual ~SmallObject() {}
@ -201,8 +181,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // SMALLOBJ_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef SMARTPTR_INC_
#define SMARTPTR_INC_
@ -67,7 +45,7 @@ namespace Loki
template <class T>
class DefaultSPStorage
{
protected:
public:
typedef T* StoredType; // the type of the pointee_ object
typedef T* PointerType; // type returned by operator->
typedef T& ReferenceType; // type returned by operator*
@ -589,7 +567,7 @@ namespace Loki
{
NullPointerException() : std::runtime_error("")
{ }
const char* what() const
const char* what() const throw () //### BCB: throw() added
{ return "Null Pointer Exception"; }
};
@ -708,8 +686,7 @@ namespace Loki
public:
ByRef(T& v) : value_(v) {}
operator T&() { return value_; }
// gcc doesn't like this:
// operator const T&() const { return value_; }
operator const T&() const { return value_; }
private:
T& value_;
};
@ -757,9 +734,10 @@ namespace Loki
typedef typename SP::StoredType StoredType;
typedef typename SP::ReferenceType ReferenceType;
typedef typename Select<OP::destructiveCopy,
SmartPtr, const SmartPtr>::Result
CopyArg;
enum { aux = OP::destructiveCopy }; //### BCB
typedef const SmartPtr<T, OwnershipPolicy, ConversionPolicy, CheckingPolicy, StoragePolicy> Ptr_t;
typedef const Ptr_t cPtr_t;
typedef typename Select<aux, Ptr_t, cPtr_t>::Result CopyArg;
SmartPtr()
{ KP::OnDefault(GetImpl(*this)); }
@ -795,11 +773,13 @@ namespace Loki
: SP(rhs), OP(rhs), KP(rhs), CP(rhs)
{ GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); }
SmartPtr(ByRef<SmartPtr> rhs)
//### BCB
SmartPtr(ByRef<Ptr_t> rhs)
: SP(rhs), OP(rhs), KP(rhs), CP(rhs)
{}
operator ByRef<SmartPtr>()
//### BCB
operator ByRef<Ptr_t>()
{ return ByRef<SmartPtr>(*this); }
SmartPtr& operator=(CopyArg& rhs)
@ -864,25 +844,25 @@ namespace Loki
friend inline void Reset(SmartPtr& sp, typename SP::StoredType p)
{ SmartPtr(p).Swap(sp); }
PointerType operator->()
T* operator->() //### BCB PointerType causes internal compiler crash
{
KP::OnDereference(GetImplRef(*this));
return SP::operator->();
}
PointerType operator->() const
T* operator->() const //### BCB PointerType causes internal compiler crash
{
KP::OnDereference(GetImplRef(*this));
return SP::operator->();
}
ReferenceType operator*()
T& operator*() //### BCB ReferenceType causes internal compiler crash
{
KP::OnDereference(GetImplRef(*this));
return SP::operator*();
}
ReferenceType operator*() const
T& operator*() const //### BCB ReferenceType causes internal compiler crash
{
KP::OnDereference(GetImplRef(*this));
return SP::operator*();
@ -968,7 +948,8 @@ namespace Loki
Insipid(PointerType) {}
};
typedef typename Select<CP::allow, PointerType, Insipid>::Result
enum { aux2 = CP::allow }; // ### BCB, PointerType must be also removed
typedef typename Select<aux2, T*, Insipid>::Result
AutomaticConversionResult;
public:
@ -1212,8 +1193,7 @@ namespace std
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// December 09, 2001: Included <cassert>
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // SMARTPTR_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,8 +13,10 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
#ifndef THREADS_H_
#define THREADS_H_
// Last update: August 9, 2002
#ifndef THREADS_INC_
#define THREADS_INC_
////////////////////////////////////////////////////////////////////////////////
// macro DEFAULT_THREADING
@ -46,6 +26,15 @@ text
// affects only default template arguments
////////////////////////////////////////////////////////////////////////////////
#ifdef __WIN32__
# ifndef _WINDOWS_
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif
#endif
#include <cassert>
// Last update: June 20, 2001
#ifndef DEFAULT_THREADING
@ -99,7 +88,8 @@ namespace Loki
{ lval = val; }
};
#ifdef _WINDOWS_
//#ifdef _WINDOWS_ Borland doesn't use this
#ifdef __WIN32__
////////////////////////////////////////////////////////////////////////////////
// class template ObjectLevelLockable
@ -164,7 +154,11 @@ namespace Loki
class ClassLevelLockable
{
static CRITICAL_SECTION mtx_;
static volatile LONG mtx_initialisation_started;
static volatile LONG mtx_initialisation_done;
//### Borland C++ doesn't like this (it is ignored)
/*
struct Initializer;
friend struct Initializer;
struct Initializer
@ -180,30 +174,12 @@ namespace Loki
};
static Initializer initializer_;
*/
public:
class Lock;
friend class Lock;
class Lock
{
Lock(const Lock&);
Lock& operator=(const Lock&);
public:
Lock()
{
::EnterCriticalSection(&mtx_);
}
Lock(Host&)
{
::EnterCriticalSection(&mtx_);
}
~Lock()
{
::LeaveCriticalSection(&mtx_);
}
};
typedef volatile Host VolatileType;
typedef LONG IntType;
@ -219,14 +195,76 @@ namespace Loki
static void AtomicAssign(IntType& lval, volatile IntType& val)
{ InterlockedExchange(&lval, val); }
private:
// used to protect critical section initialisation
static LONG AtomicExchange(volatile IntType& lval, IntType& new_value) {
return InterlockedExchange(&lval, new_value);
}
public:
class Lock
{
Lock(const Lock&);
Lock& operator=(const Lock&);
//### BCB: the initialisation itself must be protected as it is not done during static initialisation
void initialize_impl(void)
{
LONG now = true;
now = ClassLevelLockable<Host>::AtomicExchange(ClassLevelLockable<Host>::mtx_initialisation_started, now);
assert(ClassLevelLockable<Host>::mtx_initialisation_started);
if (!now) {
assert(!ClassLevelLockable<Host>::mtx_initialisation_done);
::InitializeCriticalSection(&mtx_);
ClassLevelLockable<Host>::mtx_initialisation_done = true;
} else {
// critical section is just being initialized by other thread
while (!ClassLevelLockable<Host>::mtx_initialisation_done) {
Sleep(0);
}
}
}
public:
Lock()
{
//### Here's the trick to make it working on BC++B 6.0
// (because the static Initializer struct is ignored)
//
// The critical section isn't deleted by atexit().
// Shouldn't matter in practise. You may add it here if you want.
if (!mtx_initialisation_done) {
initialize_impl();
}
::EnterCriticalSection(&mtx_);
}
Lock(Host&)
{
if (!mtx_initialisation_done) {
initialize_impl();
}
::EnterCriticalSection(&mtx_);
}
~Lock()
{
::LeaveCriticalSection(&mtx_);
}
};
};
template <class Host>
CRITICAL_SECTION ClassLevelLockable<Host>::mtx_;
template <class Host>
typename ClassLevelLockable<Host>::Initializer
ClassLevelLockable<Host>::initializer_;
LONG volatile ClassLevelLockable<Host>::mtx_initialisation_started;
template <class Host>
LONG volatile ClassLevelLockable<Host>::mtx_initialisation_done;
//### Borland C++ does like this
// template <class Host>
// typename ClassLevelLockable<Host>::Initializer
// ClassLevelLockable<Host>::initializer_;
#endif
}
@ -235,8 +273,7 @@ namespace Loki
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// January 10, 2002: Fixed bug in AtomicDivide - credit due to Jordi Guerrero
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
////////////////////////////////////////////////////////////////////////////////
// This file is intentionally left empty
@ -43,4 +21,3 @@ text
// HierarchyGenerators.h
////////////////////////////////////////////////////////////////////////////////
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: July 10, 2002
// Last update: August 9, 2002
#ifndef TYPEMANIP_INC_
#define TYPEMANIP_INC_
@ -200,8 +178,7 @@ namespace Loki
// (credit due to Brad Town)
// November 23, 2001: (well it's 12:01 am) fixed bug in SUPERSUBCLASS - added
// the volatile qualifier to be 100% politically correct
// July 16, 2002: Ported by Terje Slettebø to Borland C++ Builder 6.0
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // TYPEMANIP_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,6 +13,8 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: August 9, 2002
#ifndef TYPETRAITS_INC_
#define TYPETRAITS_INC_
@ -291,8 +271,7 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // TYPETRAITS_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,6 +13,8 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: August 9, 2002
#ifndef TYPELIST_INC_
#define TYPELIST_INC_
@ -761,8 +741,7 @@ namespace Loki
// Adam Wilkshire;
// Friedrik Hedman who fixed the bug but didn't send the fix;
// Kevin Cline who sent the first actual fix)
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // TYPELIST_INC_
@

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,13 +13,12 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef VISITOR_INC_
#define VISITOR_INC_
#include "Typelist.h"
#include "HierarchyGenerators.h"
namespace Loki
{
@ -179,8 +156,9 @@ struct DefaultCatchAll
// deriving it from BaseVisitable<R>
////////////////////////////////////////////////////////////////////////////////
//### BCB port - added Loki:: prefix
#define DEFINE_VISITABLE() \
virtual ReturnType Accept(BaseVisitor& guest) \
virtual ReturnType Accept(Loki::BaseVisitor& guest) \
{ return AcceptImpl(*this, guest); }
////////////////////////////////////////////////////////////////////////////////
@ -219,8 +197,7 @@ struct DefaultCatchAll
// Change log:
// March 20: add default argument DefaultCatchAll to BaseVisitable
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // VISITOR_INC_
@

108
Borland/loki_typeinfo.h Normal file
View file

@ -0,0 +1,108 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
// 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.
// The author or Addison-Wesley Longman make no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: August 9, 2002
#ifndef TYPEINFO_INC_
#define TYPEINFO_INC_
#include <typeinfo>
#include <cassert>
#include "Typelist.h"
namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
// class TypeInfo
// Purpose: offer a first-class, comparable wrapper over std::type_info
////////////////////////////////////////////////////////////////////////////////
class TypeInfo
{
public:
// Constructors
TypeInfo(); // needed for containers
TypeInfo(const std::type_info&); // non-explicit
// Access for the wrapped std::type_info
const std::type_info& Get() const;
// Compatibility functions
bool before(const TypeInfo& rhs) const;
const char* name() const;
private:
const std::type_info* pInfo_;
};
// Implementation
inline TypeInfo::TypeInfo()
{
class Nil {};
pInfo_ = &typeid(Nil);
assert(pInfo_);
}
inline TypeInfo::TypeInfo(const std::type_info& ti)
: pInfo_(&ti)
{ assert(pInfo_); }
inline bool TypeInfo::before(const TypeInfo& rhs) const
{
assert(pInfo_);
return pInfo_->before(*rhs.pInfo_);
}
inline const std::type_info& TypeInfo::Get() const
{
assert(pInfo_);
return *pInfo_;
}
inline const char* TypeInfo::name() const
{
assert(pInfo_);
return pInfo_->name();
}
// Comparison operators
inline bool operator==(const TypeInfo& lhs, const TypeInfo& rhs)
{ return lhs.Get() == rhs.Get(); }
inline bool operator<(const TypeInfo& lhs, const TypeInfo& rhs)
{ return lhs.before(rhs); }
inline bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs)
{ return !(lhs == rhs); }
inline bool operator>(const TypeInfo& lhs, const TypeInfo& rhs)
{ return rhs < lhs; }
inline bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs)
{ return !(lhs > rhs); }
inline bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs)
{ return !(lhs < rhs); }
}
////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // TYPEINFO_INC_

View file

@ -1 +0,0 @@
?

22
Borland/readme.txt Normal file
View file

@ -0,0 +1,22 @@
Last update: August 9, 2002
Directions:
To use Loki, simply extract the files from the archive, give your compiler access to their path, and include them appropriately in your code via #include.
If you use the small object allocator directly or indirectly (through the Functor class) you must add SmallObj.cpp to your project/makefile.
If you use Singletons with longevity you must add Singleton.cpp to your project/makefile.
Compatibility:
Loki has been tested with Metrowerks CodeWarrior Pro 6 under Windows. CodeWarrior has a problem with the Conversion template (see TypeManip.h) and, though it compiles it, it doesn't provide correct results. Consequently, the DerivedToFront algorithm in Typelist.h does not function. This affects the static dispatcher in Multimethods.h. As a fix, you must order the types (putting the most derived ones in the front) when providing the typelist argument to StaticDispatcher.
Also, Loki has been ported to g++ 2.95.3 by Nick Thurn.
This is a ported version of Loki to Borland C++ Builder 6.0. However, it uses standard C++, so it should work on the other compilers, as well.
More info:
http://moderncppdesign.com

View file

@ -1,26 +1,4 @@
head 1.1;
access;
symbols;
locks; strict;
comment @ * @;
1.1
date 2002.07.16.22.42.05; author tslettebo; state Exp;
branches;
next ;
desc
@@
1.1
log
@Initial commit
@
text
@////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
@ -35,7 +13,7 @@ text
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
// Last update: June 20, 2001
// Last update: August 9, 2002
#ifndef STATIC_CHECK_INC_
#define STATIC_CHECK_INC_
@ -59,17 +37,24 @@ namespace Loki
// If expr is zero, id will appear in a compile-time error message.
////////////////////////////////////////////////////////////////////////////////
#define STATIC_CHECK(expr, msg) \
{ Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }
template<bool>
struct CompileTimeChecker
{
CompileTimeChecker(...);
};
template<> struct CompileTimeChecker<false> {};
#define STATIC_CHECK(expr, msg)\
{\
class ERROR_##msg {}; \
(void)sizeof(CompileTimeChecker<(expr)>(ERROR_##msg()));\
}
////////////////////////////////////////////////////////////////////////////////
// Change log:
// March 20, 2001: add extra parens to STATIC_CHECK - it looked like a fun
// definition
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// July 16, 2002: Ported by Terje Slettebø to BCC 5.6
// July 16, 2002: Ported by Terje Slettebø and Pavel Vozenilek to BCC 5.6
////////////////////////////////////////////////////////////////////////////////
#endif // STATIC_CHECK_INC_
@