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,41 +1,19 @@
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:
// 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.
// 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 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"
// 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: March 05, 2001
// Last update: August 9, 2002
#ifndef HIERARCHYGENERATORS_INC_
#define HIERARCHYGENERATORS_INC_
@ -51,13 +29,13 @@ namespace Loki
// Generates a scattered hierarchy starting from a typelist and a template
// Invocation (TList is a typelist, Model is a template of one arg):
// GenScatterHierarchy<TList, Model>
// The generated class inherits all classes generated by instantiating the
// template 'Model' with the types contained in TList
// The generated class inherits all classes generated by instantiating the
// template 'Model' with the types contained in TList
////////////////////////////////////////////////////////////////////////////////
template <class TList, template <class> class Unit>
class GenScatterHierarchy;
template <class T1, class T2, template <class> class Unit>
class GenScatterHierarchy<Typelist<T1, T2>, Unit>
: public GenScatterHierarchy<T1, Unit>
@ -72,7 +50,7 @@ namespace Loki
typedef Unit<T> Result;
};
};
template <class AtomicType, template <class> class Unit>
class GenScatterHierarchy : public Unit<AtomicType>
{
@ -82,7 +60,7 @@ namespace Loki
typedef Unit<T> Result;
};
};
template <template <class> class Unit>
class GenScatterHierarchy<NullType, Unit>
{
@ -91,31 +69,31 @@ namespace Loki
typedef Unit<T> Result;
};
};
////////////////////////////////////////////////////////////////////////////////
// function template Field
// Accesses a field in an object of a type generated with GenScatterHierarchy
// Invocation (obj is an object of a type H generated with GenScatterHierarchy,
// T is a type in the typelist used to generate H):
// Field<T>(obj)
// returns a reference to Unit<T>, where Unit is the template used to generate H
// returns a reference to Unit<T>, where Unit is the template used to generate H
////////////////////////////////////////////////////////////////////////////////
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;
}
////////////////////////////////////////////////////////////////////////////////
// function template TupleUnit
// The building block of tuples
// The building block of tuples
////////////////////////////////////////////////////////////////////////////////
template <class T>
@ -128,30 +106,41 @@ namespace Loki
////////////////////////////////////////////////////////////////////////////////
// class template Tuple
// Implements a tuple class that holds a number of values and provides field
// access to them via the Field function (below)
// Implements a tuple class that holds a number of values and provides field
// 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;
template <class H>
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
{
isTuple = Conversion<UnitType, TupleUnit<ElementType> >::sameType,
@ -159,16 +148,16 @@ 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,
UnqualifiedResultType>::Result ResultType;
typedef typename IntSelect<isConst, const UnqualifiedResultType,
UnqualifiedResultType>::Result ResultType;
static ResultType& Do(H& obj)
{
LeftBase& leftBase = 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,15 +179,15 @@ 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,
UnqualifiedResultType>::Result ResultType;
typedef typename IntSelect<isConst, const UnqualifiedResultType,
UnqualifiedResultType>::Result ResultType;
static ResultType& Do(H& obj)
{
RightBase& rightBase = obj;
@ -206,8 +195,6 @@ namespace Loki
}
};
*/
////////////////////////////////////////////////////////////////////////////////
// function template Field
// Accesses a field in an object of a type generated with GenScatterHierarchy
@ -215,27 +202,23 @@ namespace Loki
// i is the index of a type in the typelist used to generate H):
// Field<i>(obj)
// returns a reference to Unit<T>, where Unit is the template used to generate H
// and T is the i-th type in the typelist
// and T is the i-th type in the typelist
////////////////////////////////////////////////////////////////////////////////
/*
template <int i, class H>
typename FieldHelper<H, i>::ResultType&
Field(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);
}
*/
// template <int i, class H>
// const typename FieldHelper<H, i>::ResultType&
// Field(const H& obj)
// {
// return FieldHelper<H, i>::Do(obj);
// }
////////////////////////////////////////////////////////////////////////////////
// class template GenLinearHierarchy
// Generates a linear hierarchy starting from a typelist and a template
@ -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_
@