From 98c07576c8dd14e14e8f9996a6c41f84b0d5dbaf Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Thu, 6 Oct 2005 17:50:51 +0000 Subject: [PATCH] adding template based list/sequence implementation, should replace LOKI_TYPELIST_, update some files git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@292 7ec92016-0320-0410-acc4-a06ded1c099a --- test/Factory/Factory.cpp | 21 ++++ test/RegressionTest/SequenceTest.h | 188 +++++++++++++++++++++++++++++ test/RegressionTest/Test.cpp | 4 + 3 files changed, 213 insertions(+) create mode 100755 test/RegressionTest/SequenceTest.h diff --git a/test/Factory/Factory.cpp b/test/Factory/Factory.cpp index 250ae42..f33a37d 100755 --- a/test/Factory/Factory.cpp +++ b/test/Factory/Factory.cpp @@ -11,9 +11,15 @@ //#define CLASS_LEVEL_THERADING +#define USE_SEQUENCE + #include #include "loki/Factory.h" #include "loki/Functor.h" +#ifdef USE_SEQUENCE +#include "loki/Sequence.h" +using Loki::Seq; +#endif using Loki::Functor; using Loki::Factory; @@ -52,7 +58,11 @@ PFactoryNull; typedef SingletonHolder < +#ifndef USE_SEQUENCE Factory< AbstractProduct, int, LOKI_TYPELIST_2( int, int ) > +#else + Factory< AbstractProduct, int, Seq< int, int >::Type > +#endif > PFactory; @@ -136,12 +146,20 @@ public: // get creator functions on runntime /////////////////////////////////////////////////////////////// +#ifndef USE_SEQUENCE typedef Functor CreateFunctor; +#else +typedef Functor::Type> CreateFunctor; +#endif typedef SingletonHolder < +#ifndef USE_SEQUENCE Factory< AbstractProduct, int,LOKI_TYPELIST_3(CreateFunctor,int,int) > +#else + Factory< AbstractProduct, int,Seq::Type > +#endif > PFactoryFunctorParm; @@ -226,6 +244,9 @@ int main(int argc, char *argv[]) } // $Log$ +// Revision 1.3 2005/10/06 17:50:14 syntheticpp +// adding template based list/sequence implementation, should replace LOKI_TYPELIST_, update some files +// // Revision 1.2 2005/09/26 07:33:05 syntheticpp // move macros into LOKI_ namespace // diff --git a/test/RegressionTest/SequenceTest.h b/test/RegressionTest/SequenceTest.h new file mode 100755 index 0000000..728e05d --- /dev/null +++ b/test/RegressionTest/SequenceTest.h @@ -0,0 +1,188 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef SEQUENCETEST_H +#define SEQUENCETEST_H + +#include + +/////////////////////////////////////////////////////////////////////////////// +// SequenceTest +/////////////////////////////////////////////////////////////////////////////// + +class SequenceTest : public Test +{ +public: + SequenceTest() : Test("Sequence.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + using namespace Loki::TL; + + typedef Seq::Type CharList; + typedef Seq::Type CharIntDoubleList; + typedef Seq::Type CharIntDoubleCharList; + typedef Seq::Type BaseDerived1Derived2List; + typedef Seq::Type Derived2Derived1BaseList; + typedef Seq::Type BaseDerived1BaseDerived2List; + typedef Seq::Type Derived1BaseDerived1Derived2List; + + bool r; + + r=Length::value==0 && + Length::value==1 && + Length::value==3; + + testAssert("Length",r,result); + + r=SameType::Result,char>::value && + SameType::Result,double>::value; + + testAssert("TypeAt",r,result); + + #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) + + // TypeAtNonStrict works like TypeAt on MSVC 6.0 + + r=SameType::Result,NullType>::value && + SameType::Result,char>::value && + SameType::Result,double>::value && + SameType::Result,NullType>::value && + SameType::Result,long>::value; + + testAssert("TypeAtNonStrict",r,result); + + #else + + testAssert("TypeAtNonStrict",false,result,false); + + #endif + + r=IndexOf::value==-1 && + IndexOf::value==0 && + IndexOf::value==2 && + IndexOf::value==-1; + + testAssert("IndexOf",r,result); + + #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) + + // Append, Erase, EraseAll, NoDuplicates, Replace, ReplaceAll, Reverse, + // MostDerived and DerivedToFront doesn't work on MSVC 6.0 + + r=SameType::Result,NullType>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,CharList>::value && + SameType::Result,CharList>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value; + + testAssert("Append",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value; + + testAssert("Erase",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value; + + testAssert("EraseAll",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,CharIntDoubleList>::value; + + testAssert("NoDuplicates",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,CharList>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,Seq::Type>::value; + + testAssert("Replace",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,CharList>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,Seq::Type>::value; + + testAssert("ReplaceAll",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,Seq::Type>::value; + + testAssert("Reverse",r,result); + + r=SameType::Result,Base>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value; + + testAssert("MostDerived",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,CharIntDoubleCharList>::value && + SameType::Result,Derived2Derived1BaseList>::value && + SameType::Result,Derived2Derived1BaseList>::value && + SameType::Result,Seq::Type>::value && + SameType::Result,Seq::Type>::value; + + testAssert("DerivedToFront",r,result); + + #else + + testAssert("Append",false,result,false); + testAssert("Erase",false,result,false); + testAssert("EraseAll",false,result,false); + testAssert("NoDuplicates",false,result,false); + testAssert("Replace",false,result,false); + testAssert("Reverse",false,result,false); + testAssert("MostDerived",false,result,false); + testAssert("DerivedToFront",false,result,false); + + #endif + + std::cout << '\n'; + } + +private: + struct Base { char c; }; + struct Derived1 : Base { char c; }; + struct Derived2 : Derived1 { char c; }; +} sequenceTest; +#endif diff --git a/test/RegressionTest/Test.cpp b/test/RegressionTest/Test.cpp index 121a1a5..bae538f 100755 --- a/test/RegressionTest/Test.cpp +++ b/test/RegressionTest/Test.cpp @@ -42,6 +42,7 @@ Test::tests_type Test::tests; // unit test. #include "TypelistTest.h" +#include "SequenceTest.h" #include "TypeManipTest.h" #include "TypeTraitsTest.h" #include "TypeTraitsTest2.h" @@ -111,6 +112,9 @@ return result; // $Log$ +// Revision 1.8 2005/10/06 17:50:14 syntheticpp +// adding template based list/sequence implementation, should replace LOKI_TYPELIST_, update some files +// // Revision 1.7 2005/09/29 08:09:17 syntheticpp // update msvc build process //