diff --git a/Borland/TypeManip.h b/Borland/TypeManip.h index deba1d8..8861101 100644 --- a/Borland/TypeManip.h +++ b/Borland/TypeManip.h @@ -143,32 +143,64 @@ namespace Loki static const bool sameType = true; }; -} // namespace Loki - //////////////////////////////////////////////////////////////////////////////// -// macro SUPERSUBCLASS -// Invocation: SUPERSUBCLASS(B, D) where B and D are types. -// Returns true if B is a public base of D, or if B and D are aliases of the +// class template SuperSubclass +// Invocation: SuperSubclass::value where B and D are types. +// Returns true if B is a public base of D, or if B and D are aliases of the // same type. // // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// -#define SUPERSUBCLASS(T, U) \ - (::Loki::Conversion::exists && \ - !::Loki::Conversion::sameType) +template +struct SuperSubclass +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType) }; +}; //////////////////////////////////////////////////////////////////////////////// -// macro SUPERSUBCLASS -// Invocation: SUPERSUBCLASS(B, D) where B and D are types. +// class template SuperSubclassStrict +// Invocation: SuperSubclassStrict::value where B and D are types. // Returns true if B is a public base of D. // // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// +template +struct SuperSubclassStrict +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType && + !::Loki::Conversion::sameType) }; +}; + +} // namespace Loki + +//////////////////////////////////////////////////////////////////////////////// +// macro SUPERSUBCLASS +// Invocation: SUPERSUBCLASS(B, D) where B and D are types. +// Returns true if B is a public base of D, or if B and D are aliases of the +// same type. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +// Deprecated: Use SuperSubclass class template instead. +//////////////////////////////////////////////////////////////////////////////// + +#define SUPERSUBCLASS(T, U) \ + ::Loki::SuperSubclass::value + +//////////////////////////////////////////////////////////////////////////////// +// macro SUPERSUBCLASS_STRICT +// Invocation: SUPERSUBCLASS(B, D) where B and D are types. +// Returns true if B is a public base of D. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +// Deprecated: Use SuperSubclassStrict class template instead. +//////////////////////////////////////////////////////////////////////////////// + #define SUPERSUBCLASS_STRICT(T, U) \ - ((SUPERSUBCLASS(T, U) && \ - !::Loki::Conversion::sameType)) + ::Loki::SuperSubclassStrict::value //////////////////////////////////////////////////////////////////////////////// // Change log: @@ -179,6 +211,8 @@ namespace Loki // 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ų and Pavel Vozenilek to BCC 5.6 +// October 12, 2002: Added SuperSubclass and SuperSubclassStrict templates. +// The corresponding macros are deprecated. T.S. //////////////////////////////////////////////////////////////////////////////// #endif // TYPEMANIP_INC_ diff --git a/MSVC/1200/AssocVector.h b/MSVC/1200/AssocVector.h new file mode 100644 index 0000000..2b4386e --- /dev/null +++ b/MSVC/1200/AssocVector.h @@ -0,0 +1,335 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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. +//////////////////////////////////////////////////////////////////////////////// + +#ifndef ASSOCVECTOR_INC_ +#define ASSOCVECTOR_INC_ + +#include +#include +#include +#include + +namespace Loki +{ +//////////////////////////////////////////////////////////////////////////////// +// class template AssocVectorCompare +// Used by AssocVector +//////////////////////////////////////////////////////////////////////////////// + + namespace Private + { + template + class AssocVectorCompare : public C + { + typedef std::pair + Data; + typedef typename C::first_argument_type first_argument_type; + + public: + AssocVectorCompare() + {} + + AssocVectorCompare(const C& src) : C(src) + {} + + bool operator()(const first_argument_type& lhs, + const first_argument_type& rhs) const + { return C::operator()(lhs, rhs); } + + bool operator()(const Data& lhs, const Data& rhs) const + { return operator()(lhs.first, rhs.first); } + + bool operator()(const Data& lhs, + const first_argument_type& rhs) const + { return operator()(lhs.first, rhs); } + + bool operator()(const first_argument_type& lhs, + const Data& rhs) const + { return operator()(lhs, rhs.first); } + }; + } + +//////////////////////////////////////////////////////////////////////////////// +// class template AssocVector +// An associative vector built as a syntactic drop-in replacement for std::map +// BEWARE: AssocVector doesn't respect all map's guarantees, the most important +// being: +// * iterators are invalidated by insert and erase operations +// * the complexity of insert/erase is O(N) not O(log N) +// * value_type is std::pair not std::pair +// * iterators are random +//////////////////////////////////////////////////////////////////////////////// + + template + < + class K, + class V, + class C = std::less, + class A = std::allocator< std::pair > + > + class AssocVector + : private std::vector< std::pair, A > + , private Private::AssocVectorCompare + { + typedef std::vector, A> Base; + typedef Private::AssocVectorCompare 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 + , 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()) + : Base(alloc), MyCompare(comp) + {} + + template + AssocVector(InputIterator first, InputIterator last, + const key_compare& comp = key_compare(), + const A& alloc = A()) + : Base(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 Base::begin(); } + const_iterator begin() const { return Base::begin(); } + iterator end() { return Base::end(); } + const_iterator end() const { return Base::end(); } + reverse_iterator rbegin() { return Base::rbegin(); } + const_reverse_iterator rbegin() const { return Base::rbegin(); } + reverse_iterator rend() { return Base::rend(); } + const_reverse_iterator rend() const { return Base::rend(); } + + // capacity: + bool empty() const { return Base::empty(); } + size_type size() const { return Base::size(); } + size_type max_size() { return Base::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 insert(const value_type& val) + { + bool found(true); + iterator i(lower_bound(val.first)); + + if (i == end() || operator()(val.first, i->first)) + { + i = Base::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 Base::insert(pos, val); + } + return insert(val).first; + } + + template + void insert(InputIterator first, InputIterator last) + { for (; first != last; ++first) insert(*first); } + + void erase(iterator pos) + { Base::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) + { Base::erase(first, last); } + + void swap(AssocVector& other) + { + using std::swap; + Base::swap(other); + MyCompare& me = *this; + MyCompare& rhs = other; + swap(me, rhs); + } + + void clear() + { Base::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 equal_range(const key_type& k) + { + MyCompare& me = *this; + return std::equal_range(begin(), end(), k, me); + } + + std::pair 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 Base& me = lhs; + return me == rhs; + } + + bool operator<(const AssocVector& rhs) const + { + const Base& me = *this; + const Base& 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 + void swap(AssocVector& lhs, AssocVector& rhs) + { lhs.swap(rhs); } + +} // namespace Loki + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// May 20, 2001: change operator= - credit due to Cristoph Koegl +// 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 +// June 25, 2002: fixed template insert() - credit due to Robert Minsk +// June 27, 2002: fixed member swap() - credit due to David Brookman +//////////////////////////////////////////////////////////////////////////////// + +#endif // ASSOCVECTOR_INC_ diff --git a/MSVC/1200/EmptyType.h b/MSVC/1200/EmptyType.h new file mode 100644 index 0000000..e8ffb17 --- /dev/null +++ b/MSVC/1200/EmptyType.h @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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: June 20, 2001 + +#ifndef EMPTYTYPE_INC_ +#define EMPTYTYPE_INC_ + +namespace Loki +{ +//////////////////////////////////////////////////////////////////////////////// +// class EmptyType +// Used as a class type that doesn't hold anything +// Useful as a strawman class +//////////////////////////////////////////////////////////////////////////////// + + class EmptyType {}; +} + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +//////////////////////////////////////////////////////////////////////////////// + +#endif // EMPTYTYPE_INC_ diff --git a/MSVC/1200/Factory.h b/MSVC/1200/Factory.h new file mode 100644 index 0000000..d72416b --- /dev/null +++ b/MSVC/1200/Factory.h @@ -0,0 +1,153 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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: October 12, 2002 + +#ifndef FACTORY_INC_ +#define FACTORY_INC_ + +#include "TypeInfo.h" +#include "AssocVector.h" +#include + +namespace Loki +{ + +//////////////////////////////////////////////////////////////////////////////// +// class DefaultFactoryError +// Manages the "Unknown Type" error in an object factory +//////////////////////////////////////////////////////////////////////////////// + + struct DefaultFactoryError + { + + struct Exception : public std::exception + { + const char* what() const throw() { return "Unknown Type"; } + }; + + template + static AbstractProduct* OnUnknownType(IdentifierType,AbstractProduct *) + { + throw Exception(); + } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template Factory +// Implements a generic object factory +//////////////////////////////////////////////////////////////////////////////// + + template + < + class AbstractProduct, + typename IdentifierType, + typename ProductCreator = AbstractProduct* (*)(), + class FactoryErrorPolicy = DefaultFactoryError + > + class Factory + : public FactoryErrorPolicy + { + public: + bool Register(const IdentifierType& id, ProductCreator creator) + { + return associations_.insert( + IdToProductMap::value_type(id, creator)).second; + } + + bool Unregister(const IdentifierType& id) + { + return associations_.erase(id) == 1; + } + + AbstractProduct* CreateObject(const IdentifierType& id) + { + typename IdToProductMap::iterator i = associations_.find(id); + if (i != associations_.end()) + { + return (i->second)(); + } + + AbstractProduct *dummy; + + return OnUnknownType(id,dummy); + } + + private: + typedef AssocVector IdToProductMap; + IdToProductMap associations_; + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template CloneFactory +// Implements a generic cloning factory +//////////////////////////////////////////////////////////////////////////////// + + template + < + class AbstractProduct, + class ProductCreator = + AbstractProduct* (*)(const AbstractProduct*), + typename FactoryErrorPolicy = DefaultFactoryError + > + class CloneFactory + : public FactoryErrorPolicy + { + public: + bool Register(const TypeInfo& ti, ProductCreator creator) + { + return associations_.insert( + IdToProductMap::value_type(ti, creator)).second; + } + + bool Unregister(const TypeInfo& id) + { + return associations_.erase(id) == 1; + } + + AbstractProduct* CreateObject(const AbstractProduct* model) + { + if (model == 0) return 0; + + typename IdToProductMap::iterator i = + associations_.find(typeid(*model)); + if (i != associations_.end()) + { + return (i->second)(model); + } + + AbstractProduct *dummy; + + return OnUnknownType(TypeInfo(typeid(*model)),dummy); + } + + private: + typedef AssocVector IdToProductMap; + IdToProductMap associations_; + }; +} // namespace Loki + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +// 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. +// October 12, 2002: Ported to MSVC 6 by Terje Slettebų. Interface for Factory +// and CloneFactory changed from using template template parameter, +// to using class with member template, for the FactoryErrorPolicy. +//////////////////////////////////////////////////////////////////////////////// + +#endif // FACTORY_INC_ diff --git a/MSVC/1200/NullType.h b/MSVC/1200/NullType.h new file mode 100644 index 0000000..c2f31be --- /dev/null +++ b/MSVC/1200/NullType.h @@ -0,0 +1,39 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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: November 22, 2001 + +#ifndef NULLTYPE_INC_ +#define NULLTYPE_INC_ + +namespace Loki +{ +//////////////////////////////////////////////////////////////////////////////// +// class NullType +// Used as a placeholder for "no type here" +// Useful as an end marker in typelists +//////////////////////////////////////////////////////////////////////////////// + + class NullType {}; + +} // 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 +//////////////////////////////////////////////////////////////////////////////// + +#endif // NULLTYPE_INC_ diff --git a/MSVC/1200/Singleton.cpp b/MSVC/1200/Singleton.cpp new file mode 100644 index 0000000..6be0957 --- /dev/null +++ b/MSVC/1200/Singleton.cpp @@ -0,0 +1,53 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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: June 20, 2001 + +#include "Singleton.h" + +using namespace Loki::Private; + +Loki::Private::TrackerArray Loki::Private::pTrackerArray = 0; +unsigned int Loki::Private::elements = 0; + +//////////////////////////////////////////////////////////////////////////////// +// function AtExitFn +// Ensures proper destruction of objects with longevity +//////////////////////////////////////////////////////////////////////////////// + +void Loki::Private::AtExitFn() +{ + assert(elements > 0 && pTrackerArray != 0); + // Pick the element at the top of the stack + LifetimeTracker* pTop = pTrackerArray[elements - 1]; + // Remove that object off the stack + // Don't check errors - realloc with less memory + // can't fail + pTrackerArray = static_cast(realloc( + pTrackerArray, sizeof(*pTrackerArray) * --elements)); + // Destroy the element + delete pTop; +} + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// 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 +// May 08, 2002: Refixed bug in call to realloc +// October 12, 2002: Ported to MSVC 6 by Terje Slettebų. +// Interface for SingletonHolder changed from using template template +// parameters, to using classes with member templates. +//////////////////////////////////////////////////////////////////////////////// diff --git a/MSVC/1200/Singleton.h b/MSVC/1200/Singleton.h new file mode 100644 index 0000000..775d409 --- /dev/null +++ b/MSVC/1200/Singleton.h @@ -0,0 +1,499 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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. +//////////////////////////////////////////////////////////////////////////////// + +#ifndef SINGLETON_INC_ +#define SINGLETON_INC_ + +#include "Threads.h" +#include +#include +#include +#include +#include + +namespace Loki +{ + namespace Private + { + template< typename T > + struct MSVCNeverTrue + { + enum { value = false }; + }; + + template + struct Apply + { + #ifdef _MSC_VER + // based on the (non-conforming) MSVC trick from MPL + + template + struct MetaFunctionWrapper_VC : MetaFunctionWrapper {}; + + //illegal C++ which causes VC to admit that MetaFunctionWrapper_VC + //can have a nested template: + + template<> + struct MetaFunctionWrapper_VC + {template struct VolatileType; }; + + typedef typename MetaFunctionWrapper_VC< + MSVCNeverTrue::value + >::template VolatileType::Result Result; + #else + typedef typename MetaFunctionWrapper::template VolatileType::Result Result; + #endif + }; + +//////////////////////////////////////////////////////////////////////////////// +// class LifetimeTracker +// Helper class for SetLongevity +//////////////////////////////////////////////////////////////////////////////// + + class LifetimeTracker + { + public: + LifetimeTracker(unsigned int x) : longevity_(x) + {} + + virtual ~LifetimeTracker() = 0; + + static bool Compare(const LifetimeTracker* lhs, + const LifetimeTracker* rhs) + { + return lhs->longevity_ > rhs->longevity_; + } + + private: + unsigned int longevity_; + }; + + // Definition required + inline LifetimeTracker::~LifetimeTracker() {} + + // Helper data + typedef LifetimeTracker** TrackerArray; + extern TrackerArray pTrackerArray; + extern unsigned int elements; + + // Helper destroyer function + template + struct Deleter + { + static void Delete(T* pObj) + { delete pObj; } + }; + + // Concrete lifetime tracker for objects of type T + template + class ConcreteLifetimeTracker : public LifetimeTracker + { + public: + ConcreteLifetimeTracker(T* p,unsigned int longevity, Destroyer d) + : LifetimeTracker(longevity) + , pTracked_(p) + , destroyer_(d) + {} + + ~ConcreteLifetimeTracker() + { destroyer_(pTracked_); } + + private: + T* pTracked_; + Destroyer destroyer_; + }; + + void AtExitFn(); // declaration needed below + + } // namespace Private + +//////////////////////////////////////////////////////////////////////////////// +// function template SetLongevity +// Assigns an object a longevity; ensures ordered destructions of objects +// registered thusly during the exit sequence of the application +//////////////////////////////////////////////////////////////////////////////// + + template + void SetLongevity(T* pDynObject, unsigned int longevity, + Destroyer d = Private::Deleter::Delete) + { + using namespace Private; + + TrackerArray pNewArray = static_cast( + realloc(pTrackerArray, + sizeof(*pTrackerArray) * (elements + 1))); + if (!pNewArray) throw std::bad_alloc(); + + // Delayed assignment for exception safety + pTrackerArray = pNewArray; + + LifetimeTracker* p = new ConcreteLifetimeTracker( + pDynObject, longevity, d); + + // Insert a pointer to the object into the queue + TrackerArray pos = std::upper_bound( + pTrackerArray, + pTrackerArray + elements, + p, + LifetimeTracker::Compare); + std::copy_backward( + pos, + pTrackerArray + elements, + pTrackerArray + elements + 1); + *pos = p; + ++elements; + + // Register a call to AtExitFn + atexit(Private::AtExitFn); + } + +//////////////////////////////////////////////////////////////////////////////// +// class template CreateUsingNew +// Implementation of the CreationPolicy used by SingletonHolder +// Creates objects using a straight call to the new operator +//////////////////////////////////////////////////////////////////////////////// + + struct CreateUsingNew + { + template + static T* Create(T*) + { return new T; } + + template + static void Destroy(T* p) + { delete p; } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template CreateUsingNew +// Implementation of the CreationPolicy used by SingletonHolder +// Creates objects using a call to std::malloc, followed by a call to the +// placement new operator +//////////////////////////////////////////////////////////////////////////////// + + struct CreateUsingMalloc + { + + template + static T* Create(T*) + { + void* p = malloc(sizeof(T)); + if (!p) return 0; + return new(p) T; + } + + template + static void Destroy(T* p) + { + p->~T(); + free(p); + } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template CreateStatic +// Implementation of the CreationPolicy used by SingletonHolder +// Creates an object in static memory +// Implementation is slightly nonportable because it uses the MaxAlign trick +// (an union of all types to ensure proper memory alignment). This trick is +// nonportable in theory but highly portable in practice. +//////////////////////////////////////////////////////////////////////////////// + + struct CreateStatic + { + template + static T* Create(T*) + { + union MaxAlign + { + char t_[sizeof(T)]; + short int shortInt_; + int int_; + long int longInt_; + float float_; + double double_; + long double longDouble_; + struct Test; + int Test::* pMember_; + int (Test::*pMemberFn_)(int); + }; + + static MaxAlign staticMemory_; + return new(&staticMemory_) T; + } + + template + static void Destroy(T* p) + { + p->~T(); + } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template DefaultLifetime +// Implementation of the LifetimePolicy used by SingletonHolder +// Schedules an object's destruction as per C++ rules +// Forwards to std::atexit +//////////////////////////////////////////////////////////////////////////////// + + struct DefaultLifetime + { + template + static void ScheduleDestruction(T*, void (*pFun)()) + { atexit(pFun); } + + template + static void OnDeadReference(T*) + { throw std::exception("Dead Reference Detected"); } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template PhoenixSingleton +// Implementation of the LifetimePolicy used by SingletonHolder +// Schedules an object's destruction as per C++ rules, and it allows object +// recreation by not throwing an exception from OnDeadReference +//////////////////////////////////////////////////////////////////////////////// + + class PhoenixSingleton + { + public: + template + static void ScheduleDestruction(T*, void (*pFun)()) + { +#ifndef ATEXIT_FIXED + if (!destroyedOnce_) +#endif + atexit(pFun); + } + + template + static void OnDeadReference(T*) + { +#ifndef ATEXIT_FIXED + destroyedOnce_ = true; +#endif + } + + private: +#ifndef ATEXIT_FIXED + static bool destroyedOnce_; +#endif + }; + +#ifndef ATEXIT_FIXED + bool PhoenixSingleton::destroyedOnce_ = false; +#endif + +//////////////////////////////////////////////////////////////////////////////// +// class template Adapter +// Helper for SingletonWithLongevity below +//////////////////////////////////////////////////////////////////////////////// + + namespace Private + { + template + struct Adapter + { + void operator()(T*) { pFun_(); } + void (*pFun_)(); + }; + } + +//////////////////////////////////////////////////////////////////////////////// +// class template SingletonWithLongevity +// Implementation of the LifetimePolicy used by SingletonHolder +// Schedules an object's destruction in order of their longevities +// Assumes a visible function GetLongevity(T*) that returns the longevity of the +// object +//////////////////////////////////////////////////////////////////////////////// + + class SingletonWithLongevity + { + public: + template + static void ScheduleDestruction(T* pObj, void (*pFun)()) + { + Private::Adapter adapter = { pFun }; + SetLongevity(pObj, GetLongevity(pObj), adapter); + } + + template + static void OnDeadReference(T*) + { throw std::exception("Dead Reference Detected"); } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template NoDestroy +// Implementation of the LifetimePolicy used by SingletonHolder +// Never destroys the object +//////////////////////////////////////////////////////////////////////////////// + + struct NoDestroy + { + template + static void ScheduleDestruction(T*, void (*)()) + {} + + template + static void OnDeadReference(T*) + {} + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template SingletonHolder +// Provides Singleton amenities for a type T +// To protect that type from spurious instantiations, you have to protect it +// yourself. +//////////////////////////////////////////////////////////////////////////////// + + template + < + typename T, + class CreationPolicy = CreateUsingNew, + class LifetimePolicy = DefaultLifetime, + class ThreadingModel = SingleThreaded + > + class SingletonHolder + { + public: + static T& Instance(); + + private: + // Helpers + static void MakeInstance(); + static void DestroySingleton(); + + // Protection + SingletonHolder(); + + // Data + typedef typename Private::Apply::Result PtrInstanceType; + +// typedef typename ThreadingModel::VolatileType::Result PtrInstanceType; + static PtrInstanceType pInstance_; + static bool destroyed_; + }; + +//////////////////////////////////////////////////////////////////////////////// +// SingletonHolder's data +//////////////////////////////////////////////////////////////////////////////// + + template + < + class T, + class C, + class L, + class M + > + typename SingletonHolder::PtrInstanceType + SingletonHolder::pInstance_; + + template + < + class T, + class C, + class L, + class M + > + bool SingletonHolder::destroyed_; + +//////////////////////////////////////////////////////////////////////////////// +// SingletonHolder::Instance +//////////////////////////////////////////////////////////////////////////////// + + template + < + class T, + class CreationPolicy, + class LifetimePolicy, + class ThreadingModel + > + inline T& SingletonHolder::Instance() + { + if (!pInstance_) + { + MakeInstance(); + } + return *pInstance_; + } + +//////////////////////////////////////////////////////////////////////////////// +// SingletonHolder::MakeInstance (helper for Instance) +//////////////////////////////////////////////////////////////////////////////// + + template + < + class T, + class CreationPolicy, + class LifetimePolicy, + class ThreadingModel + > + void SingletonHolder::MakeInstance() + { + typename ThreadingModel::Lock guard; + (void)guard; + + if (!pInstance_) + { + if (destroyed_) + { + T* dummy; + + LifetimePolicy::OnDeadReference(dummy); + destroyed_ = false; + } + + T* dummy; + + pInstance_ = CreationPolicy::Create(dummy); + LifetimePolicy::ScheduleDestruction(pInstance_, + &DestroySingleton); + } + } + + template + < + class T, + class CreationPolicy, + class L, + class M + > + void SingletonHolder::DestroySingleton() + { + assert(!destroyed_); + CreationPolicy::Destroy(pInstance_); + pInstance_ = 0; + destroyed_ = true; + } +} // namespace Loki + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// May 21, 2001: Correct the volatile qualifier - credit due to Darin Adler +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +// January 08, 2002: Fixed bug in call to realloc - credit due to Nigel Gent and +// Eike Petersen +// March 08, 2002: moved the assignment to pTrackerArray in SetLongevity to fix +// exception safety issue. Credit due to Kari Hoijarvi +// May 09, 2002: Fixed bug in Compare that caused longevities to act backwards. +// Credit due to Scott McDonald. +// October 12, 2002: Ported to MSVC 6 by Terje Slettebų. +// Interface for SingletonHolder changed from using template template +// parameters, to using classes with member templates. +//////////////////////////////////////////////////////////////////////////////// + +#endif // SINGLETON_INC_ diff --git a/MSVC/1200/Threads.h b/MSVC/1200/Threads.h new file mode 100644 index 0000000..d45b5df --- /dev/null +++ b/MSVC/1200/Threads.h @@ -0,0 +1,213 @@ +#ifndef THREADS_H_ +#define THREADS_H_ + +//////////////////////////////////////////////////////////////////////////////// +// macro DEFAULT_THREADING +// Selects the default threading model for certain components of Loki +// If you don't define it, it defaults to single-threaded +// All classes in Loki have configurable threading model; DEFAULT_THREADING +// affects only default template arguments +//////////////////////////////////////////////////////////////////////////////// + +// Last update: June 20, 2001 + +#ifndef DEFAULT_THREADING +#define DEFAULT_THREADING /**/ ::Loki::SingleThreaded +#endif + +namespace Loki +{ +//////////////////////////////////////////////////////////////////////////////// +// class template SingleThreaded +// Implementation of the ThreadingModel policy used by various classes +// Implements a single-threaded model; no synchronization +//////////////////////////////////////////////////////////////////////////////// + + class SingleThreaded + { + public: + template + struct Lock + { + Lock() {} + Lock(const Host&) {} + }; + + template + struct VolatileType + { + typedef Host Result; + }; + + typedef int IntType; + + static IntType AtomicAdd(volatile IntType& lval, IntType val) + { return lval += val; } + + static IntType AtomicSubtract(volatile IntType& lval, IntType val) + { return lval -= val; } + + static IntType AtomicMultiply(volatile IntType& lval, IntType val) + { return lval *= val; } + + static IntType AtomicDivide(volatile IntType& lval, IntType val) + { return lval /= val; } + + static IntType AtomicIncrement(volatile IntType& lval) + { return ++lval; } + + static IntType AtomicDecrement(volatile IntType& lval) + { return --lval; } + + static void AtomicAssign(volatile IntType & lval, IntType val) + { lval = val; } + + static void AtomicAssign(IntType & lval, volatile IntType & val) + { lval = val; } + }; + +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) + +#include + +//////////////////////////////////////////////////////////////////////////////// +// class template ObjectLevelLockable +// Implementation of the ThreadingModel policy used by various classes +// Implements a object-level locking scheme +//////////////////////////////////////////////////////////////////////////////// + + class ObjectLevelLockable + { + CRITICAL_SECTION mtx_; + + public: + ObjectLevelLockable() + { + InitializeCriticalSection(&mtx_); + } + + ~ObjectLevelLockable() + { + DeleteCriticalSection(&mtx_); + } + + template + class Lock + { + ObjectLevelLockable& host_; + + Lock(const Lock&); + Lock& operator=(const Lock&); + public: + Lock(Host& host) : host_(host) + { + ::EnterCriticalSection(&host_.mtx_); + } + ~Lock() + { + ::LeaveCriticalSection(&host_.mtx_); + } + }; + + template + struct VolatileType + { + typedef volatile Host Result; + }; + + typedef LONG IntType; + + static IntType AtomicIncrement(volatile IntType& lval) + { return InterlockedIncrement(&const_cast(lval)); } + + static IntType AtomicDecrement(volatile IntType& lval) + { return InterlockedDecrement(&const_cast(lval)); } + + static void AtomicAssign(volatile IntType& lval, IntType val) + { InterlockedExchange(&const_cast(lval), val); } + + static void AtomicAssign(IntType& lval, volatile IntType& val) + { InterlockedExchange(&lval, val); } + }; + + class ClassLevelLockable + { + struct Initializer; + friend struct Initializer; + struct Initializer + { + Initializer() + { + InitializeCriticalSection(&mtx_); + } + ~Initializer() + { + DeleteCriticalSection(&mtx_); + } + }; + + static Initializer initializer_; + + public: + static CRITICAL_SECTION mtx_; + + template + class Lock + { + Lock(const Lock&); + Lock& operator=(const Lock&); + public: + Lock() + { + EnterCriticalSection(&mtx_); + } + Lock(Host&) + { + EnterCriticalSection(&mtx_); + } + ~Lock() + { + LeaveCriticalSection(&mtx_); + } + }; + + template + struct VolatileType + { + typedef Host Result; + }; + + typedef LONG IntType; + + static IntType AtomicIncrement(volatile IntType& lval) + { return InterlockedIncrement(&const_cast(lval)); } + + static IntType AtomicDecrement(volatile IntType& lval) + { return InterlockedDecrement(&const_cast(lval)); } + + static void AtomicAssign(volatile IntType& lval, IntType val) + { InterlockedExchange(&const_cast(lval), val); } + + static void AtomicAssign(IntType& lval, volatile IntType& val) + { InterlockedExchange(&lval, val); } + }; + + CRITICAL_SECTION ClassLevelLockable::mtx_; + + ClassLevelLockable::Initializer ClassLevelLockable::initializer_; + +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +// 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 +// August 14, 2002: Changed some AtomicDivide's to AtomicDecrement's MKH +// October 12, 2002: Ported to MSVC 6 by Terje Slettebų. +// SingleThreaded, ObjectLevelLockable and ClassLevelLockable changed from +// templates to classes with member templates, to be usable as policies in +// the other ported components. +//////////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/MSVC/1200/TypeInfo.h b/MSVC/1200/TypeInfo.h new file mode 100644 index 0000000..f9ed1a5 --- /dev/null +++ b/MSVC/1200/TypeInfo.h @@ -0,0 +1,106 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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: June 20, 2001 + +#ifndef TYPEINFO_INC_ +#define TYPEINFO_INC_ + +#include +#include +#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!!! +//////////////////////////////////////////////////////////////////////////////// + +#endif // TYPEINFO_INC_ diff --git a/MSVC/1200/TypeList.h b/MSVC/1200/TypeList.h index 040ce98..abe6a41 100644 --- a/MSVC/1200/TypeList.h +++ b/MSVC/1200/TypeList.h @@ -786,4 +786,3 @@ public: //////////////////////////////////////////////////////////////////////////////// #endif // TYPELIST_INC_ - diff --git a/MSVC/1200/TypeManip.h b/MSVC/1200/TypeManip.h index 2392d94..ab12100 100644 --- a/MSVC/1200/TypeManip.h +++ b/MSVC/1200/TypeManip.h @@ -232,7 +232,39 @@ public: enum { sameType = Chooser::sameType }; }; -} // namespace Loki +//////////////////////////////////////////////////////////////////////////////// +// class template SuperSubclass +// Invocation: SuperSubclass::value where B and D are types. +// Returns true if B is a public base of D, or if B and D are aliases of the +// same type. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +//////////////////////////////////////////////////////////////////////////////// + +template +struct SuperSubclass +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType) }; +}; + +//////////////////////////////////////////////////////////////////////////////// +// class template SuperSubclassStrict +// Invocation: SuperSubclassStrict::value where B and D are types. +// Returns true if B is a public base of D. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +//////////////////////////////////////////////////////////////////////////////// + +template +struct SuperSubclassStrict +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType && + !::Loki::Conversion::sameType) }; +}; + +} // namespace Loki //////////////////////////////////////////////////////////////////////////////// // macro SUPERSUBCLASS @@ -241,28 +273,30 @@ public: // same type. // // Caveat: might not work if T and U are in a private inheritance hierarchy. +// Deprecated: Use SuperSubclass class template instead. //////////////////////////////////////////////////////////////////////////////// #define SUPERSUBCLASS(T, U) \ - (::Loki::Conversion::exists && \ - !::Loki::Conversion::sameType) + ::Loki::SuperSubclass::value //////////////////////////////////////////////////////////////////////////////// -// macro SUPERSUBCLASS +// macro SUPERSUBCLASS_STRICT // Invocation: SUPERSUBCLASS(B, D) where B and D are types. // Returns true if B is a public base of D. // // Caveat: might not work if T and U are in a private inheritance hierarchy. +// Deprecated: Use SuperSubclassStrict class template instead. //////////////////////////////////////////////////////////////////////////////// #define SUPERSUBCLASS_STRICT(T, U) \ - (SUPERSUBCLASS(T, U) && \ - !::Loki::Conversion::sameType) + ::Loki::SuperSubclassStrict::value //////////////////////////////////////////////////////////////////////////////// // Change log: -// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! -// August 22, 2001: ported by Jonathan H Lundquist to MSVC +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +// August 22, 2001: ported by Jonathan H Lundquist to MSVC +// October 12, 2002: Added SuperSubclass and SuperSubclassStrict templates. +// The corresponding macros are deprecated. T.S. //////////////////////////////////////////////////////////////////////////////// #endif // TYPEMANIP_INC_ diff --git a/MSVC/1200/portby.txt b/MSVC/1200/portby.txt deleted file mode 100644 index 6836ad7..0000000 --- a/MSVC/1200/portby.txt +++ /dev/null @@ -1,2 +0,0 @@ -MSVC6 -Jonathan H. Lundquist \ No newline at end of file diff --git a/MSVC/1300/TypeManip.h b/MSVC/1300/TypeManip.h index 873dafa..cf94ee1 100644 --- a/MSVC/1300/TypeManip.h +++ b/MSVC/1300/TypeManip.h @@ -175,15 +175,6 @@ namespace Loki enum { sameType = (SameType::value) }; }; -//////////////////////////////////////////////////////////////////////////////// -// macro SUPERSUBCLASS -// Invocation: SUPERSUBCLASS(B, D) where B and D are types. -// Returns true if B is a public base of D, or if B and D are aliases of the -// same type. -// -// Caveat: might not work if T and U are in a private inheritance hierarchy. -//////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////// // class template SuperSubclass // Invocation: SuperSubclass::value where B and D are types. @@ -216,30 +207,40 @@ struct SuperSubclassStrict !::Loki::Conversion::sameType) }; }; -#define SUPERSUBCLASS(T, U) \ - (::Loki::Conversion::exists && \ - !::Loki::Conversion::sameType) +} // namespace Loki //////////////////////////////////////////////////////////////////////////////// // macro SUPERSUBCLASS // Invocation: SUPERSUBCLASS(B, D) where B and D are types. +// Returns true if B is a public base of D, or if B and D are aliases of the +// same type. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +// Deprecated: Use SuperSubclass class template instead. +//////////////////////////////////////////////////////////////////////////////// + +#define SUPERSUBCLASS(T, U) \ + ::Loki::SuperSubclass::value + +//////////////////////////////////////////////////////////////////////////////// +// macro SUPERSUBCLASS_STRICT +// Invocation: SUPERSUBCLASS(B, D) where B and D are types. // Returns true if B is a public base of D. // // Caveat: might not work if T and U are in a private inheritance hierarchy. +// Deprecated: Use SuperSubclassStrict class template instead. //////////////////////////////////////////////////////////////////////////////// #define SUPERSUBCLASS_STRICT(T, U) \ - (SUPERSUBCLASS(T, U) && \ - !::Loki::Conversion::sameType) - -} // namespace Loki + ::Loki::SuperSubclassStrict::value //////////////////////////////////////////////////////////////////////////////// // Change log: -// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! -// May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466) -// Oct 10, 2002: Commented SameType template (not a loki-template - yet) +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +// May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466) +// October 10, 2002: Commented SameType template (not a Loki-template - yet). MKH +// October 12, 2002: Added SuperSubclass and SuperSubclassStrict templates. +// The corresponding macros are deprecated. T.S. //////////////////////////////////////////////////////////////////////////////// #endif // TYPEMANIP_INC_ - diff --git a/tools/RegressionTest/AbstractFactoryTest.h b/tools/RegressionTest/AbstractFactoryTest.h index 1be1f65..4fae51a 100644 --- a/tools/RegressionTest/AbstractFactoryTest.h +++ b/tools/RegressionTest/AbstractFactoryTest.h @@ -38,49 +38,49 @@ class BadSuperMonster : public SuperMonster {}; typedef Loki::AbstractFactory AbstractEnemyFactory; typedef Loki::ConcreteFactory EasyLevelEnemyFactory; + TYPELIST_3(SillySoldier, SillyMonster, SillySuperMonster)> EasyLevelEnemyFactory; typedef Loki::ConcreteFactory HardLevelEnemyFactory; + TYPELIST_3(BadSoldier, BadMonster, BadSuperMonster)> HardLevelEnemyFactory; class AbstractFactoryTest : public Test { public: - AbstractFactoryTest() : Test("AbstractFactory.h") {} + AbstractFactoryTest() : Test("AbstractFactory.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - bool r; + bool r; - std::auto_ptr easyFactory(new EasyLevelEnemyFactory); - std::auto_ptr hardFactory(new HardLevelEnemyFactory); + std::auto_ptr easyFactory(new EasyLevelEnemyFactory); + std::auto_ptr hardFactory(new HardLevelEnemyFactory); - Soldier *s; + Soldier *s; - s = easyFactory->Create(); - - r= !!(typeid(*s)==typeid(SillySoldier)); //SGB !! eliminates bool-to-int performance warning + s = easyFactory->Create(); + + r= !!(typeid(*s)==typeid(SillySoldier)); //SGB !! eliminates bool-to-int performance warning - delete s; + delete s; #ifndef __BORLANDC__ - s = hardFactory->Create(); //BCB bug!!! - always creates SillySoldier + s = hardFactory->Create(); //BCB bug!!! - always creates SillySoldier - r=r && typeid(*s)==typeid(BadSoldier); + r=r && typeid(*s)==typeid(BadSoldier); - delete s; + delete s; #endif - testAssert("AbstractFactory",r,result); + testAssert("AbstractFactory",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } } abstractFactoryTest; #endif diff --git a/tools/RegressionTest/AssocVectorTest.h b/tools/RegressionTest/AssocVectorTest.h index a0d6ae6..4b73613 100644 --- a/tools/RegressionTest/AssocVectorTest.h +++ b/tools/RegressionTest/AssocVectorTest.h @@ -20,6 +20,12 @@ #include #include "UnitTest.h" +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) + #define C_Namespace +#else + #define C_Namespace std +#endif + /////////////////////////////////////////////////////////////////////////////// // AssocVectorTest /////////////////////////////////////////////////////////////////////////////// @@ -31,51 +37,57 @@ template class TestAllocator : public std::allocator { public: - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef C_Namespace::size_t size_type; + typedef C_Namespace::ptrdiff_t difference_type; - template - struct rebind { typedef TestAllocator other; }; + template + struct rebind { typedef TestAllocator other; }; - TestAllocator() {} - TestAllocator(const TestAllocator&) {} - template - TestAllocator(const TestAllocator&) {} - ~TestAllocator() {} + TestAllocator() {} + TestAllocator(const TestAllocator&) {} - pointer address(reference x) const { return &x; } - const_pointer address(const_reference x) const { - return x; - } +#if !(defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__)) - pointer allocate(size_type n, const_pointer = 0) { - return static_cast(::operator new(n * sizeof(T))); - } + template + TestAllocator(const TestAllocator&) {} - void deallocate(pointer p, size_type size) { - ::operator delete(p); - } - - size_type max_size() const { - return static_cast(-1) / sizeof(T); - } - - void construct(pointer p, const value_type& x) { - new(p) value_type(x); - } - void destroy(pointer p) { -#ifndef _USE_OLD_RW_STL // ?? failed to compile when RogueWave is enabled !?! - p->~value_type(); #endif - } + + ~TestAllocator() {} + + pointer address(reference x) const { return &x; } + const_pointer address(const_reference x) const { + return x; + } + + pointer allocate(size_type n, const_pointer = 0) { + return static_cast(::operator new(n * sizeof(T))); + } + + void deallocate(pointer p, size_type size) { + ::operator delete(p); + } + + size_type max_size() const { + return static_cast(-1) / sizeof(T); + } + + void construct(pointer p, const value_type& x) { + new(p) value_type(x); + } + void destroy(pointer p) { +#ifndef _USE_OLD_RW_STL // ?? failed to compile when RogueWave is enabled !?! + p->~value_type(); +#endif + } private: - void operator=(const TestAllocator&); + void operator=(const TestAllocator&); }; /////////////////////////////////////////////////////////////////////////////// @@ -85,19 +97,19 @@ private: class AVTestClass { public: - AVTestClass(int value) : value_(value) {} - AVTestClass(const AVTestClass& other) : value_(other.value_) {} - AVTestClass& operator=(const AVTestClass& other) { - value_ = other.value_; - return *this; - } + AVTestClass(int value) : value_(value) {} + AVTestClass(const AVTestClass& other) : value_(other.value_) {} + AVTestClass& operator=(const AVTestClass& other) { + value_ = other.value_; + return *this; + } - int value_; + int value_; }; bool operator<(const AVTestClass& lhs, const AVTestClass& rhs) { - return lhs.value_ < rhs.value_; + return lhs.value_ < rhs.value_; } /////////////////////////////////////////////////////////////////////////////// @@ -105,9 +117,9 @@ bool operator<(const AVTestClass& lhs, const AVTestClass& rhs) /////////////////////////////////////////////////////////////////////////////// struct str_less : public std::binary_function { - bool operator()(const char* x, const char* y) const { - return strcmp(x, y) < 0; - } + bool operator()(const char* x, const char* y) const { + return strcmp(x, y) < 0; + } }; /////////////////////////////////////////////////////////////////////////////// @@ -117,10 +129,10 @@ struct str_less : public std::binary_function { unsigned int_test_count = 0; // to verify usage struct int_less : public std::less { - bool operator()(int x, int y) const { - ++int_test_count; - return x < y; - } + bool operator()(int x, int y) const { + ++int_test_count; + return x < y; + } }; /////////////////////////////////////////////////////////////////////////////// @@ -129,17 +141,17 @@ struct int_less : public std::less template bool is_sorted(const Vect& v) { - if (v.size() < 2) return true; - typename Vect::const_iterator it = v.begin(); - typename Vect::key_type previous = it->first; - ++it; - while (it != v.end()) { - typename Vect::key_type current = it->first; - if (!(Vect::key_compare()(previous, current))) return false; - previous = current; - ++it; - } - return true; + if (v.size() < 2) return true; + typename Vect::const_iterator it = v.begin(); + typename Vect::key_type previous = it->first; + ++it; + while (it != v.end()) { + typename Vect::key_type current = it->first; + if (!(Vect::key_compare()(previous, current))) return false; + previous = current; + ++it; + } + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -154,13 +166,13 @@ typedef Loki::AssocVector test_vect5_t; void check_insert1(test_vect1_t& v) { - std::srand(10); - for (unsigned i = 0; i < 100; ++i) { - int x = std::rand(); - v.insert(std::make_pair(x, x)); - assert(is_sorted(v)); - } - assert(v.size() == 100); + C_Namespace::srand(10); + for (unsigned i = 0; i < 100; ++i) { + int x = C_Namespace::rand(); + v.insert(std::make_pair(x, x)); + assert(is_sorted(v)); + } + assert(v.size() == 100); } /////////////////////////////////////////////////////////////////////////////// @@ -170,11 +182,11 @@ void check_insert1(test_vect1_t& v) template void check_swap(Vect& v1, Vect& v2) { - unsigned size1 = v1.size(); - unsigned size2 = v2.size(); - v1.swap(v2); - assert(v1.size() == size2); - assert(v2.size() == size1); + unsigned size1 = v1.size(); + unsigned size2 = v2.size(); + v1.swap(v2); + assert(v1.size() == size2); + assert(v2.size() == size1); } /////////////////////////////////////////////////////////////////////////////// @@ -183,47 +195,47 @@ void check_swap(Vect& v1, Vect& v2) void test_vect1() { - test_vect1_t vec11; - assert(vec11.size() == 0); + test_vect1_t vec11; + assert(vec11.size() == 0); - check_insert1(vec11); - size_t size1 = vec11.size(); - assert(size1); + check_insert1(vec11); + size_t size1 = vec11.size(); + assert(size1); - test_vect1_t vec12(vec11.begin(), vec11.end()); - assert(vec12.size() == vec11.size()); - assert(vec11.size() == size1); + test_vect1_t vec12(vec11.begin(), vec11.end()); + assert(vec12.size() == vec11.size()); + assert(vec11.size() == size1); - test_vect1_t vec13; - vec13 = vec11; - assert(vec13.size() == vec11.size()); - assert(vec11.size() == size1); + test_vect1_t vec13; + vec13 = vec11; + assert(vec13.size() == vec11.size()); + assert(vec11.size() == size1); - // this doesn't compile on Borland C++ 6.0 !?! - //test_vect1_t vec99(test_vect1_t::key_compare(), TestAllocator()); - //assert(vec99.size() == 0); //- here ir cries + // this doesn't compile on Borland C++ 6.0 !?! + //test_vect1_t vec99(test_vect1_t::key_compare(), TestAllocator()); + //assert(vec99.size() == 0); //- here ir cries - test_vect1_t::key_compare comp = test_vect1_t::key_compare(); - test_vect1_t vec14(comp, TestAllocator()); - assert(vec14.size() == 0); + test_vect1_t::key_compare comp = test_vect1_t::key_compare(); + test_vect1_t vec14(comp, TestAllocator()); + assert(vec14.size() == 0); - check_swap(vec11, vec14); - assert(vec14.size() == size1); - assert(vec11.size() == 0); + check_swap(vec11, vec14); + assert(vec14.size() == size1); + assert(vec11.size() == 0); - // this compiles, unlike object on stack - test_vect1_t* vec15 = new test_vect1_t(test_vect1_t::key_compare(), TestAllocator()); - assert(vec15->size() == 0); - check_insert1(*vec15); - delete vec15; + // this compiles, unlike object on stack + test_vect1_t* vec15 = new test_vect1_t(test_vect1_t::key_compare(), TestAllocator()); + assert(vec15->size() == 0); + check_insert1(*vec15); + delete vec15; - // different comparator test - doesn't work for Loki - //comp = int_less(); - //test_vect1_t vec16(comp); - //assert(vec16.size() == 0); - //assert(int_test_count == 0); - //check_insert1(vec16); - //assert(int_test_count != 0); + // different comparator test - doesn't work for Loki + //comp = int_less(); + //test_vect1_t vec16(comp); + //assert(vec16.size() == 0); + //assert(int_test_count == 0); + //check_insert1(vec16); + //assert(int_test_count != 0); } /////////////////////////////////////////////////////////////////////////////// @@ -232,32 +244,32 @@ void test_vect1() void test_vect2() { - test_vect2_t vec21; - vec21.insert(std::make_pair("abc", 1)); - vec21.insert(std::make_pair("xyz", 3)); - vec21.insert(std::make_pair("def", 2)); - assert(vec21.size() == 3); - assert(is_sorted(vec21)); + test_vect2_t vec21; + vec21.insert(std::make_pair("abc", 1)); + vec21.insert(std::make_pair("xyz", 3)); + vec21.insert(std::make_pair("def", 2)); + assert(vec21.size() == 3); + assert(is_sorted(vec21)); - test_vect2_t::iterator it = vec21.find("xyz"); - assert(it != vec21.end()); - assert(it->second == 3); + test_vect2_t::iterator it = vec21.find("xyz"); + assert(it != vec21.end()); + assert(it->second == 3); - std::pair aux = vec21.insert(std::make_pair("xyz", 99)); - assert(aux.first); //TODOSGB was second meant, not first? MSVC7 dies here (more errors follow) - it = vec21.find("xyz"); - assert(it->second == 3); + std::pair aux = vec21.insert(std::make_pair("xyz", 99)); + assert(aux.first); //TODOSGB was second meant, not first? MSVC7 dies here (more errors follow) + it = vec21.find("xyz"); + assert(it->second == 3); - vec21.erase(it); - assert(vec21.size() == 2); - it = vec21.find("xyz"); - assert(it == vec21.end()); - vec21.erase("xyz"); - vec21.erase("abc"); - assert(vec21.size() == 1); + vec21.erase(it); + assert(vec21.size() == 2); + it = vec21.find("xyz"); + assert(it == vec21.end()); + vec21.erase("xyz"); + vec21.erase("abc"); + assert(vec21.size() == 1); - vec21.clear(); - assert(vec21.size() == 0); + vec21.clear(); + assert(vec21.size() == 0); } /////////////////////////////////////////////////////////////////////////////// @@ -266,20 +278,20 @@ void test_vect2() void test_vect3() { - // To use string, you need: - // 1) enable _STLP_USE_NEWALLOC in include\stl\_site_config.h - // 2) either disable use of any dynamic RTL (menu Project | Options | Linker) - // 3) or recompile STLPort DLL. - // This all is related to bug in STLPort allocator. - test_vect3_t vec31; - std::srand(111); - // a stress test - for (unsigned i = 0; i < 2 * 1000; ++i) { - char buffer[16]; - std::sprintf(buffer, "string%d", std::rand()); - std::string s(buffer); - vec31.insert(std::make_pair(s, s)); - } + // To use string, you need: + // 1) enable _STLP_USE_NEWALLOC in include\stl\_site_config.h + // 2) either disable use of any dynamic RTL (menu Project | Options | Linker) + // 3) or recompile STLPort DLL. + // This all is related to bug in STLPort allocator. + test_vect3_t vec31; + C_Namespace::srand(111); + // a stress test + for (unsigned i = 0; i < 2 * 1000; ++i) { + char buffer[16]; + C_Namespace::sprintf(buffer, "string%d", C_Namespace::rand()); + std::string s(buffer); + vec31.insert(std::make_pair(s, s)); + } } /////////////////////////////////////////////////////////////////////////////// @@ -288,27 +300,27 @@ void test_vect3() void test_vect4() { - test_vect4_t vec41; - for (int i = 0; i < 100; ++i) { - vec41.insert(std::make_pair(AVTestClass(i), AVTestClass(i))); - } - assert(vec41.size() == 100); + test_vect4_t vec41; + for (int i = 0; i < 100; ++i) { + vec41.insert(std::make_pair(AVTestClass(i), AVTestClass(i))); + } + assert(vec41.size() == 100); - vec41.insert(std::make_pair(AVTestClass(300), AVTestClass(300))); - vec41.insert(std::make_pair(AVTestClass(200), AVTestClass(200))); - assert(vec41.size() == 102); + vec41.insert(std::make_pair(AVTestClass(300), AVTestClass(300))); + vec41.insert(std::make_pair(AVTestClass(200), AVTestClass(200))); + assert(vec41.size() == 102); - test_vect4_t::iterator it = vec41.find(AVTestClass(22)); - assert(it != vec41.end()); - assert(it->second.value_ == 22); + test_vect4_t::iterator it = vec41.find(AVTestClass(22)); + assert(it != vec41.end()); + assert(it->second.value_ == 22); - test_vect4_t vec42; - vec42.swap(vec41); - assert(vec41.size() == 0); - assert(vec42.size() == 102); + test_vect4_t vec42; + vec42.swap(vec41); + assert(vec41.size() == 0); + assert(vec42.size() == 102); - vec42.erase(vec42.begin(), vec42.end()); - assert(vec42.size() == 0); + vec42.erase(vec42.begin(), vec42.end()); + assert(vec42.size() == 0); } /////////////////////////////////////////////////////////////////////////////// @@ -317,42 +329,42 @@ void test_vect4() void test_vect5() { - test_vect5_t vec51; - vec51.insert(test_vect5_t::value_type(3, "XXX")); - vec51.insert(std::make_pair(1, "X")); - vec51.insert(std::make_pair(2, "XX")); + test_vect5_t vec51; + vec51.insert(test_vect5_t::value_type(3, "XXX")); + vec51.insert(std::make_pair(1, "X")); + vec51.insert(std::make_pair(2, "XX")); - test_vect5_t::const_iterator it = vec51.begin(); - int count=1; + test_vect5_t::const_iterator it = vec51.begin(); + int count=1; - while (it != vec51.end()) { - assert(std::string(it->second).length()==count); + while (it != vec51.end()) { + assert(std::string(it->second).length()==count); - ++count; + ++count; - it++; // intentionally - } + it++; // intentionally + } } class AssocVectorTest : public Test { public: - AssocVectorTest() : Test("AssocVector.h") {} + AssocVectorTest() : Test("AssocVector.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - test_vect1(); - test_vect2(); - test_vect3(); - test_vect4(); - test_vect5(); + test_vect1(); + test_vect2(); + test_vect3(); + test_vect4(); + test_vect5(); - testAssert("AssocVector",true,result), + testAssert("AssocVector",true,result), - std::cout << '\n'; - } + std::cout << '\n'; + } } assocVectorTest; #endif diff --git a/tools/RegressionTest/DataGeneratorsTest.h b/tools/RegressionTest/DataGeneratorsTest.h index 57cee7b..5e7dd4c 100644 --- a/tools/RegressionTest/DataGeneratorsTest.h +++ b/tools/RegressionTest/DataGeneratorsTest.h @@ -8,55 +8,55 @@ #include struct DataGeneratorsTest : public Test - { - DataGeneratorsTest() : Test("DataGeneratorsTest.h") - {} - virtual void execute(TestResult& result) - { - this->printName(result); - - using namespace Loki; - using namespace Loki::TL; - - bool b; - typedef MakeTypelist<>::Result null_tl; - typedef MakeTypelist::Result char_types; - int n = Length::value; - - std::vector names; - names.reserve(n); - //Some fascist decided that all temporaries should be const. - //The following line of code stupidity is a direct result of the half-baked idea - iterate_types(std::back_inserter(names)); - b = names.size() == n; - testAssert("iterate_types - Check Length", b, result); - - std::vector sizes; - sizes.reserve(n); - typedef MakeTypelist::Result some_types; - iterate_types(std::back_inserter(sizes)); - size_t apriori_size[] = {sizeof(char), sizeof(short), sizeof(int), sizeof(double)}; - b = true; - for(int i=0; i(sizes); - b = sizes.size() == 0; - testAssert("iterate_types - Degenerate Case 1 - Null List", b, result); + { + DataGeneratorsTest() : Test("DataGeneratorsTest.h") + {} + virtual void execute(TestResult& result) + { + this->printName(result); + + using namespace Loki; + using namespace Loki::TL; + + bool b; + typedef MakeTypelist<>::Result null_tl; + typedef MakeTypelist::Result char_types; + int n = Length::value; + + std::vector names; + names.reserve(n); + //Some fascist decided that all temporaries should be const. + //The following line of code stupidity is a direct result of the half-baked idea + iterate_types(std::back_inserter(names)); + b = names.size() == n; + testAssert("iterate_types - Check Length", b, result); + + std::vector sizes; + sizes.reserve(n); + typedef MakeTypelist::Result some_types; + iterate_types(std::back_inserter(sizes)); + size_t apriori_size[] = {sizeof(char), sizeof(short), sizeof(int), sizeof(double)}; + b = true; + for(int i=0; i(sizes); + b = sizes.size() == 0; + testAssert("iterate_types - Degenerate Case 1 - Null List", b, result); - sizes.resize(0); - iterate_types(sizes); - b = sizes.size() == 0; - testAssert("iterate_types - Degenerate Case 2 - NullType", b, result); - } - } datageneratorsTest; + sizes.resize(0); + iterate_types(sizes); + b = sizes.size() == 0; + testAssert("iterate_types - Degenerate Case 2 - NullType", b, result); + } + } datageneratorsTest; #endif //DATAGENERATORSTEST_H diff --git a/tools/RegressionTest/FactoryTest.h b/tools/RegressionTest/FactoryTest.h index 8343693..5e3d804 100644 --- a/tools/RegressionTest/FactoryTest.h +++ b/tools/RegressionTest/FactoryTest.h @@ -23,124 +23,124 @@ namespace FactoryTestPrivate { - class Shape - { - public: - virtual ~Shape() = 0; - }; + class Shape + { + public: + virtual ~Shape() = 0; + }; - inline Shape::~Shape() {} + inline Shape::~Shape() {} - class Polygon : public Shape - { - }; + class Polygon : public Shape + { + }; - class Line : public Shape - { - }; + class Line : public Shape + { + }; - class Circle : public Shape - { - }; + class Circle : public Shape + { + }; - Polygon *createPolygon() { return new Polygon; } - Line *createLine() { return new Line; } - Circle *createCircle() { return new Circle; } + Polygon *createPolygon() { return new Polygon; } + Line *createLine() { return new Line; } + Circle *createCircle() { return new Circle; } - Polygon *clonePolygon(Polygon *) { return new Polygon; } - Line *cloneLine(Line *) { return new Line; } - Circle *cloneCircle(Circle *) { return new Circle; } + Polygon *clonePolygon(Polygon *) { return new Polygon; } + Line *cloneLine(Line *) { return new Line; } + Circle *cloneCircle(Circle *) { return new Circle; } - typedef Loki::Factory FactoryType; + typedef Loki::Factory FactoryType; - bool testFactory() - { - FactoryType factory; + bool testFactory() + { + FactoryType factory; - factory.Register(1, (Shape * (*)()) createPolygon); - factory.Register(2, (Shape * (*)()) createCircle); - factory.Register(3, (Shape * (*)()) createLine); + factory.Register(1, (Shape * (*)()) createPolygon); + factory.Register(2, (Shape * (*)()) createCircle); + factory.Register(3, (Shape * (*)()) createLine); - Shape *s; + Shape *s; - s = factory.CreateObject(1); - delete s; - bool test1=s!=NULL; + s = factory.CreateObject(1); + delete s; + bool test1=s!=NULL; - s = factory.CreateObject(2); - delete s; - bool test2=s!=NULL; + s = factory.CreateObject(2); + delete s; + bool test2=s!=NULL; - s = factory.CreateObject(3); - delete s; - bool test3=s!=NULL; + s = factory.CreateObject(3); + delete s; + bool test3=s!=NULL; - bool test4=true; + bool test4=true; -// try -// { -// factory.CreateObject(4); +// try +// { +// factory.CreateObject(4); // -// test4=false; -// } -// catch (std::exception&) -// { -// } +// test4=false; +// } +// catch (std::exception&) +// { +// } - return test1 && test2 && test3 && test4; - } + return test1 && test2 && test3 && test4; + } - typedef Loki::CloneFactory CloneFactoryType; + typedef Loki::CloneFactory CloneFactoryType; - bool testCloneFactory() - { - CloneFactoryType factory; + bool testCloneFactory() + { + CloneFactoryType factory; - factory.Register(Loki::TypeInfo(typeid(Polygon)), (Shape * (*)(const Shape *)) clonePolygon); - factory.Register(Loki::TypeInfo(typeid(Circle)), (Shape * (*)(const Shape *)) cloneCircle); - factory.Register(Loki::TypeInfo(typeid(Line)), (Shape * (*)(const Shape *)) cloneLine); + factory.Register(Loki::TypeInfo(typeid(Polygon)), (Shape * (*)(const Shape *)) clonePolygon); + factory.Register(Loki::TypeInfo(typeid(Circle)), (Shape * (*)(const Shape *)) cloneCircle); + factory.Register(Loki::TypeInfo(typeid(Line)), (Shape * (*)(const Shape *)) cloneLine); - Polygon p; - Circle c; - Line l; + Polygon p; + Circle c; + Line l; - Shape *s; + Shape *s; - s = factory.CreateObject(&p); - delete s; - bool test1=s!=NULL; + s = factory.CreateObject(&p); + delete s; + bool test1=s!=NULL; - s = factory.CreateObject(&c); - delete s; - bool test2=s!=NULL; + s = factory.CreateObject(&c); + delete s; + bool test2=s!=NULL; - s = factory.CreateObject(&l); - delete s; - bool test3=s!=NULL; + s = factory.CreateObject(&l); + delete s; + bool test3=s!=NULL; - return test1 && test2 && test3; - } + return test1 && test2 && test3; + } } class FactoryTest : public Test { public: - FactoryTest() : Test("Factory.h") {} + FactoryTest() : Test("Factory.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - bool test1=FactoryTestPrivate::testFactory(); + bool test1=FactoryTestPrivate::testFactory(); - bool test2=FactoryTestPrivate::testCloneFactory(); + bool test2=FactoryTestPrivate::testCloneFactory(); - bool r=test1 && test2; + bool r=test1 && test2; - testAssert("Factory",r,result); + testAssert("Factory",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } } factoryTest; #endif diff --git a/tools/RegressionTest/FunctorTest.h b/tools/RegressionTest/FunctorTest.h index 3a4397c..720d890 100644 --- a/tools/RegressionTest/FunctorTest.h +++ b/tools/RegressionTest/FunctorTest.h @@ -24,89 +24,89 @@ class FunctorTest : public Test { public: - FunctorTest() : Test("Functor.h") {} + FunctorTest() : Test("Functor.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - bool r; + bool r; - TestFunctor testFunctor; - TestClass testClass; + TestFunctor testFunctor; + TestClass testClass; - Functor function(testFunction); - Functor functor(testFunctor); - Functor classFunctor(&testClass,&TestClass::member); - Functor functorCopy(function); - Functor bindFunctor(BindFirst(function,testResult)); - Functor chainFunctor(Chain(bindFunctor,bindFunctor)); + Functor function(testFunction); + Functor functor(testFunctor); + Functor classFunctor(&testClass,&TestClass::member); + Functor functorCopy(function); + Functor bindFunctor(BindFirst(function,testResult)); + Functor chainFunctor(Chain(bindFunctor,bindFunctor)); - testResult=false; - function(testResult); - bool functionResult=testResult; + testResult=false; + function(testResult); + bool functionResult=testResult; - testResult=false; - functor(testResult); - bool functorResult=testResult; + testResult=false; + functor(testResult); + bool functorResult=testResult; - testResult=false; - classFunctor(testResult); - bool classFunctorResult=testResult; + testResult=false; + classFunctor(testResult); + bool classFunctorResult=testResult; - testResult=false; - functorCopy(testResult); - bool functorCopyResult=testResult; + testResult=false; + functorCopy(testResult); + bool functorCopyResult=testResult; - testResult=false; - bindFunctor(); - bool bindFunctorResult=testResult; + testResult=false; + bindFunctor(); + bool bindFunctorResult=testResult; - testResult=false; - chainFunctor(); - bool chainFunctorResult=testResult; + testResult=false; + chainFunctor(); + bool chainFunctorResult=testResult; - r=functionResult && functorResult && classFunctorResult && functorCopyResult && bindFunctorResult && - chainFunctorResult; + r=functionResult && functorResult && classFunctorResult && functorCopyResult && bindFunctorResult && + chainFunctorResult; - testAssert("Functor",r,result); + testAssert("Functor",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } private: - static bool testResult; + static bool testResult; - static void testFunction(bool &result) - { - result=true; - } + static void testFunction(bool &result) + { + result=true; + } - class TestFunctor - { - public: - void operator()(bool &result) - { - result=true; - } - }; + class TestFunctor + { + public: + void operator()(bool &result) + { + result=true; + } + }; - class TestClass - { - public: - void member(bool &result) - { - result=true; - } - }; + class TestClass + { + public: + void member(bool &result) + { + result=true; + } + }; } functorTest; bool FunctorTest::testResult; #ifndef SMALLOBJ_CPP -# define SMALLOBJ_CPP -# include "../../SmallObj.cpp" +# define SMALLOBJ_CPP +# include "../../SmallObj.cpp" #endif #endif diff --git a/tools/RegressionTest/LokiTest.h b/tools/RegressionTest/LokiTest.h deleted file mode 100644 index 7b7bb91..0000000 --- a/tools/RegressionTest/LokiTest.h +++ /dev/null @@ -1,80 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// 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 LOKITEST_H -#define LOKITEST_H - -#include "TypelistTest.h" -//#include "TypeManipTest.h" -//#include "TypeTraitsTest.h" -//#include "SmallObjectTest.h" -//#include "SingletonTest.h" -//#include "SmartPtrTest.h" -//#include "FactoryTest.h" -//#include "AbstractFactoryTest.h" -//#include "AssocVectorTest.h" -//#include "FunctorTest.h" -#include "DataGeneratorsTest.h" - -/////////////////////////////////////////////////////////////////////////////// -// LokiTest -/////////////////////////////////////////////////////////////////////////////// - -class LokiTest -{ -public: - LokiTest() - { - addTests(); - } - - int result() - { - return unitTest.run("Unit Test",tests); - } - -private: - void addTests() - { - tests.add(typelistTest); -// tests.add(typeManipTest); -// tests.add(typeTraitsTest); -// tests.add(smallObjectTest); -// tests.add(singletonTest); -// tests.add(smartPtrTest); -// tests.add(factoryTest); -// tests.add(abstractFactoryTest); -// tests.add(assocVectorTest); -// tests.add(functorTest); - tests.add(datageneratorTest); - } - -private: - UnitTest unitTest; - TestSuite tests; - - TypelistTest typelistTest; -// TypeManipTest typeManipTest; -// TypeTraitsTest typeTraitsTest; -// SmallObjectTest smallObjectTest; -// SingletonTest singletonTest; -// SmartPtrTest smartPtrTest; -// FactoryTest factoryTest; -// AbstractFactoryTest abstractFactoryTest; -// AssocVectorTest assocVectorTest; -// FunctorTest functorTest; - DataGeneratorsTest datageneratorTest; -}; - -#endif diff --git a/tools/RegressionTest/SingletonTest.h b/tools/RegressionTest/SingletonTest.h index b60d718..e4d2b24 100644 --- a/tools/RegressionTest/SingletonTest.h +++ b/tools/RegressionTest/SingletonTest.h @@ -20,11 +20,11 @@ #include "UnitTest.h" #define MAKE_TEST(name)\ - if(singletonTest && name::Instance().a != 99)\ - singletonTest=false;\ - ++name::Instance().a;\ - if(singletonTest && name::Instance().a != 100)\ - singletonTest=false; + if(singletonTest && name::Instance().a != 99)\ + singletonTest=false;\ + ++name::Instance().a;\ + if(singletonTest && name::Instance().a != 100)\ + singletonTest=false; /////////////////////////////////////////////////////////////////////////////// // SingletonTest @@ -34,18 +34,18 @@ template class MyClass { public: - MyClass() : a(99), wasDestroyed(false) {} + MyClass() : a(99), wasDestroyed(false) {} - virtual ~MyClass() - { - assert(!wasDestroyed); + virtual ~MyClass() + { + assert(!wasDestroyed); - wasDestroyed = true; - } + wasDestroyed = true; + } public: - int a; - bool wasDestroyed; + int a; + bool wasDestroyed; }; inline unsigned GetLongevity(MyClass<3> *) { return 6; } @@ -57,41 +57,41 @@ inline unsigned GetLongevity(MyClass<23> *) { return 3; } namespace { - using namespace Loki; + using namespace Loki; - typedef SingletonHolder > t0; + typedef SingletonHolder > t0; - typedef SingletonHolder, CreateUsingNew, DefaultLifetime, SingleThreaded> t1; - typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, SingleThreaded> t2; - typedef SingletonHolder, CreateUsingNew, SingletonWithLongevity, SingleThreaded> t3; - typedef SingletonHolder, CreateUsingNew, NoDestroy, SingleThreaded> t4; + typedef SingletonHolder, CreateUsingNew, DefaultLifetime, SingleThreaded> t1; + typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, SingleThreaded> t2; + typedef SingletonHolder, CreateUsingNew, SingletonWithLongevity, SingleThreaded> t3; + typedef SingletonHolder, CreateUsingNew, NoDestroy, SingleThreaded> t4; - typedef SingletonHolder, CreateUsingMalloc, DefaultLifetime, SingleThreaded> t9; - typedef SingletonHolder, CreateUsingMalloc, PhoenixSingleton, SingleThreaded> t10; - typedef SingletonHolder, CreateUsingMalloc, SingletonWithLongevity, SingleThreaded> t11; - typedef SingletonHolder, CreateUsingMalloc, NoDestroy, SingleThreaded> t12; + typedef SingletonHolder, CreateUsingMalloc, DefaultLifetime, SingleThreaded> t9; + typedef SingletonHolder, CreateUsingMalloc, PhoenixSingleton, SingleThreaded> t10; + typedef SingletonHolder, CreateUsingMalloc, SingletonWithLongevity, SingleThreaded> t11; + typedef SingletonHolder, CreateUsingMalloc, NoDestroy, SingleThreaded> t12; - typedef SingletonHolder, CreateStatic, DefaultLifetime, SingleThreaded> t17; - typedef SingletonHolder, CreateStatic, PhoenixSingleton, SingleThreaded> t18; - typedef SingletonHolder, CreateStatic, SingletonWithLongevity, SingleThreaded> t19; - typedef SingletonHolder, CreateStatic, NoDestroy, SingleThreaded> t20; + typedef SingletonHolder, CreateStatic, DefaultLifetime, SingleThreaded> t17; + typedef SingletonHolder, CreateStatic, PhoenixSingleton, SingleThreaded> t18; + typedef SingletonHolder, CreateStatic, SingletonWithLongevity, SingleThreaded> t19; + typedef SingletonHolder, CreateStatic, NoDestroy, SingleThreaded> t20; -#if !__INTEL_COMPILER && !__GNUC__ && !_MSC_VER +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) - typedef SingletonHolder, CreateUsingNew, DefaultLifetime, ClassLevelLockable> t5; - typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, ClassLevelLockable> t6; - typedef SingletonHolder, CreateUsingNew, SingletonWithLongevity, ClassLevelLockable> t7; - typedef SingletonHolder, CreateUsingNew, NoDestroy, ClassLevelLockable> t8; + typedef SingletonHolder, CreateUsingNew, DefaultLifetime, ClassLevelLockable> t5; + typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, ClassLevelLockable> t6; + typedef SingletonHolder, CreateUsingNew, SingletonWithLongevity, ClassLevelLockable> t7; + typedef SingletonHolder, CreateUsingNew, NoDestroy, ClassLevelLockable> t8; - typedef SingletonHolder, CreateUsingMalloc, DefaultLifetime, ClassLevelLockable> t13; - typedef SingletonHolder, CreateUsingMalloc, PhoenixSingleton, ClassLevelLockable> t14; - typedef SingletonHolder, CreateUsingMalloc, SingletonWithLongevity, ClassLevelLockable> t15; - typedef SingletonHolder, CreateUsingMalloc, NoDestroy, ClassLevelLockable> t16; + typedef SingletonHolder, CreateUsingMalloc, DefaultLifetime, ClassLevelLockable> t13; + typedef SingletonHolder, CreateUsingMalloc, PhoenixSingleton, ClassLevelLockable> t14; + typedef SingletonHolder, CreateUsingMalloc, SingletonWithLongevity, ClassLevelLockable> t15; + typedef SingletonHolder, CreateUsingMalloc, NoDestroy, ClassLevelLockable> t16; - typedef SingletonHolder, CreateStatic, DefaultLifetime, ClassLevelLockable> t21; - typedef SingletonHolder, CreateStatic, PhoenixSingleton, ClassLevelLockable> t22; - typedef SingletonHolder, CreateStatic, SingletonWithLongevity, ClassLevelLockable> t23; - typedef SingletonHolder, CreateStatic, NoDestroy, ClassLevelLockable> t24; + typedef SingletonHolder, CreateStatic, DefaultLifetime, ClassLevelLockable> t21; + typedef SingletonHolder, CreateStatic, PhoenixSingleton, ClassLevelLockable> t22; + typedef SingletonHolder, CreateStatic, SingletonWithLongevity, ClassLevelLockable> t23; + typedef SingletonHolder, CreateStatic, NoDestroy, ClassLevelLockable> t24; #endif } @@ -99,59 +99,59 @@ namespace class SingletonTest : public Test { public: - SingletonTest() : Test("Singleton.h") {} + SingletonTest() : Test("Singleton.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - singletonTest=true; + singletonTest=true; - MAKE_TEST(t0) + MAKE_TEST(t0) - MAKE_TEST(t1) - MAKE_TEST(t2) - MAKE_TEST(t3) - MAKE_TEST(t4) + MAKE_TEST(t1) + MAKE_TEST(t2) + MAKE_TEST(t3) + MAKE_TEST(t4) - MAKE_TEST(t9) - MAKE_TEST(t10) - MAKE_TEST(t11) - MAKE_TEST(t12) + MAKE_TEST(t9) + MAKE_TEST(t10) + MAKE_TEST(t11) + MAKE_TEST(t12) - MAKE_TEST(t17) - MAKE_TEST(t18) - MAKE_TEST(t19) - MAKE_TEST(t20) + MAKE_TEST(t17) + MAKE_TEST(t18) + MAKE_TEST(t19) + MAKE_TEST(t20) -#if !__INTEL_COMPILER && !__GNUC__ && !_MSC_VER +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) - MAKE_TEST(t5) - MAKE_TEST(t6) - MAKE_TEST(t7) - MAKE_TEST(t8) + MAKE_TEST(t5) + MAKE_TEST(t6) + MAKE_TEST(t7) + MAKE_TEST(t8) - MAKE_TEST(t13) - MAKE_TEST(t14) - MAKE_TEST(t15) - MAKE_TEST(t16) + MAKE_TEST(t13) + MAKE_TEST(t14) + MAKE_TEST(t15) + MAKE_TEST(t16) - MAKE_TEST(t21) - MAKE_TEST(t22) - MAKE_TEST(t23) - MAKE_TEST(t24) + MAKE_TEST(t21) + MAKE_TEST(t22) + MAKE_TEST(t23) + MAKE_TEST(t24) #endif - testAssert("Singleton",singletonTest,result); + testAssert("Singleton",singletonTest,result); - std::cout << '\n'; - } + std::cout << '\n'; + } private: - bool singletonTest; + bool singletonTest; } singletonTest; #include "../../Singleton.cpp" diff --git a/tools/RegressionTest/SmallObjectTest.h b/tools/RegressionTest/SmallObjectTest.h index 9eec393..abf1a6d 100644 --- a/tools/RegressionTest/SmallObjectTest.h +++ b/tools/RegressionTest/SmallObjectTest.h @@ -26,143 +26,143 @@ class SmallObjectTest : public Test { public: - SmallObjectTest() : Test("SmallObject.h") {} + SmallObjectTest() : Test("SmallObject.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - bool r; + bool r; - SmallClass* a = new SmallClass; - delete a; + SmallClass* a = new SmallClass; + delete a; - bool smallTest1=a!=NULL; + bool smallTest1=a!=NULL; - a = new SmallClass2; - delete a; + a = new SmallClass2; + delete a; - bool smallTest2=a!=NULL; + bool smallTest2=a!=NULL; - BigClass* b = new BigClass; - delete b; + BigClass* b = new BigClass; + delete b; - bool bigTest1=b!=NULL; + bool bigTest1=b!=NULL; - b = new BigClass2; - delete b; + b = new BigClass2; + delete b; - bool bigTest2=b!=NULL; + bool bigTest2=b!=NULL; - char* buff = static_cast(Loki::SmallObject<>::operator new(10)); - Loki::SmallObject<>::operator delete(buff, 10); + char* buff = static_cast(Loki::SmallObject<>::operator new(10)); + Loki::SmallObject<>::operator delete(buff, 10); - bool test=buff!=NULL; + bool test=buff!=NULL; -// stress_test(); +// stress_test(); - r=smallTest1 && smallTest2 && bigTest1 && bigTest2 && test; + r=smallTest1 && smallTest2 && bigTest1 && bigTest2 && test; - testAssert("SmallObject",r,result); + testAssert("SmallObject",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } private: - class SmallClass : public Loki::SmallObject<> - { - int a; - }; + class SmallClass : public Loki::SmallObject<> + { + int a; + }; - class SmallClass2 : public SmallClass - { - int b; - }; + class SmallClass2 : public SmallClass + { + int b; + }; - class BigClass : public Loki::SmallObject<> - { - char a[200]; - }; + class BigClass : public Loki::SmallObject<> + { + char a[200]; + }; - class BigClass2 : public BigClass - { - int b; - }; + class BigClass2 : public BigClass + { + int b; + }; - class Base - { - public: - virtual ~Base() {} - }; + class Base + { + public: + virtual ~Base() {} + }; - class A : public Base, public Loki::SmallObject<> - { - int a[1]; - }; + class A : public Base, public Loki::SmallObject<> + { + int a[1]; + }; - class B : public Base, public Loki::SmallObject<> - { - int a[2]; - }; + class B : public Base, public Loki::SmallObject<> + { + int a[2]; + }; - class C : public Base, public Loki::SmallObject<> - { - int a[3]; - }; + class C : public Base, public Loki::SmallObject<> + { + int a[3]; + }; - class D : public Base, public Loki::SmallObject<> - { - int a[4]; - }; + class D : public Base, public Loki::SmallObject<> + { + int a[4]; + }; - static void stress_test() - { - std::vector vec; + static void stress_test() + { + std::vector vec; - vec.reserve(20 * 1024); + vec.reserve(20 * 1024); - std::srand(1231); + std::srand(1231); - for (int i = 0; i < 10; ++i) - { - for (int j = 0; j < 2 * 1024; ++j) - { - Base* p; + for (int i = 0; i < 10; ++i) + { + for (int j = 0; j < 2 * 1024; ++j) + { + Base* p; - switch (std::rand() % 4) - { - case 0: p = new A; break; - case 1: p = new B; break; - case 2: p = new C; break; - case 3: p = new D; break; - } + switch (std::rand() % 4) + { + case 0: p = new A; break; + case 1: p = new B; break; + case 2: p = new C; break; + case 3: p = new D; break; + } - vec.push_back(p); - } + vec.push_back(p); + } - for (int j = 0; j < 1024; ++j) - { - size_t pos = std::rand() % vec.size(); + for (int j = 0; j < 1024; ++j) + { + size_t pos = std::rand() % vec.size(); - delete vec[pos]; + delete vec[pos]; - vec[pos] = 0; - } - } + vec[pos] = 0; + } + } - while (!vec.empty()) - { - delete vec.back(); + while (!vec.empty()) + { + delete vec.back(); - vec.pop_back(); - } - } + vec.pop_back(); + } + } } smallObjectTest; #ifndef SMALLOBJ_CPP -# define SMALLOBJ_CPP -# include "../../SmallObj.cpp" +# define SMALLOBJ_CPP +# include "../../SmallObj.cpp" #endif #endif diff --git a/tools/RegressionTest/SmartPtrTest.h b/tools/RegressionTest/SmartPtrTest.h index e602bfe..3ad8e98 100644 --- a/tools/RegressionTest/SmartPtrTest.h +++ b/tools/RegressionTest/SmartPtrTest.h @@ -25,33 +25,33 @@ class TestClass { public: - TestClass() : references(1) - { - ++instances; - } + TestClass() : references(1) + { + ++instances; + } - ~TestClass() - { - --instances; - } + ~TestClass() + { + --instances; + } - void AddRef() - { - ++references; - } + void AddRef() + { + ++references; + } - void Release() - { - --references; + void Release() + { + --references; - if (references <= 0) - delete this; - } + if (references <= 0) + delete this; + } public: - static int instances; + static int instances; - int references; + int references; }; int TestClass::instances = 0; @@ -59,232 +59,232 @@ int TestClass::instances = 0; class SmartPtrTest : public Test { public: - SmartPtrTest() : Test("SmartPtr.h") {} + SmartPtrTest() : Test("SmartPtr.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - { SmartPtr p = new TestClass; } + { SmartPtr p = new TestClass; } - bool test1=TestClass::instances == 0; + bool test1=TestClass::instances == 0; - { p0 p = new TestClass(); } - { p1 p = new TestClass(); } -// { p2 p = new TestClass(); } - { p3 p = new TestClass(); } - { p4 p = new TestClass(); } - { p5 p = new TestClass(); } - { p6 p = new TestClass(); } - { p7 p = new TestClass(); } - { p8 p = new TestClass(); } - { p9 p = new TestClass(); } -// { p10 p = new TestClass(); } - { p11 p = new TestClass(); } - { p12 p = new TestClass(); } - { p13 p = new TestClass(); } - { p14 p = new TestClass(); } - { p15 p = new TestClass(); } - { p16 p = new TestClass(); } - { p17 p = new TestClass(); } -// { p18 p = new TestClass(); } - { p19 p = new TestClass(); } - { p20 p = new TestClass(); } - { p21 p = new TestClass(); } - { p22 p = new TestClass(); } - { p23 p = new TestClass(); } - { p24 p = new TestClass(); } - { p25 p = new TestClass(); } -// { p26 p = new TestClass(); } - { p27 p = new TestClass(); } - { p28 p = new TestClass(); } - { p29 p = new TestClass(); } - { p30 p = new TestClass(); } - { p31 p = new TestClass(); } - { p40 p = new TestClass(); } - { p41 p = new TestClass(); } -// { p42 p = new TestClass(); } - { p43 p = new TestClass(); } - { p44 p = new TestClass(); } - { p45 p = new TestClass(); } - { p46 p = new TestClass(); } - { p47 p = new TestClass(); } - { p48 p = new TestClass(); } - { p49 p = new TestClass(); } -// { p50 p = new TestClass(); } - { p51 p = new TestClass(); } - { p52 p = new TestClass(); } - { p53 p = new TestClass(); } - { p54 p = new TestClass(); } - { p55 p = new TestClass(); } - { p56 p = new TestClass(); } - { p57 p = new TestClass(); } -// { p58 p = new TestClass(); } - { p59 p = new TestClass(); } - { p60 p = new TestClass(); } - { p61 p = new TestClass(); } - { p62 p = new TestClass(); } - { p63 p = new TestClass(); } - { p64 p = new TestClass(); } - { p65 p = new TestClass(); } -// { p66 p = new TestClass(); } - { p67 p = new TestClass(); } - { p68 p = new TestClass(); } - { p69 p = new TestClass(); } - { p70 p = new TestClass(); } - { p71 p = new TestClass(); } - { p72 p = new TestClass(); } - { p73 p = new TestClass(); } -// { p74 p = new TestClass(); } - { p75 p = new TestClass(); } - { p76 p = new TestClass(); } - { p77 p = new TestClass(); } - { p78 p = new TestClass(); } - { p79 p = new TestClass(); } - { p80 p = new TestClass(); } - { p81 p = new TestClass(); } -// { p82 p = new TestClass(); } - { p83 p = new TestClass(); } - { p84 p = new TestClass(); } - { p85 p = new TestClass(); } - { p86 p = new TestClass(); } - { p87 p = new TestClass(); } - { p88 p = new TestClass(); } - { p89 p = new TestClass(); } -// { p90 p = new TestClass(); } - { p91 p = new TestClass(); } - { p92 p = new TestClass(); } - { p93 p = new TestClass(); } - { p94 p = new TestClass(); } - { p95 p = new TestClass(); } - { p96 p = new TestClass(); } - { p97 p = new TestClass(); } -// { p98 p = new TestClass(); } - { p99 p = new TestClass(); } - { p100 p = new TestClass(); } - { p101 p = new TestClass(); } - { p102 p = new TestClass(); } - { p103 p = new TestClass(); } + { p0 p = new TestClass(); } + { p1 p = new TestClass(); } +// { p2 p = new TestClass(); } + { p3 p = new TestClass(); } + { p4 p = new TestClass(); } + { p5 p = new TestClass(); } + { p6 p = new TestClass(); } + { p7 p = new TestClass(); } + { p8 p = new TestClass(); } + { p9 p = new TestClass(); } +// { p10 p = new TestClass(); } + { p11 p = new TestClass(); } + { p12 p = new TestClass(); } + { p13 p = new TestClass(); } + { p14 p = new TestClass(); } + { p15 p = new TestClass(); } + { p16 p = new TestClass(); } + { p17 p = new TestClass(); } +// { p18 p = new TestClass(); } + { p19 p = new TestClass(); } + { p20 p = new TestClass(); } + { p21 p = new TestClass(); } + { p22 p = new TestClass(); } + { p23 p = new TestClass(); } + { p24 p = new TestClass(); } + { p25 p = new TestClass(); } +// { p26 p = new TestClass(); } + { p27 p = new TestClass(); } + { p28 p = new TestClass(); } + { p29 p = new TestClass(); } + { p30 p = new TestClass(); } + { p31 p = new TestClass(); } + { p40 p = new TestClass(); } + { p41 p = new TestClass(); } +// { p42 p = new TestClass(); } + { p43 p = new TestClass(); } + { p44 p = new TestClass(); } + { p45 p = new TestClass(); } + { p46 p = new TestClass(); } + { p47 p = new TestClass(); } + { p48 p = new TestClass(); } + { p49 p = new TestClass(); } +// { p50 p = new TestClass(); } + { p51 p = new TestClass(); } + { p52 p = new TestClass(); } + { p53 p = new TestClass(); } + { p54 p = new TestClass(); } + { p55 p = new TestClass(); } + { p56 p = new TestClass(); } + { p57 p = new TestClass(); } +// { p58 p = new TestClass(); } + { p59 p = new TestClass(); } + { p60 p = new TestClass(); } + { p61 p = new TestClass(); } + { p62 p = new TestClass(); } + { p63 p = new TestClass(); } + { p64 p = new TestClass(); } + { p65 p = new TestClass(); } +// { p66 p = new TestClass(); } + { p67 p = new TestClass(); } + { p68 p = new TestClass(); } + { p69 p = new TestClass(); } + { p70 p = new TestClass(); } + { p71 p = new TestClass(); } + { p72 p = new TestClass(); } + { p73 p = new TestClass(); } +// { p74 p = new TestClass(); } + { p75 p = new TestClass(); } + { p76 p = new TestClass(); } + { p77 p = new TestClass(); } + { p78 p = new TestClass(); } + { p79 p = new TestClass(); } + { p80 p = new TestClass(); } + { p81 p = new TestClass(); } +// { p82 p = new TestClass(); } + { p83 p = new TestClass(); } + { p84 p = new TestClass(); } + { p85 p = new TestClass(); } + { p86 p = new TestClass(); } + { p87 p = new TestClass(); } + { p88 p = new TestClass(); } + { p89 p = new TestClass(); } +// { p90 p = new TestClass(); } + { p91 p = new TestClass(); } + { p92 p = new TestClass(); } + { p93 p = new TestClass(); } + { p94 p = new TestClass(); } + { p95 p = new TestClass(); } + { p96 p = new TestClass(); } + { p97 p = new TestClass(); } +// { p98 p = new TestClass(); } + { p99 p = new TestClass(); } + { p100 p = new TestClass(); } + { p101 p = new TestClass(); } + { p102 p = new TestClass(); } + { p103 p = new TestClass(); } - bool test2=TestClass::instances==0; + bool test2=TestClass::instances==0; - bool r=test1 && test2; + bool r=test1 && test2; - testAssert("SmartPtr",r,result); + testAssert("SmartPtr",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } private: - typedef SmartPtr p0; - typedef SmartPtr p1; - //typedef SmartPtr p2; - typedef SmartPtr p3; - typedef SmartPtr p4; - typedef SmartPtr p5; - typedef SmartPtr p6; - typedef SmartPtr p7; + typedef SmartPtr p0; + typedef SmartPtr p1; + //typedef SmartPtr p2; + typedef SmartPtr p3; + typedef SmartPtr p4; + typedef SmartPtr p5; + typedef SmartPtr p6; + typedef SmartPtr p7; - typedef SmartPtr p8; - typedef SmartPtr p9; - //typedef SmartPtr p10; - typedef SmartPtr p11; - typedef SmartPtr p12; - typedef SmartPtr p13; - typedef SmartPtr p14; - typedef SmartPtr p15; + typedef SmartPtr p8; + typedef SmartPtr p9; + //typedef SmartPtr p10; + typedef SmartPtr p11; + typedef SmartPtr p12; + typedef SmartPtr p13; + typedef SmartPtr p14; + typedef SmartPtr p15; - typedef SmartPtr p16; - typedef SmartPtr p17; - //typedef SmartPtr p18; - typedef SmartPtr p19; - typedef SmartPtr p20; - typedef SmartPtr p21; - typedef SmartPtr p22; - typedef SmartPtr p23; + typedef SmartPtr p16; + typedef SmartPtr p17; + //typedef SmartPtr p18; + typedef SmartPtr p19; + typedef SmartPtr p20; + typedef SmartPtr p21; + typedef SmartPtr p22; + typedef SmartPtr p23; - typedef SmartPtr p24; - typedef SmartPtr p25; - //typedef SmartPtr p26; - typedef SmartPtr p27; - typedef SmartPtr p28; - typedef SmartPtr p29; - typedef SmartPtr p30; - typedef SmartPtr p31; + typedef SmartPtr p24; + typedef SmartPtr p25; + //typedef SmartPtr p26; + typedef SmartPtr p27; + typedef SmartPtr p28; + typedef SmartPtr p29; + typedef SmartPtr p30; + typedef SmartPtr p31; - typedef SmartPtr p40; - typedef SmartPtr p41; - //typedef SmartPtr p42; - typedef SmartPtr p43; - typedef SmartPtr p44; - typedef SmartPtr p45; - typedef SmartPtr p46; - typedef SmartPtr p47; + typedef SmartPtr p40; + typedef SmartPtr p41; + //typedef SmartPtr p42; + typedef SmartPtr p43; + typedef SmartPtr p44; + typedef SmartPtr p45; + typedef SmartPtr p46; + typedef SmartPtr p47; - typedef SmartPtr p48; - typedef SmartPtr p49; - //typedef SmartPtr p50; - typedef SmartPtr p51; - typedef SmartPtr p52; - typedef SmartPtr p53; - typedef SmartPtr p54; - typedef SmartPtr p55; + typedef SmartPtr p48; + typedef SmartPtr p49; + //typedef SmartPtr p50; + typedef SmartPtr p51; + typedef SmartPtr p52; + typedef SmartPtr p53; + typedef SmartPtr p54; + typedef SmartPtr p55; - typedef SmartPtr p56; - typedef SmartPtr p57; - //typedef SmartPtr p58; - typedef SmartPtr p59; - typedef SmartPtr p60; - typedef SmartPtr p61; - typedef SmartPtr p62; - typedef SmartPtr p63; + typedef SmartPtr p56; + typedef SmartPtr p57; + //typedef SmartPtr p58; + typedef SmartPtr p59; + typedef SmartPtr p60; + typedef SmartPtr p61; + typedef SmartPtr p62; + typedef SmartPtr p63; - typedef SmartPtr p64; - typedef SmartPtr p65; - //typedef SmartPtr p66; - typedef SmartPtr p67; - typedef SmartPtr p68; - typedef SmartPtr p69; - typedef SmartPtr p70; - typedef SmartPtr p71; + typedef SmartPtr p64; + typedef SmartPtr p65; + //typedef SmartPtr p66; + typedef SmartPtr p67; + typedef SmartPtr p68; + typedef SmartPtr p69; + typedef SmartPtr p70; + typedef SmartPtr p71; - typedef SmartPtr p72; - typedef SmartPtr p73; - //typedef SmartPtr p74; - typedef SmartPtr p75; - typedef SmartPtr p76; - typedef SmartPtr p77; - typedef SmartPtr p78; - typedef SmartPtr p79; + typedef SmartPtr p72; + typedef SmartPtr p73; + //typedef SmartPtr p74; + typedef SmartPtr p75; + typedef SmartPtr p76; + typedef SmartPtr p77; + typedef SmartPtr p78; + typedef SmartPtr p79; - typedef SmartPtr p80; - typedef SmartPtr p81; - //typedef SmartPtr p82; - typedef SmartPtr p83; - typedef SmartPtr p84; - typedef SmartPtr p85; - typedef SmartPtr p86; - typedef SmartPtr p87; + typedef SmartPtr p80; + typedef SmartPtr p81; + //typedef SmartPtr p82; + typedef SmartPtr p83; + typedef SmartPtr p84; + typedef SmartPtr p85; + typedef SmartPtr p86; + typedef SmartPtr p87; - typedef SmartPtr p88; - typedef SmartPtr p89; - //typedef SmartPtr p90; - typedef SmartPtr p91; - typedef SmartPtr p92; - typedef SmartPtr p93; - typedef SmartPtr p94; - typedef SmartPtr p95; + typedef SmartPtr p88; + typedef SmartPtr p89; + //typedef SmartPtr p90; + typedef SmartPtr p91; + typedef SmartPtr p92; + typedef SmartPtr p93; + typedef SmartPtr p94; + typedef SmartPtr p95; - typedef SmartPtr p96; - typedef SmartPtr p97; - //typedef SmartPtr p98; - typedef SmartPtr p99; - typedef SmartPtr p100; - typedef SmartPtr p101; - typedef SmartPtr p102; - typedef SmartPtr p103; + typedef SmartPtr p96; + typedef SmartPtr p97; + //typedef SmartPtr p98; + typedef SmartPtr p99; + typedef SmartPtr p100; + typedef SmartPtr p101; + typedef SmartPtr p102; + typedef SmartPtr p103; } smartPtrTest; #endif diff --git a/tools/RegressionTest/Test.cpp b/tools/RegressionTest/Test.cpp index 2cf6096..71eae5f 100644 --- a/tools/RegressionTest/Test.cpp +++ b/tools/RegressionTest/Test.cpp @@ -9,26 +9,29 @@ // // This software is provided "as is" without express or implied warranty. // -// Last update: October 10, 2002 +// Last update: October 12, 2002 /////////////////////////////////////////////////////////////////////////////// #ifdef __INTEL_COMPILER # pragma warning(disable: 111 193 304 383 444 488 981 1418) +#elif defined(_MSC_VER) && !defined(__MWERKS__) +# pragma warning(disable: 4018 4097 4100 4213 4290 4512 4514 4700 4702 4710 4786 4800) #endif -//Some platforms might have difficulty with this -//Need to ifdef around those cases. -//TODOSGB +// Some platforms might have difficulty with this +// Need to ifdef around those cases. +// TODO SGB #include "UnitTest.h" -//static variable defintion, do not remove +// static variable defintion, do not remove + Test::tests_type Test::tests; - -//Merely comment out any of the following headers to +// Merely comment out any of the following headers to // prevent thier execution during the test. -//A pluggable-factory-like method is used to +// +// A pluggable-factory-like method is used to // auto-register the test, so all that is needed // is the header inclusion to execute the correspond // unit test. @@ -45,37 +48,44 @@ Test::tests_type Test::tests; #include "FunctorTest.h" #include "DataGeneratorsTest.h" - /* * AP - All Pass * FC - Fails to Compile * ? - Unknown/Not Tested/Not Recorded * * TypelistTest TypeManipTest TypeTraitsTest SmallObjectTest SingletonTest - * gcc 2.95.3 ? ? ? ? ? - * gcc 3.2 AP AP AP AP P #ifdef? - * MSVC 6 ? ? ? ? ? - * MSVC 7 AP Conversion FC AP P #ifdef? - * Intel ? ? ? ? ? ? - * BCB 5.5? ? ? ? ? ? - * CW 6.0 ? ? ? ? ? + * gcc 2.95.3 ? ? ? ? ? + * gcc 3.2 AP AP AP AP P (Only SingleThreaded) + * MSVC 6.0 P AP FC FC AP + * MSVC 7.0 AP Conversion FC AP P (Only SingleThreaded) ? + * Intel 5.0 AP AP AP FC FC + * Intel 6.0 AP AP AP FC P (Only SingleThreaded) + * Intel 7.0 AP AP AP FC P (Only SingleThreaded) + * BCC 5.5 ? ? ? ? ? + * BCC 5.6 ? ? ? ? ? + * CW 6.0 ? ? ? ? ? * * SmartPtrTest FactoryTest AbstractFactoryTest AssocVectorTest FunctorTest - * gcc 2.95.3 ? ? ? ? ? - * gcc 3.2 FC AP AP FC AP - * MSVC 6 ? ? ? ? ? - * MSVC 7 FC AP AP FC AP - * Intel ? ? ? ? ? ? - * BCB 5.5? ? ? ? ? ? - * CW 6.0 ? ? ? ? ? + * gcc 2.95.3 ? ? ? ? ? + * gcc 3.2 FC AP AP FC AP + * MSVC 6.0 FC AP FC FC FC + * MSVC 7.0 FC AP AP FC AP + * Intel 5.0 FC FC FC FC FC + * Intel 6.0 FC AP AP FC FC + * Intel 7.0 FC AP AP FC FC + * BCC 5.5 ? ? ? ? ? + * CW 6.0 ? ? ? ? ? * * DataGeneratorsTest - * gcc 2.95.3 ? - * gcc 3.2 AP - * MSVC 6 ? - * MSVC 7 AP - * Intel ? ? - * BCB 5.5? ? + * gcc 2.95.3 ? + * gcc 3.2 AP + * MSVC 6.0 FC + * MSVC 7.0 AP + * Intel 5.0 FC + * Intel 6.0 AP + * Intel 7.0 AP + * BCC 5.5 ? + * BCC 5.6 ? * CW 6.0 ? */ @@ -85,10 +95,8 @@ int main() int result = Test::run("Loki Unit Test"); -#if __BORLANDC__ - while(true); // Stop console window from closing if run from IDE. -#elif _MSC_VER || __GNUC__ - system("pause"); +#if defined(__BORLANDC__) || defined(__GNUC__) + system("pause"); // Stop console window from closing if run from IDE. #endif return result; diff --git a/tools/RegressionTest/TypeManipTest.h b/tools/RegressionTest/TypeManipTest.h index b8c5017..77faa96 100644 --- a/tools/RegressionTest/TypeManipTest.h +++ b/tools/RegressionTest/TypeManipTest.h @@ -25,95 +25,95 @@ class TypeManipTest : public Test { public: - TypeManipTest() : Test("TypeManip.h") {} + TypeManipTest() : Test("TypeManip.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - bool r; + bool r; - r=Int2Type<1>::value==1; + r=Int2Type<1>::value==1; - testAssert("Int2Type",r,result); + testAssert("Int2Type",r,result); - r=SameType::OriginalType,char>::value; + r=SameType::OriginalType,char>::value; - testAssert("Type2Type",r,result); + testAssert("Type2Type",r,result); - r=SameType::Result,char>::value && - SameType::Result,int>::value; + r=SameType::Result,char>::value && + SameType::Result,int>::value; - testAssert("Select",r,result); + testAssert("Select",r,result); - r=Conversion::exists && - Conversion::exists2Way && - !Conversion::sameType && - Conversion::exists && - Conversion::exists2Way && - Conversion::sameType && - Conversion::exists && - !Conversion::exists && - Conversion::exists && - Conversion::exists && - Conversion::exists && - Conversion::exists && - !Conversion::exists && - !Conversion::exists && - Conversion::exists && - Conversion::exists && - !Conversion::exists && - !Conversion::exists && - Conversion::exists && - !Conversion::exists; + r=Conversion::exists && + Conversion::exists2Way && + !Conversion::sameType && + Conversion::exists && + Conversion::exists2Way && + Conversion::sameType && + Conversion::exists && + !Conversion::exists && + Conversion::exists && + Conversion::exists && + Conversion::exists && + Conversion::exists && + !Conversion::exists && + !Conversion::exists && + Conversion::exists && + Conversion::exists && + !Conversion::exists && + !Conversion::exists && + Conversion::exists && + !Conversion::exists; - testAssert("Conversion",r,result); + testAssert("Conversion",r,result); - r=SuperSubclass::value && - SuperSubclass::value && - SuperSubclass::value && - !SuperSubclass::value && - !SuperSubclass::value && - !SuperSubclass::value; - - testAssert("SuperSubclass",r,result); + r=SuperSubclass::value && + SuperSubclass::value && + SuperSubclass::value && + !SuperSubclass::value && + !SuperSubclass::value && + !SuperSubclass::value; + + testAssert("SuperSubclass",r,result); - r=SuperSubclassStrict::value && - SuperSubclassStrict::value && - !SuperSubclassStrict::value && - !SuperSubclassStrict::value && - !SuperSubclassStrict::value && - !SuperSubclassStrict::value; + r=SuperSubclassStrict::value && + SuperSubclassStrict::value && + !SuperSubclassStrict::value && + !SuperSubclassStrict::value && + !SuperSubclassStrict::value && + !SuperSubclassStrict::value; - testAssert("SuperSubclassStrict",r,result); + testAssert("SuperSubclassStrict",r,result); - r=SUPERSUBCLASS(Base,Derived1) && - SUPERSUBCLASS(Base,Derived2) && - SUPERSUBCLASS(Base,Base) && - !SUPERSUBCLASS(Derived1,Base) && - !SUPERSUBCLASS(Derived2,Base) && - !SUPERSUBCLASS(void,Base); + r=SUPERSUBCLASS(Base,Derived1) && + SUPERSUBCLASS(Base,Derived2) && + SUPERSUBCLASS(Base,Base) && + !SUPERSUBCLASS(Derived1,Base) && + !SUPERSUBCLASS(Derived2,Base) && + !SUPERSUBCLASS(void,Base); - testAssert("SUPERSUBCLASS",r,result); + testAssert("SUPERSUBCLASS",r,result); - r=SUPERSUBCLASS_STRICT(Base,Derived1) && - SUPERSUBCLASS_STRICT(Base,Derived2) && - !SUPERSUBCLASS_STRICT(Base,Base) && - !SUPERSUBCLASS_STRICT(Derived1,Base) && - !SUPERSUBCLASS_STRICT(Derived2,Base) && - !SUPERSUBCLASS_STRICT(void,Base); + r=SUPERSUBCLASS_STRICT(Base,Derived1) && + SUPERSUBCLASS_STRICT(Base,Derived2) && + !SUPERSUBCLASS_STRICT(Base,Base) && + !SUPERSUBCLASS_STRICT(Derived1,Base) && + !SUPERSUBCLASS_STRICT(Derived2,Base) && + !SUPERSUBCLASS_STRICT(void,Base); - testAssert("SUPERSUBCLASS_STRICT",r,result); + testAssert("SUPERSUBCLASS_STRICT",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } private: - struct Base { char c; }; - struct Derived1 : Base { char c; }; - struct Derived2 : Derived1 { char c; }; + struct Base { char c; }; + struct Derived1 : Base { char c; }; + struct Derived2 : Derived1 { char c; }; } typeManipTest; #endif diff --git a/tools/RegressionTest/TypeTraitsTest.h b/tools/RegressionTest/TypeTraitsTest.h index b10ecfd..8295ab4 100644 --- a/tools/RegressionTest/TypeTraitsTest.h +++ b/tools/RegressionTest/TypeTraitsTest.h @@ -24,92 +24,92 @@ class TypeTraitsTest : public Test { public: - TypeTraitsTest() : Test("TypeTraits.h") {} + TypeTraitsTest() : Test("TypeTraits.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; + using namespace Loki; - bool r; + bool r; - r=TypeTraits::isPointer && - !TypeTraits::isPointer && - SameType::PointeeType,int>::value && - SameType::PointeeType,NullType>::value && + r=TypeTraits::isPointer && + !TypeTraits::isPointer && + SameType::PointeeType,int>::value && + SameType::PointeeType,NullType>::value && - TypeTraits::isReference && - !TypeTraits::isReference && - SameType::ReferredType,int>::value && - SameType::ReferredType,int>::value && + TypeTraits::isReference && + !TypeTraits::isReference && + SameType::ReferredType,int>::value && + SameType::ReferredType,int>::value && - TypeTraits::isMemberPointer && - !TypeTraits::isMemberPointer && + TypeTraits::isMemberPointer && + !TypeTraits::isMemberPointer && - TypeTraits::isStdUnsignedInt && - !TypeTraits::isStdUnsignedInt && + TypeTraits::isStdUnsignedInt && + !TypeTraits::isStdUnsignedInt && - TypeTraits::isStdSignedInt && - !TypeTraits::isStdSignedInt && + TypeTraits::isStdSignedInt && + !TypeTraits::isStdSignedInt && - TypeTraits::isStdIntegral && - !TypeTraits::isStdIntegral && + TypeTraits::isStdIntegral && + !TypeTraits::isStdIntegral && - TypeTraits::isStdFloat && - !TypeTraits::isStdFloat && + TypeTraits::isStdFloat && + !TypeTraits::isStdFloat && - TypeTraits::isStdArith && - !TypeTraits::isStdArith && + TypeTraits::isStdArith && + !TypeTraits::isStdArith && - TypeTraits::isStdFundamental && - !TypeTraits::isStdFundamental && + TypeTraits::isStdFundamental && + !TypeTraits::isStdFundamental && - TypeTraits::isUnsignedInt && - !TypeTraits::isUnsignedInt && + TypeTraits::isUnsignedInt && + !TypeTraits::isUnsignedInt && - TypeTraits::isSignedInt && - !TypeTraits::isSignedInt && + TypeTraits::isSignedInt && + !TypeTraits::isSignedInt && - TypeTraits::isIntegral && - !TypeTraits::isIntegral && + TypeTraits::isIntegral && + !TypeTraits::isIntegral && - TypeTraits::isFloat && - !TypeTraits::isFloat && + TypeTraits::isFloat && + !TypeTraits::isFloat && - TypeTraits::isArith && - TypeTraits::isArith && - TypeTraits::isArith && - !TypeTraits::isArith && + TypeTraits::isArith && + TypeTraits::isArith && + TypeTraits::isArith && + !TypeTraits::isArith && - TypeTraits::isFundamental && - !TypeTraits::isFundamental && + TypeTraits::isFundamental && + !TypeTraits::isFundamental && #ifndef __BORLANDC__ - TypeTraits::isConst && - !TypeTraits::isConst && - SameType::NonConstType,int>::value && - SameType::NonConstType,int>::value && + TypeTraits::isConst && + !TypeTraits::isConst && + SameType::NonConstType,int>::value && + SameType::NonConstType,int>::value && - TypeTraits::isVolatile && - !TypeTraits::isVolatile && - SameType::NonVolatileType,int>::value && - SameType::NonVolatileType,int>::value && + TypeTraits::isVolatile && + !TypeTraits::isVolatile && + SameType::NonVolatileType,int>::value && + SameType::NonVolatileType,int>::value && - SameType::UnqualifiedType,int>::value && + SameType::UnqualifiedType,int>::value && #endif - SameType::ParameterType,char>::value && - SameType::ParameterType,int>::value && - SameType::ParameterType,double>::value && - SameType::ParameterType,Test &>::value; + SameType::ParameterType,char>::value && + SameType::ParameterType,int>::value && + SameType::ParameterType,double>::value && + SameType::ParameterType,Test &>::value; - testAssert("TypeTraits",r,result); + testAssert("TypeTraits",r,result); - std::cout << '\n'; - } + std::cout << '\n'; + } } typeTraitsTest; #endif diff --git a/tools/RegressionTest/TypelistTest.h b/tools/RegressionTest/TypelistTest.h index 9cc8d0e..c430811 100644 --- a/tools/RegressionTest/TypelistTest.h +++ b/tools/RegressionTest/TypelistTest.h @@ -24,165 +24,165 @@ class TypelistTest : public Test { public: - TypelistTest() : Test("Typelist.h") {} + TypelistTest() : Test("Typelist.h") {} - virtual void execute(TestResult &result) - { - printName(result); + virtual void execute(TestResult &result) + { + printName(result); - using namespace Loki; - using namespace Loki::TL; + using namespace Loki; + using namespace Loki::TL; - typedef TYPELIST_1(char) CharList; - typedef TYPELIST_3(char,int,double) CharIntDoubleList; - typedef TYPELIST_4(char,int,double,char) CharIntDoubleCharList; - typedef TYPELIST_3(Base,Derived1,Derived2) BaseDerived1Derived2List; - typedef TYPELIST_3(Derived2,Derived1,Base) Derived2Derived1BaseList; - typedef TYPELIST_4(Base,Derived1,Base,Derived2) BaseDerived1BaseDerived2List; - typedef TYPELIST_4(Derived1,Base,Derived1,Derived2) Derived1BaseDerived1Derived2List; + typedef TYPELIST_1(char) CharList; + typedef TYPELIST_3(char,int,double) CharIntDoubleList; + typedef TYPELIST_4(char,int,double,char) CharIntDoubleCharList; + typedef TYPELIST_3(Base,Derived1,Derived2) BaseDerived1Derived2List; + typedef TYPELIST_3(Derived2,Derived1,Base) Derived2Derived1BaseList; + typedef TYPELIST_4(Base,Derived1,Base,Derived2) BaseDerived1BaseDerived2List; + typedef TYPELIST_4(Derived1,Base,Derived1,Derived2) Derived1BaseDerived1Derived2List; - bool r; + bool r; - r=Length::value==0 && - Length::value==1 && - Length::value==3; + r=Length::value==0 && + Length::value==1 && + Length::value==3; - testAssert("Length",r,result); + testAssert("Length",r,result); - r=SameType::Result,char>::value && - SameType::Result,double>::value; + r=SameType::Result,char>::value && + SameType::Result,double>::value; - testAssert("TypeAt",r,result); + testAssert("TypeAt",r,result); - #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) + #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) - // TypeAtNonStrict works like TypeAt on MSVC 6.0 + // 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 && + 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); + testAssert("TypeAtNonStrict",r,result); - #else + #else - testAssert("TypeAtNonStrict",false,result,false); + testAssert("TypeAtNonStrict",false,result,false); - #endif + #endif - r=IndexOf::value==-1 && - IndexOf::value==0 && - IndexOf::value==2 && - IndexOf::value==-1; + r=IndexOf::value==-1 && + IndexOf::value==0 && + IndexOf::value==2 && + IndexOf::value==-1; - testAssert("IndexOf",r,result); + testAssert("IndexOf",r,result); - #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) + #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 + // Append, Erase, EraseAll, NoDuplicates, Replace, ReplaceAll, Reverse, + // MostDerived and DerivedToFront doesn't work on MSVC 6.0 - r=SameType::Result,NullType>::value && - SameType::Result,TYPELIST_1(char)>::value && - SameType::Result,CharList>::value && - SameType::Result,CharList>::value && - SameType::Result,TYPELIST_2(char,int)>::value && - SameType::Result,TYPELIST_4(char,char,int,double)>::value; + r=SameType::Result,NullType>::value && + SameType::Result,TYPELIST_1(char)>::value && + SameType::Result,CharList>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_2(char,int)>::value && + SameType::Result,TYPELIST_4(char,char,int,double)>::value; - testAssert("Append",r,result); + testAssert("Append",r,result); - r=SameType::Result,NullType>::value && - SameType::Result,NullType>::value && - SameType::Result,CharList>::value && - SameType::Result,TYPELIST_2(char,double)>::value && - SameType::Result,TYPELIST_2(char,int)>::value; + r=SameType::Result,NullType>::value && + SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_2(char,double)>::value && + SameType::Result,TYPELIST_2(char,int)>::value; - testAssert("Erase",r,result); + testAssert("Erase",r,result); - r=SameType::Result,NullType>::value && - SameType::Result,NullType>::value && - SameType::Result,CharList>::value && - SameType::Result,TYPELIST_2(char,double)>::value && - SameType::Result,TYPELIST_2(char,int)>::value && - SameType::Result,TYPELIST_2(int,double)>::value && - SameType::Result,TYPELIST_3(char,double,char)>::value && - SameType::Result,TYPELIST_3(char,int,char)>::value; + r=SameType::Result,NullType>::value && + SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_2(char,double)>::value && + SameType::Result,TYPELIST_2(char,int)>::value && + SameType::Result,TYPELIST_2(int,double)>::value && + SameType::Result,TYPELIST_3(char,double,char)>::value && + SameType::Result,TYPELIST_3(char,int,char)>::value; - testAssert("EraseAll",r,result); + testAssert("EraseAll",r,result); - r=SameType::Result,NullType>::value && - SameType::Result,CharList>::value && - SameType::Result,CharIntDoubleList>::value && - SameType::Result,CharIntDoubleList>::value; + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,CharIntDoubleList>::value; - testAssert("NoDuplicates",r,result); + testAssert("NoDuplicates",r,result); - r=SameType::Result,NullType>::value && - SameType::Result,TYPELIST_1(long)>::value && - SameType::Result,CharList>::value && - SameType::Result,TYPELIST_3(long,int,double)>::value && - SameType::Result,CharIntDoubleList>::value && - SameType::Result,TYPELIST_4(long,int,double,char)>::value; + r=SameType::Result,NullType>::value && + SameType::Result,TYPELIST_1(long)>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_3(long,int,double)>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,TYPELIST_4(long,int,double,char)>::value; - testAssert("Replace",r,result); + testAssert("Replace",r,result); - r=SameType::Result,NullType>::value && - SameType::Result,TYPELIST_1(long)>::value && - SameType::Result,CharList>::value && - SameType::Result,TYPELIST_3(long,int,double)>::value && - SameType::Result,CharIntDoubleList>::value && - SameType::Result,TYPELIST_4(long,int,double,long)>::value; + r=SameType::Result,NullType>::value && + SameType::Result,TYPELIST_1(long)>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_3(long,int,double)>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,TYPELIST_4(long,int,double,long)>::value; - testAssert("ReplaceAll",r,result); + testAssert("ReplaceAll",r,result); - r=SameType::Result,NullType>::value && - SameType::Result,CharList>::value && - SameType::Result,TYPELIST_3(double,int,char)>::value; + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_3(double,int,char)>::value; - testAssert("Reverse",r,result); + 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; + 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); + 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,TYPELIST_4(Derived2,Derived1,Base,Base)>::value && - SameType::Result,TYPELIST_4(Derived2,Derived1,Derived1,Base)>::value; + 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,TYPELIST_4(Derived2,Derived1,Base,Base)>::value && + SameType::Result,TYPELIST_4(Derived2,Derived1,Derived1,Base)>::value; - testAssert("DerivedToFront",r,result); + testAssert("DerivedToFront",r,result); - #else + #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); + 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 + #endif - std::cout << '\n'; - } + std::cout << '\n'; + } private: - struct Base { char c; }; - struct Derived1 : Base { char c; }; - struct Derived2 : Derived1 { char c; }; + struct Base { char c; }; + struct Derived1 : Base { char c; }; + struct Derived2 : Derived1 { char c; }; } typelistTest; #endif diff --git a/tools/RegressionTest/UnitTest.h b/tools/RegressionTest/UnitTest.h index d442d79..3d3f652 100644 --- a/tools/RegressionTest/UnitTest.h +++ b/tools/RegressionTest/UnitTest.h @@ -25,26 +25,26 @@ // SameType /////////////////////////////////////////////////////////////////////////////// -#if _MSC_VER && !__INTEL_COMPILER && !__MWERKS__ +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) // Rani Sharoni's SameType +// +// Non-conforming workaround for MSVC -//This is non-standard code, you are not allowed to -// specialize a nested template template struct SameType { private: - template - struct In - { enum { value = false }; }; + template + struct In + { enum { value = false }; }; - template<> - struct In - { enum { value = true }; }; + template<> + struct In + { enum { value = true }; }; public: - enum { value = In::value }; + enum { value = In::value }; }; #else @@ -52,13 +52,13 @@ public: template struct SameType { - static const bool value=false; + static const bool value=false; }; template struct SameType { - static const bool value=true; + static const bool value=true; }; #endif @@ -70,12 +70,12 @@ struct SameType class TestResult { public: - TestResult() : pos(0),passed(0),failed(0),notSupported(0) {} + TestResult() : pos(0),passed(0),failed(0),notSupported(0) {} - int pos; - int passed; - int failed; - int notSupported; + int pos; + int passed; + int failed; + int notSupported; }; @@ -89,94 +89,94 @@ typedef std::vector tests_type; static tests_type tests; public: - explicit Test(const std::string &n) : name(n) - { - Test::tests.push_back(this); - } + explicit Test(const std::string &n) : name(n) + { + Test::tests.push_back(this); + } - virtual void execute(TestResult &) =0; - + virtual void execute(TestResult &) =0; + protected: - ~Test() {} + ~Test() {} - void printName(const TestResult &result) const - { - if(name.length()!=0) - std::cout << std::string(result.pos,' ') << name << '\n'; - } + void printName(const TestResult &result) const + { + if(name.length()!=0) + std::cout << std::string(result.pos,' ') << name << '\n'; + } - void testAssert(const std::string &s,bool assertion,TestResult &result,bool supported =true, - const std::string &failStr =emptyStr()) - { - std::string str=std::string(result.pos+2,' ')+s; + void testAssert(const std::string &s,bool assertion,TestResult &result,bool supported =true, + const std::string &failStr =emptyStr()) + { + std::string str=std::string(result.pos+2,' ')+s; - str+=std::string(offset-str.length(),' '); + str+=std::string(offset-str.length(),' '); - if(supported) - { - if(assertion) - { - std::cout << str << "Passed\n"; + if(supported) + { + if(assertion) + { + std::cout << str << "Passed\n"; - ++result.passed; - } - else - { - std::cout << str << (failStr==emptyStr() ? std::string("Failed") : "Failed - "+failStr) << '\n'; + ++result.passed; + } + else + { + std::cout << str << (failStr==emptyStr() ? std::string("Failed") : "Failed - "+failStr) << '\n'; - ++result.failed; - } - } - else - { - std::cout << str << "Not Supported\n"; + ++result.failed; + } + } + else + { + std::cout << str << "Not Supported\n"; - ++result.notSupported; - } - } + ++result.notSupported; + } + } - static std::string emptyStr() - { - return std::string(); - } + static std::string emptyStr() + { + return std::string(); + } public: - enum { offset=63 }; + enum { offset=63 }; protected: - const std::string name; - + const std::string name; + public: - static int run(const std::string &title) - { - std::cout << title << std::string(Test::offset-title.length(),' ') << "Result\n"; - std::cout << std::string(76,'-') << '\n'; - - TestResult testResult; - - tests_type::iterator it; - tests_type::const_iterator itEnd = Test::tests.end(); - for(it=Test::tests.begin(); it!=itEnd; ++it) - { - Test* test = *it; - test->execute(testResult); - } - - std::cout << std::string(76,'-') << '\n'; + static int run(const std::string &title) + { + std::cout << title << std::string(Test::offset-title.length(),' ') << "Result\n"; + std::cout << std::string(76,'-') << '\n'; + + TestResult testResult; + + tests_type::iterator it; + tests_type::const_iterator itEnd = Test::tests.end(); + for(it=Test::tests.begin(); it!=itEnd; ++it) + { + Test* test = *it; + test->execute(testResult); + } + + std::cout << std::string(76,'-') << '\n'; - const int total=testResult.passed+testResult.failed; - const int totalAll=total+testResult.notSupported; + const int total=testResult.passed+testResult.failed; + const int totalAll=total+testResult.notSupported; - if(total!=0) - std::cout << "Total - " << testResult.passed << '/' << total << (total==1 ? " test, " : " tests, ") - << testResult.passed*100/total << "% Passed\n"; + if(total!=0) + std::cout << "Total - " << testResult.passed << '/' << total << (total==1 ? " test, " : " tests, ") + << testResult.passed*100/total << "% Passed\n"; - if(testResult.notSupported!=0) - std::cout << "Not Supported - " << testResult.notSupported << '/' << totalAll << ", " - << testResult.notSupported*100/totalAll << "%\n"; + if(testResult.notSupported!=0) + std::cout << "Not Supported - " << testResult.notSupported << '/' << totalAll << ", " + << testResult.notSupported*100/totalAll << "%\n"; - return testResult.failed; - } + return testResult.failed; + } };