From 6f706cff82b9dba7c811f17ac3320b2de3331f91 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Mon, 16 Oct 2006 10:30:16 +0000 Subject: [PATCH] add CachedFactory, remove gcc warnings git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@722 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/CachedFactory.h | 4 ++-- test/CachedFactory/CachedFactory.dev | 22 +++++++++++++++++++++- test/CachedFactory/CachedFactoryTest.cpp | 11 ++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/loki/CachedFactory.h b/include/loki/CachedFactory.h index 8e8b112..2083e6b 100755 --- a/include/loki/CachedFactory.h +++ b/include/loki/CachedFactory.h @@ -214,7 +214,7 @@ namespace Loki { assert(byTime>0); this->maxCreation = maxCreation; - this->timeValidity = (clock_t)(byTime * CLOCKS_PER_SEC / 1000); + this->timeValidity = static_cast(byTime * CLOCKS_PER_SEC / 1000); D( cout << "Setting no more than "<< maxCreation <<" creation within " << this->timeValidity <<" ms"<< endl; ) } }; @@ -467,7 +467,7 @@ namespace Loki { if(m_vKeys.size()==0) throw EvictionException(); - size_type random = (size_type)((m_vKeys.size()*rand())/(int)(RAND_MAX + 1)); + size_type random = static_cast((m_vKeys.size()*rand())/int(RAND_MAX + 1)); iterator pos = m_vKeys.begin()+random; DT& evictKey = *pos; remove(evictKey); diff --git a/test/CachedFactory/CachedFactory.dev b/test/CachedFactory/CachedFactory.dev index ee06381..39dcda2 100755 --- a/test/CachedFactory/CachedFactory.dev +++ b/test/CachedFactory/CachedFactory.dev @@ -1,7 +1,7 @@ [Project] FileName=CachedFactory.dev Name=Factory -UnitCount=3 +UnitCount=5 Type=1 Ver=1 ObjFiles= @@ -77,3 +77,23 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit4] +FileName=..\..\include\loki\Key.h +CompileCpp=1 +Folder=Factory +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=..\..\include\loki\CachedFactory.h +CompileCpp=1 +Folder=Factory +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/test/CachedFactory/CachedFactoryTest.cpp b/test/CachedFactory/CachedFactoryTest.cpp index 18f24b5..2ac9417 100755 --- a/test/CachedFactory/CachedFactoryTest.cpp +++ b/test/CachedFactory/CachedFactoryTest.cpp @@ -1,5 +1,6 @@ #define USE_SEQUENCE +#include #include #include @@ -12,7 +13,10 @@ #endif #include -#include +#if defined(_WIN32) || defined(__CYGWIN__) + #include +#endif + using std::cout; using std::cerr; @@ -96,7 +100,7 @@ bool unitTestCacheOverhead(int loop){ } elapsedCache = std::clock() - start; cout << " " << elapsedCache << " ms"; - cout << " | average overhead per fetch : " <<(((double)(elapsedCache-elapsedNoCache)) / CLOCKS_PER_SEC * 1000 / loop) << " ms" << endl; + cout << " | average overhead per fetch : " <<((static_cast(elapsedCache-elapsedNoCache)) / CLOCKS_PER_SEC * 1000 / loop) << " ms" << endl; return true; } @@ -145,7 +149,8 @@ std::clock_t typicalUse( Cache &CC, unsigned objectKind, unsigned maxObjectCount vector< AbstractProduct* > fetched; fetched.reserve(maxObjectCount); srand(0); // initialise the pseudo random operator - std::clock_t start, end; + std::clock_t start(0); + std::clock_t end(0); try{ // Registering objects for(size_t i=0;i