You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(80) |
Aug
(36) |
Sep
(120) |
Oct
(89) |
Nov
(57) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(308) |
Feb
(66) |
Mar
(88) |
Apr
(54) |
May
(43) |
Jun
(40) |
Jul
(33) |
Aug
(1) |
Sep
(7) |
Oct
(65) |
Nov
(19) |
Dec
(10) |
2007 |
Jan
(5) |
Feb
(8) |
Mar
(7) |
Apr
|
May
(7) |
Jun
|
Jul
(5) |
Aug
(3) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(5) |
Jun
(21) |
Jul
(27) |
Aug
(6) |
Sep
|
Oct
(1) |
Nov
(5) |
Dec
(10) |
2009 |
Jan
(67) |
Feb
(3) |
Mar
(26) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(10) |
Oct
(18) |
Nov
(20) |
Dec
(3) |
2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(9) |
Oct
(3) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
|
Sep
(39) |
Oct
(43) |
Nov
(7) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <ric...@us...> - 2011-09-23 00:47:00
|
Revision: 1116 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1116&view=rev Author: rich_sposato Date: 2011-09-23 00:46:54 +0000 (Fri, 23 Sep 2011) Log Message: ----------- Added text of MIT License. Modified Paths: -------------- trunk/src/LevelMutex.cpp trunk/src/OrderedStatic.cpp trunk/src/SafeFormat.cpp trunk/src/Singleton.cpp trunk/src/SmallObj.cpp trunk/src/SmartPtr.cpp trunk/src/StrongPtr.cpp Modified: trunk/src/LevelMutex.cpp =================================================================== --- trunk/src/LevelMutex.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/LevelMutex.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -2,16 +2,26 @@ // // LevelMutex facility for the Loki Library // Copyright (c) 2008, 2009 Richard Sposato -// The copyright on this file is protected under the terms of the MIT license. +// Code covered by the MIT License // -// 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. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // -// The author makes no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied warranty. +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// //////////////////////////////////////////////////////////////////////////////// // $Id$ Modified: trunk/src/OrderedStatic.cpp =================================================================== --- trunk/src/OrderedStatic.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/OrderedStatic.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -1,13 +1,25 @@ //////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2005 Peter K\xFCmmel -// 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 makes no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // $Id$ @@ -16,14 +28,14 @@ #include <loki/OrderedStatic.h> #include <limits> -#ifdef min -#undef min +#ifdef min +#undef min #endif - -#ifdef max -#undef max -#endif +#ifdef max +#undef max +#endif + namespace Loki { namespace Private @@ -32,12 +44,12 @@ OrderedStaticCreatorFunc::OrderedStaticCreatorFunc() { } - + OrderedStaticCreatorFunc::~OrderedStaticCreatorFunc() { } - + OrderedStaticManagerClass::OrderedStaticManagerClass() : staticObjects_(), max_longevity_(std::numeric_limits<unsigned int>::min()), Modified: trunk/src/SafeFormat.cpp =================================================================== --- trunk/src/SafeFormat.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/SafeFormat.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -1,13 +1,25 @@ //////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2005 by Andrei Alexandrescu // Copyright (c) 2006 Peter K\xFCmmel -// 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 makes no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied -// warranty. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // $Id$ @@ -33,7 +45,7 @@ assert(from <= to); s.append(from, to); } - + // Write to a stream void write(std::ostream& f, const char* from, const char* to) { Modified: trunk/src/Singleton.cpp =================================================================== --- trunk/src/Singleton.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/Singleton.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -2,15 +2,27 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this -// permission 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. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // $Id$ @@ -36,16 +48,16 @@ void LOKI_C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn() { assert(pTrackerArray!=0 && !pTrackerArray->empty()); - + // Pick the element at the top of the stack LifetimeTracker* pTop = pTrackerArray->back(); - + // Remove that object off the stack _before_ deleting pTop pTrackerArray->pop_back(); - + // Destroy the element delete pTop; - + // Destroy stack when it's empty _after_ deleting pTop if(pTrackerArray->empty()) { @@ -62,7 +74,7 @@ // 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 + // Don't check errors - realloc with less memory // can't fail pTrackerArray = static_cast<TrackerArray>(std::realloc( pTrackerArray, sizeof(*pTrackerArray) * --elements)); @@ -70,5 +82,5 @@ delete pTop; } -#endif +#endif Modified: trunk/src/SmallObj.cpp =================================================================== --- trunk/src/SmallObj.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/SmallObj.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -4,13 +4,25 @@ // 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. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // $Id$ Modified: trunk/src/SmartPtr.cpp =================================================================== --- trunk/src/SmartPtr.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/SmartPtr.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -5,13 +5,25 @@ // 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. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // $Id$ Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-23 00:46:21 UTC (rev 1115) +++ trunk/src/StrongPtr.cpp 2011-09-23 00:46:54 UTC (rev 1116) @@ -1,13 +1,25 @@ //////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2006 Rich Sposato -// 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 makes no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // $Id$ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-23 00:46:29
|
Revision: 1115 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1115&view=rev Author: rich_sposato Date: 2011-09-23 00:46:21 +0000 (Fri, 23 Sep 2011) Log Message: ----------- Added text of MIT License. Modified Paths: -------------- trunk/include/loki/AbstractFactory.h trunk/include/loki/Allocator.h trunk/include/loki/AssocVector.h trunk/include/loki/CachedFactory.h trunk/include/loki/CheckReturn.h trunk/include/loki/Checker.h trunk/include/loki/ConstPolicy.h trunk/include/loki/DataGenerators.h trunk/include/loki/EmptyType.h trunk/include/loki/Factory.h trunk/include/loki/ForEachType.h trunk/include/loki/Function.h trunk/include/loki/Functor.h trunk/include/loki/HierarchyGenerators.h trunk/include/loki/Key.h trunk/include/loki/LevelMutex.h trunk/include/loki/LockingPtr.h trunk/include/loki/LokiExport.h trunk/include/loki/LokiTypeInfo.h trunk/include/loki/MultiMethods.h trunk/include/loki/NullType.h trunk/include/loki/OrderedStatic.h trunk/include/loki/Pimpl.h trunk/include/loki/RefToValue.h trunk/include/loki/Register.h trunk/include/loki/SPCachedFactory.h trunk/include/loki/SafeBits.h trunk/include/loki/SafeFormat.h trunk/include/loki/ScopeGuard.h trunk/include/loki/Sequence.h trunk/include/loki/Singleton.h trunk/include/loki/SmallObj.h trunk/include/loki/SmartPtr.h trunk/include/loki/StrongPtr.h trunk/include/loki/ThreadLocal.h trunk/include/loki/Threads.h trunk/include/loki/Tuple.h trunk/include/loki/TypeManip.h trunk/include/loki/TypeTraits.h trunk/include/loki/Typelist.h trunk/include/loki/TypelistMacros.h trunk/include/loki/Visitor.h trunk/include/loki/static_check.h Modified: trunk/include/loki/AbstractFactory.h =================================================================== --- trunk/include/loki/AbstractFactory.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/AbstractFactory.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -4,13 +4,26 @@ // 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. +// +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_ABSTRACTFACTORY_INC_ #define LOKI_ABSTRACTFACTORY_INC_ Modified: trunk/include/loki/Allocator.h =================================================================== --- trunk/include/loki/Allocator.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/Allocator.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -2,13 +2,23 @@ // The Loki Library // Copyright (c) 2008 by Rich Sposato // -// 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 makes no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_ALLOCATOR_HPP_INCLUDED Modified: trunk/include/loki/AssocVector.h =================================================================== --- trunk/include/loki/AssocVector.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/AssocVector.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -2,15 +2,26 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this -// permission 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. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_ASSOCVECTOR_INC_ #define LOKI_ASSOCVECTOR_INC_ @@ -42,21 +53,21 @@ public: AssocVectorCompare() {} - + AssocVectorCompare(const C& src) : C(src) {} - - bool operator()(const first_argument_type& lhs, + + 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, + + 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); } @@ -82,7 +93,7 @@ class C = std::less<K>, class A = std::allocator< std::pair<K, V> > > - class AssocVector + class AssocVector : private std::vector< std::pair<K, V>, A > , private Private::AssocVectorCompare<V, C> { @@ -112,7 +123,7 @@ , private key_compare { friend class AssocVector; - + protected: value_compare(key_compare pred) : key_compare(pred) {} @@ -121,27 +132,27 @@ 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(), + explicit AssocVector(const key_compare& comp = key_compare(), const A& alloc = A()) : Base(alloc), MyCompare(comp) {} - + template <class InputIterator> - AssocVector(InputIterator first, InputIterator last, - const key_compare& comp = key_compare(), + 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); + { + AssocVector(rhs).swap(*this); return *this; } @@ -155,7 +166,7 @@ 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(); } @@ -182,18 +193,18 @@ //http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/libstdc++/23_containers/howto.html#4 iterator insert(iterator pos, const value_type& val) { - if( (pos == begin() || this->operator()(*(pos-1),val)) && + if( (pos == begin() || this->operator()(*(pos-1),val)) && (pos == end() || this->operator()(val, *pos)) ) { return Base::insert(pos, val); } return insert(val).first; } - + template <class InputIterator> void insert(InputIterator first, InputIterator last) { for (; first != last; ++first) insert(*first); } - + void erase(iterator pos) { Base::erase(pos); } @@ -215,7 +226,7 @@ MyCompare& rhs = other; std::swap(me, rhs); } - + void clear() { Base::clear(); } @@ -241,7 +252,7 @@ } const_iterator find(const key_type& k) const - { + { const_iterator i(lower_bound(k)); if (i != end() && this->operator()(k, i->first)) { @@ -351,7 +362,7 @@ template <class K, class V, class C, class A> void swap(AssocVector<K, V, C, A>& lhs, AssocVector<K, V, C, A>& rhs) { lhs.swap(rhs); } - + } // namespace Loki #endif // end file guardian Modified: trunk/include/loki/CachedFactory.h =================================================================== --- trunk/include/loki/CachedFactory.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/CachedFactory.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -4,14 +4,24 @@ // // Code covered by the MIT License // -// 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. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // -// The authors make no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied warranty. +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// // This code DOES NOT accompany the book: // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. Modified: trunk/include/loki/CheckReturn.h =================================================================== --- trunk/include/loki/CheckReturn.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/CheckReturn.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -1,13 +1,26 @@ //////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2007 by Rich Sposato -// 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 makes no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_CHECK_RETURN_INC_ Modified: trunk/include/loki/Checker.h =================================================================== --- trunk/include/loki/Checker.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/Checker.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -4,14 +4,26 @@ // Copyright (c) 2008, 2009 Rich Sposato // The copyright on this file is protected under the terms of the MIT license. // -// 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. +// Code covered by the MIT License // -// The author makes no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied warranty. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// //////////////////////////////////////////////////////////////////////////////// // $Id$ Modified: trunk/include/loki/ConstPolicy.h =================================================================== --- trunk/include/loki/ConstPolicy.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/ConstPolicy.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -2,13 +2,26 @@ // The Loki Library // Copyright (c) 2006 Richard Sposato // Copyright (c) 2006 Peter K\xFCmmel -// 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 authors make no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_CONST_POLICY_INC_ #define LOKI_CONST_POLICY_INC_ Modified: trunk/include/loki/DataGenerators.h =================================================================== --- trunk/include/loki/DataGenerators.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/DataGenerators.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -5,9 +5,26 @@ // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // -// Code covered by the MIT License -// The author makes no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied warranty. +// Code covered by the MIT License: +// Copyright(c) 2010 Shannon Barber +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_DATAGENERATORS_INC_ #define LOKI_DATAGENERATORS_INC_ Modified: trunk/include/loki/EmptyType.h =================================================================== --- trunk/include/loki/EmptyType.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/EmptyType.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -2,15 +2,28 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this -// permission 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. +// +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_EMPTYTYPE_INC_ #define LOKI_EMPTYTYPE_INC_ @@ -27,18 +40,18 @@ //////////////////////////////////////////////////////////////////////////////// class EmptyType {}; - - + + inline bool operator==(const EmptyType&, const EmptyType&) { return true; - } + } inline bool operator<(const EmptyType&, const EmptyType&) { return false; } - + inline bool operator>(const EmptyType&, const EmptyType&) { return false; Modified: trunk/include/loki/Factory.h =================================================================== --- trunk/include/loki/Factory.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/Factory.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -7,8 +7,24 @@ // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // // Code covered by the MIT License -// The authors make no representations about the suitability of this software -// for any purpose. It is provided "as is" without express or implied warranty. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_FACTORYPARM_INC_ #define LOKI_FACTORYPARM_INC_ Modified: trunk/include/loki/ForEachType.h =================================================================== --- trunk/include/loki/ForEachType.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/ForEachType.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -2,13 +2,25 @@ // The Loki Library // Copyright (C) 2009 Andy Balaam // Copyright (c) 2009 Peter Kümmel -// 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 makes no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_FOR_EACH_TYPE @@ -34,7 +46,7 @@ // type of recursive function template <class TList, class Callable> struct ForEachTypeImpl; - + // Recursion rule template <class Head, class Tail, class Callable> struct ForEachTypeImpl<Typelist<Head, Tail>, Callable> @@ -42,7 +54,7 @@ { enum { value = 1 + ForEachTypeImpl<Tail, Callable>::value }; - ForEachTypeImpl( Callable& callable ) : ForEachTypeImpl<Tail, Callable>(callable) + ForEachTypeImpl( Callable& callable ) : ForEachTypeImpl<Tail, Callable>(callable) { #ifdef _MSC_VER callable.operator()<value, Head>(); @@ -50,12 +62,12 @@ callable.template operator()<value, Head>(); #endif } - + }; // Recursion end template <class Head, class Callable> - struct ForEachTypeImpl<Typelist<Head, NullType>, Callable> + struct ForEachTypeImpl<Typelist<Head, NullType>, Callable> { public: @@ -70,8 +82,8 @@ #endif } }; - + } Modified: trunk/include/loki/Function.h =================================================================== --- trunk/include/loki/Function.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/Function.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -1,13 +1,26 @@ //////////////////////////////////////////////////////////////////////////////// // The Loki Library // Copyright (c) 2005 Peter K\xFCmmel -// 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 makes no representations about the -// suitability of this software for any purpose. It is provided "as is" -// without express or implied warranty. +// +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_FUNCTION_INC_ #define LOKI_FUNCTION_INC_ @@ -30,17 +43,17 @@ /// /// \ingroup FunctorGroup /// Allows a boost/TR1 like usage of Functor. - /// + /// /// \par Usage /// /// - free functions: e.g. \code Function<int(int,int)> f(&freeFunction); /// \endcode - /// - member functions: e.g \code Function<int()> f(&object,&ObjectType::memberFunction); + /// - member functions: e.g \code Function<int()> f(&object,&ObjectType::memberFunction); /// \endcode /// /// see also test/Function/FunctionTest.cpp (the modified test program from boost) //////////////////////////////////////////////////////////////////////////////// - + template<class R = void()> struct Function; @@ -52,29 +65,29 @@ Function() : FBase() {} - Function(const Function& func) : FBase() + Function(const Function& func) : FBase() { - if( !func.empty()) + if( !func.empty()) FBase::operator=(func); } - + // test on emptiness - template<class R2> - Function(Function<R2()> func) : FBase() + template<class R2> + Function(Function<R2()> func) : FBase() { if(!func.empty()) FBase::operator=(func); } - + // clear by '= 0' Function(const int i) : FBase() - { + { if(i==0) FBase::clear(); else throw std::runtime_error("Loki::Function(const int i): i!=0"); } - + template<class Func> Function(Func func) : FBase(func) {} @@ -113,7 +126,7 @@ template<class Host, class Func> \ Function(const Host& host, const Func& func): FBase(host,func) {} - + #define LOKI_FUNCTION_R2_CTOR_BODY \ \ : FBase() \ @@ -132,77 +145,77 @@ : public Loki::Functor<> { typedef Functor<> FBase; - + template<class R2> - Function(Function<R2()> func) + Function(Function<R2()> func) LOKI_FUNCTION_R2_CTOR_BODY - LOKI_FUNCTION_BODY // if compilation breaks here then + LOKI_FUNCTION_BODY // if compilation breaks here then // Function.h was not included before // Functor.h, check your include order - // or define LOKI_ENABLE_FUNCTION + // or define LOKI_ENABLE_FUNCTION }; template<class R,class P01> - struct Function<R(P01)> + struct Function<R(P01)> : public Loki::Functor<R, Seq<P01> > { typedef Functor<R, Seq<P01> > FBase; - + template<class R2,class Q01> - Function(Function<R2(Q01)> func) + Function(Function<R2(Q01)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template<class R,class P01,class P02> - struct Function<R(P01,P02)> + struct Function<R(P01,P02)> : public Functor<R, Seq<P01,P02> > { typedef Functor<R, Seq<P01,P02> > FBase; template<class R2,class Q01, class Q02> - Function(Function<R2(Q01,Q02)> func) + Function(Function<R2(Q01,Q02)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template<class R,class P01,class P02, class P03> - struct Function<R(P01,P02,P03)> + struct Function<R(P01,P02,P03)> : public Functor<R, Seq<P01,P02,P03> > { typedef Functor<R, Seq<P01,P02,P03> > FBase; template<class R2,class Q01, class Q02,class Q03> - Function(Function<R2(Q01,Q02,Q03)> func) + Function(Function<R2(Q01,Q02,Q03)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template<class R,class P01,class P02, class P03,class P04> - struct Function<R(P01,P02,P03,P04)> + struct Function<R(P01,P02,P03,P04)> : public Functor<R, Seq<P01,P02,P03,P04> > { typedef Functor<R, Seq<P01,P02,P03,P04> > FBase; template<class R2,class Q01,class Q02, class Q03,class Q04> - Function(Function<R2(Q01,Q02,Q03,Q04)> func) + Function(Function<R2(Q01,Q02,Q03,Q04)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY }; template<class R,class P01,class P02, class P03,class P04,class P05> - struct Function<R(P01,P02,P03,P04,P05)> + struct Function<R(P01,P02,P03,P04,P05)> : public Functor<R, Seq<P01,P02,P03,P04,P05> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05> > FBase; template<class R2,class Q01,class Q02, class Q03,class Q04,class Q05> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -210,14 +223,14 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06> - struct Function<R(P01,P02,P03,P04,P05,P06)> + struct Function<R(P01,P02,P03,P04,P05,P06)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06> > FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -225,14 +238,14 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07> - struct Function<R(P01,P02,P03,P04,P05,P06,P07)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07> > FBase; template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -240,14 +253,14 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08> > FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -255,14 +268,14 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09 > > FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -270,14 +283,14 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09,class P10> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10> > FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09,class Q10> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -286,15 +299,15 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09,class P10, class P11> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11> >FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09,class Q10, class Q11> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -303,15 +316,15 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09,class P10, class P11,class P12> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12> > FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09,class Q10, class Q11,class Q12> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -320,15 +333,15 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09,class P10, class P11,class P12, class P13> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13> > FBase; - + template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09,class Q10, class Q11,class Q12, class Q13> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -337,14 +350,14 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09,class P10, class P11,class P12, class P13,class P14> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14> > FBase; template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09,class Q10, class Q11,class Q12, class Q13,class Q14> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13,Q14)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13,Q14)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY @@ -353,7 +366,7 @@ template<class R, class P01,class P02, class P03,class P04,class P05, class P06,class P07, class P08,class P09,class P10, class P11,class P12, class P13,class P14,class P15> - struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14,P15)> + struct Function<R(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14,P15)> : public Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14,P15> > { typedef Functor<R, Seq<P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,P13,P14,P15> > FBase; @@ -361,7 +374,7 @@ template<class R2, class Q01,class Q02, class Q03,class Q04,class Q05, class Q06,class Q07, class Q08,class Q09,class Q10, class Q11,class Q12, class Q13,class Q14,class Q15> - Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13,Q14,Q15)> func) + Function(Function<R2(Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13,Q14,Q15)> func) LOKI_FUNCTION_R2_CTOR_BODY LOKI_FUNCTION_BODY Modified: trunk/include/loki/Functor.h =================================================================== --- trunk/include/loki/Functor.h 2011-09-21 23:24:54 UTC (rev 1114) +++ trunk/include/loki/Functor.h 2011-09-23 00:46:21 UTC (rev 1115) @@ -2,15 +2,28 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this -// permission 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. +// +// Code covered by the MIT License +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_FUNCTOR_INC_ #define LOKI_FUNCTOR_INC_ @@ -48,7 +61,7 @@ namespace Private { template <typename R, template <class, class> class ThreadingModel> - struct FunctorImplBase + struct FunctorImplBase #ifdef LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT { #else @@ -98,12 +111,12 @@ #ifdef LOKI_FUNCTORS_ARE_COMPARABLE virtual bool operator==(const FunctorImplBase&) const = 0; - -#endif - + +#endif + }; } - + //////////////////////////////////////////////////////////////////////////////// // macro LOKI_DEFINE_CLONE_FUNCTORIMPL // Implements the DoClone function for a functor implementation @@ -121,7 +134,7 @@ // Specializations of FunctorImpl for up to 15 parameters follow //////////////////////////////////////////////////////////////////////////////// - template <typename R, class TList, + template <typename R, class TList, template <class, class> class ThreadingModel = LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL> class FunctorImpl; @@ -159,7 +172,7 @@ // Specialization for 2 parameters //////////////////////////////////////////////////////////////////////////////// - template <typename R, typename P1, typename P2, + template <typename R, typename P1, typename P2, template <class, class> class ThreadingModel> class FunctorImpl<R, Seq<P1, P2>, ThreadingModel> : public Private::FunctorImplBase<R, ThreadingModel> @@ -271,7 +284,7 @@ typedef typename TypeTraits<P5>::ParameterType Parm5; typedef typename TypeTraits<P6>::ParameterType Parm6; typedef typename TypeTraits<P7>::ParameterType Parm7; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7) = 0; }; @@ -297,7 +310,7 @@ typedef typename TypeTraits<P6>::ParameterType Parm6; typedef typename TypeTraits<P7>::ParameterType Parm7; typedef typename TypeTraits<P8>::ParameterType Parm8; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8) = 0; }; @@ -324,7 +337,7 @@ typedef typename TypeTraits<P7>::ParameterType Parm7; typedef typename TypeTraits<P8>::ParameterType Parm8; typedef typename TypeTraits<P9>::ParameterType Parm9; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9) = 0; }; @@ -353,7 +366,7 @@ typedef typename TypeTraits<P8>::ParameterType Parm8; typedef typename TypeTraits<P9>::ParameterType Parm9; typedef typename TypeTraits<P10>::ParameterType Parm10; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10) = 0; }; @@ -384,7 +397,7 @@ typedef typename TypeTraits<P9>::ParameterType Parm9; typedef typename TypeTraits<P10>::ParameterType Parm10; typedef typename TypeTraits<P11>::ParameterType Parm11; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11) = 0; }; @@ -416,7 +429,7 @@ typedef typename TypeTraits<P10>::ParameterType Parm10; typedef typename TypeTraits<P11>::ParameterType Parm11; typedef typename TypeTraits<P12>::ParameterType Parm12; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12) = 0; }; @@ -449,7 +462,7 @@ typedef typename TypeTraits<P11>::ParameterType Parm11; typedef typename TypeTraits<P12>::ParameterType Parm12; typedef typename TypeTraits<P13>::ParameterType Parm13; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13) = 0; }; @@ -484,7 +497,7 @@ typedef typename TypeTraits<P12>::ParameterType Parm12; typedef typename TypeTraits<P13>::ParameterType Parm13; typedef typename TypeTraits<P14>::ParameterType Parm14; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13, Parm14) = 0; }; @@ -520,7 +533,7 @@ typedef typename TypeTraits<P13>::ParameterType Parm13; typedef typename TypeTraits<P14>::ParameterType Parm14; typedef typename TypeTraits<P15>::ParameterType Parm15; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13, Parm14, Parm15) = 0; }; @@ -547,7 +560,7 @@ // Specialization for 2 parameters //////////////////////////////////////////////////////////////////////////////// - template <typename R, typename P1, typename P2, + template <typename R, typename P1, typename P2, template <class, class> class ThreadingModel> class FunctorImpl<R, LOKI_TYPELIST_2(P1, P2), ThreadingModel> : public Private::FunctorImplBase<R, ThreadingModel> @@ -659,7 +672,7 @@ typedef typename TypeTraits<P5>::ParameterType Parm5; typedef typename TypeTraits<P6>::ParameterType Parm6; typedef typename TypeTraits<P7>::ParameterType Parm7; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7) = 0; }; @@ -685,7 +698,7 @@ typedef typename TypeTraits<P6>::ParameterType Parm6; typedef typename TypeTraits<P7>::ParameterType Parm7; typedef typename TypeTraits<P8>::ParameterType Parm8; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8) = 0; }; @@ -712,7 +725,7 @@ typedef typename TypeTraits<P7>::ParameterType Parm7; typedef typename TypeTraits<P8>::ParameterType Parm8; typedef typename TypeTraits<P9>::ParameterType Parm9; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9) = 0; }; @@ -741,7 +754,7 @@ typedef typename TypeTraits<P8>::ParameterType Parm8; typedef typename TypeTraits<P9>::ParameterType Parm9; typedef typename TypeTraits<P10>::ParameterType Parm10; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10) = 0; }; @@ -772,7 +785,7 @@ typedef typename TypeTraits<P9>::ParameterType Parm9; typedef typename TypeTraits<P10>::ParameterType Parm10; typedef typename TypeTraits<P11>::ParameterType Parm11; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11) = 0; }; @@ -804,7 +817,7 @@ typedef typename TypeTraits<P10>::ParameterType Parm10; typedef typename TypeTraits<P11>::ParameterType Parm11; typedef typename TypeTraits<P12>::ParameterType Parm12; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12) = 0; }; @@ -837,7 +850,7 @@ typedef typename TypeTraits<P11>::ParameterType Parm11; typedef typename TypeTraits<P12>::ParameterType Parm12; typedef typename TypeTraits<P13>::ParameterType Parm13; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13) = 0; }; @@ -872,7 +885,7 @@ typedef typename TypeTraits<P12>::ParameterType Parm12; typedef typename TypeTraits<P13>::ParameterType Parm13; typedef typename TypeTraits<P14>::ParameterType Parm14; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13, Parm14) = 0; }; @@ -908,7 +921,7 @@ typedef typename TypeTraits<P13>::ParameterType Parm13; typedef typename TypeTraits<P14>::ParameterType Parm14; typedef typename TypeTraits<P15>::ParameterType Parm15; - virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, + virtual R operator()(Parm1, Parm2, Parm3, Parm4, Parm5, Parm6, Parm7, Parm8, Parm9, Parm10, Parm11, Parm12, Parm13, Parm14, Parm15) = 0; }; @@ -943,9 +956,9 @@ typedef typename Base::Parm13 Parm13; typedef typename Base::Parm14 Parm14; typedef typename Base::Parm15 Parm15; - + FunctorHandler(const Fun& fun) : f_(fun) {} - + LOKI_DEFINE_CLONE_FUNCTORIMPL(FunctorHandler) @@ -954,7 +967,7 @@ bool operator==(const typename Base::FunctorImplBaseType& rhs) const { - // there is no static information if Functor holds a member function + // there is no static information if Functor holds a member function // or a free function; this is the main difference to tr1::function if(typeid(*this) != typeid(rhs)) return false; // cannot be equal @@ -966,79 +979,79 @@ } #endif // operator() implementations for up to 15 arguments - + ResultType operator()() { return f_(); } ResultType operator()(Parm1 p1) { return f_(p1); } - + ResultType operator()(Parm1 p1, Parm2 p2) { return f_(p1, p2); } - + ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3) { return f_(p1, p2, p3); } - + ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4) { return f_(p1, p2, p3, p4); } - + ResultType operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4,... [truncated message content] |
From: <ric...@us...> - 2011-09-21 23:25:00
|
Revision: 1114 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1114&view=rev Author: rich_sposato Date: 2011-09-21 23:24:54 +0000 (Wed, 21 Sep 2011) Log Message: ----------- Added comment about policy incompatibility. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-20 23:32:29 UTC (rev 1113) +++ trunk/include/loki/SmartPtr.h 2011-09-21 23:24:54 UTC (rev 1114) @@ -400,6 +400,13 @@ /// /// \ingroup SmartPointerStorageGroup /// Implementation of the ArrayStorage used by SmartPtr +/// This assumes the pointer points to the zeroth element in an array, and uses +/// the array-delete operator to deconstruct and deallocate the array. DeepCopy +/// is not compatible with ArrayStorage DeepCopy::Clone will only copy the first +/// element in the array and won't know the size of the array. Even if it did +/// know the size, it would need to use array new to safely work the array +/// delete operator in ArrayStorage, but array new will not copy the elements +/// in the source array since it calls the default constructor for each element. //////////////////////////////////////////////////////////////////////////////// @@ -663,7 +670,12 @@ /// \ingroup SmartPointerOwnershipGroup /// Implementation of the OwnershipPolicy used by SmartPtr /// Implements deep copy semantics, assumes existence of a Clone() member -/// function of the pointee type +/// function of the pointee type. DeepCopy is not compatible with ArrayStorage +/// DeepCopy::Clone will only copy the first element in the array and won't +/// know the size of the array. Even if it did know the size, it would need to +/// use array new to safely work the array delete operator in ArrayStorage, but +/// array new will not copy the elements in the source array since it calls the +/// default constructor for each array element. //////////////////////////////////////////////////////////////////////////////// template <class P> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 23:32:35
|
Revision: 1113 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1113&view=rev Author: rich_sposato Date: 2011-09-20 23:32:29 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added tests for SmartPtr::operator[] - and related changes. Modified Paths: -------------- trunk/test/SmartPtr/base.h trunk/test/SmartPtr/main.cpp trunk/test/SmartPtr/strong.cpp Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-20 23:25:41 UTC (rev 1112) +++ trunk/test/SmartPtr/base.h 2011-09-20 23:32:29 UTC (rev 1113) @@ -73,10 +73,11 @@ return s_destructions; } +protected: + BaseClass( const BaseClass & that ) : m_refCount( that.m_refCount ) {} + private: /// Not implemented. - BaseClass( const BaseClass & ); - /// Not implemented. BaseClass & operator = ( const BaseClass & ); static unsigned int s_constructions; @@ -110,7 +111,45 @@ } }; +// ---------------------------------------------------------------------------- +/** @class Feline - The feline family of classes are to test dynamic_cast. Also used to test + pointers to arrays of objects. + */ +class Feline : public BaseClass +{ +public: + virtual ~Feline() {} + virtual Feline * Clone( void ) const = 0; +}; + +class Lion : public Feline +{ +public: + virtual ~Lion() {} + virtual Lion * Clone( void ) const { return new Lion( *this ); } +}; + +class Tiger : public Feline +{ +public: + Tiger( void ) : m_stripes( 100 ) {} + virtual ~Tiger() {} + virtual Tiger * Clone( void ) const { return new Tiger( *this ); } + unsigned int GetStripes( void ) const { return m_stripes; } + void SetStripes( unsigned int s ) { m_stripes = s; } +private: + unsigned int m_stripes; +}; + +class Dog +{ +public: + virtual ~Dog() {} + virtual Dog * Clone( void ) const { return new Dog( *this ); } +}; + + // ---------------------------------------------------------------------------- /** @class MimicCOM Acts like a COM object by having an intrusive ref count. Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-20 23:25:41 UTC (rev 1112) +++ trunk/test/SmartPtr/main.cpp 2011-09-20 23:32:29 UTC (rev 1113) @@ -1205,75 +1205,6 @@ // ---------------------------------------------------------------------------- -namespace -{ - - class Feline - { - public: - - static inline bool AllDestroyed( void ) - { - return ( s_constructions == s_destructions ); - } - - static inline bool ExtraConstructions( void ) - { - return ( s_constructions > s_destructions ); - } - - static inline bool ExtraDestructions( void ) - { - return ( s_constructions < s_destructions ); - } - - static inline unsigned int GetCtorCount( void ) - { - return s_constructions; - } - - static inline unsigned int GetDtorCount( void ) - { - return s_destructions; - } - - Feline( void ) { s_constructions++; } - virtual ~Feline() { s_destructions++; } - virtual Feline * Clone( void ) const = 0; - - private: - static unsigned int s_constructions; - static unsigned int s_destructions; - }; - - unsigned int Feline::s_constructions = 0; - unsigned int Feline::s_destructions = 0; - - class Tiger : public Feline - { - public: - virtual ~Tiger() {} - virtual Tiger * Clone( void ) const { return new Tiger( *this ); } - }; - - class Lion : public Feline - { - public: - virtual ~Lion() {} - virtual Lion * Clone( void ) const { return new Lion( *this ); } - }; - - class Dog - { - public: - virtual ~Dog() {} - virtual Dog * Clone( void ) const { return new Dog( *this ); } - }; - -} - -// ---------------------------------------------------------------------------- - void DoSmartPtrDynamicCastTests( void ) { cout << "Starting DoSmartPtrDynamicCastTests." << endl; @@ -1359,9 +1290,9 @@ assert( !pDog ); } - assert( Feline::AllDestroyed() ); - assert( !Feline::ExtraConstructions() ); - assert( !Feline::ExtraDestructions() ); + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); cout << "Finished DoSmartPtrDynamicCastTests." << endl; } @@ -1518,6 +1449,161 @@ // ---------------------------------------------------------------------------- +/// Use these typedefs to test DeleteArray policy. + +typedef Loki::SmartPtr< Tiger, RefCounted, DisallowConversion, + AssertCheck, ArrayStorage, DontPropagateConst > + TigerArray_RefCounted_ptr; + +typedef Loki::SmartPtr< Tiger, RefLinked, DisallowConversion, + AssertCheck, ArrayStorage, DontPropagateConst > + TigerArray_2RefLinks_ptr; + +// ---------------------------------------------------------------------------- + +void DoSmartArrayTests( void ) +{ + cout << "Starting DoSmartArrayTests." << endl; + + { + // test default construction. + TigerArray_RefCounted_ptr sp1; + assert( !sp1 ); + assert( 0 == sp1.GetArrayCount() ); + + // test assignment. + sp1.Assign( new Tiger[ 8 ], 8 ); + assert( sp1 ); + assert( 8 == sp1.GetArrayCount() ); + sp1[ 0 ].SetStripes( 8 ); + sp1[ 1 ].SetStripes( 16 ); + sp1[ 2 ].SetStripes( 24 ); + sp1[ 3 ].SetStripes( 32 ); + sp1[ 4 ].SetStripes( 40); + sp1[ 5 ].SetStripes( 48 ); + sp1[ 6 ].SetStripes( 56 ); + sp1[ 7 ].SetStripes( 64 ); + + // test initialization construction. + TigerArray_RefCounted_ptr sp2( new Tiger[ 4 ], 4 ); + assert( sp2 ); + assert( 4 == sp2.GetArrayCount() ); + sp2[ 0 ].SetStripes( 5 ); + sp2[ 1 ].SetStripes( 10 ); + sp2[ 2 ].SetStripes( 15 ); + sp2[ 3 ].SetStripes( 20 ); + + // test range checking. + try + { + Tiger & p4 = sp2[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test range checking. + try + { + Tiger & p8 = sp1[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test swap. + sp2.Swap( sp1 ); + assert( sp1 ); + assert( sp2 ); + // test checking of item count. + assert( 4 == sp1.GetArrayCount() ); + assert( 8 == sp2.GetArrayCount() ); + + // test that operator[] returns reference to + assert( 5 == sp1[ 0 ].GetStripes() ); + assert( 10 == sp1[ 1 ].GetStripes() ); + assert( 15 == sp1[ 2 ].GetStripes() ); + assert( 20 == sp1[ 3 ].GetStripes() ); + assert( 8 == sp2[ 0 ].GetStripes() ); + assert( 16 == sp2[ 1 ].GetStripes() ); + assert( 24 == sp2[ 2 ].GetStripes() ); + assert( 32 == sp2[ 3 ].GetStripes() ); + assert( 40 == sp2[ 4 ].GetStripes() ); + assert( 48 == sp2[ 5 ].GetStripes() ); + assert( 56 == sp2[ 6 ].GetStripes() ); + assert( 64 == sp2[ 7 ].GetStripes() ); + + try + { + Tiger & p4 = sp1[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + try + { + Tiger & p8 = sp2[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_RefCounted_ptr sp3( sp1 ); + assert( sp3 == sp1 ); + assert( sp3.GetArrayCount() == sp1.GetArrayCount() ); + try + { + const Tiger & p4 = sp3[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_RefCounted_ptr sp5( sp2 ); + assert( sp5 == sp2 ); + assert( sp5.GetArrayCount() == sp2.GetArrayCount() ); + try + { + const Tiger & p8 = sp5[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + sp2 = sp1; + assert( sp1 == sp2 ); + assert( sp3 == sp2 ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp1 != sp5 ); + assert( sp2 != sp5 ); + assert( sp3 != sp5 ); + assert( sp1.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp2.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp3.GetArrayCount() != sp5.GetArrayCount() ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoSmartArrayTests." << endl; +} + +// ---------------------------------------------------------------------------- + int main( int argc, const char * argv[] ) { bool doThreadTest = false; @@ -1556,6 +1642,7 @@ DoSmartPtrDynamicCastTests(); DoStrongPtrDynamicCastTests(); DoStrongArrayTests(); + DoSmartArrayTests(); #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) if ( doThreadTest ) Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-09-20 23:25:41 UTC (rev 1112) +++ trunk/test/SmartPtr/strong.cpp 2011-09-20 23:32:29 UTC (rev 1113) @@ -1778,42 +1778,6 @@ // ---------------------------------------------------------------------------- -namespace -{ - - class Feline : public BaseClass - { - public: - virtual ~Feline() {} - }; - - class Lion : public Feline - { - public: - virtual ~Lion() {} - }; - - class Tiger : public Feline - { - public: - Tiger( void ) : m_stripes( 100 ) {} - virtual ~Tiger() {} - unsigned int GetStripes( void ) const { return m_stripes; } - void SetStripes( unsigned int s ) { m_stripes = s; } - private: - unsigned int m_stripes; - }; - - class Dog - { - public: - virtual ~Dog() {} - }; - -} - -// ---------------------------------------------------------------------------- - void DoStrongPtrDynamicCastTests( void ) { typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 23:25:47
|
Revision: 1112 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1112&view=rev Author: rich_sposato Date: 2011-09-20 23:25:41 +0000 (Tue, 20 Sep 2011) Log Message: ----------- -m Modified Paths: -------------- trunk/include/loki/StrongPtr.h trunk/src/StrongPtr.cpp Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-20 23:19:14 UTC (rev 1111) +++ trunk/include/loki/StrongPtr.h 2011-09-20 23:25:41 UTC (rev 1112) @@ -85,7 +85,10 @@ /// If you write your own policy, you must implement these 3 functions: /// -# void static Delete( const P * p ) /// -# static P * Default( void ) -/// -# void Swap( YourResetPolicy & ) +/// -# Default constructor. +/// -# Copy constructor. +/// -# Templated copy constructor. +/// -# void Swap( YourDeletePolicy & ) /// /// \par ResetPolicy /// A reset policy tells the ReleaseAll and ResetAll functions whether they @@ -235,46 +238,7 @@ inline void Swap( DeleteSingle & ) {} }; -namespace Private -{ - //////////////////////////////////////////////////////////////////////////////// -/// \class DeleteArrayBase -/// -/// \ingroup StrongPointerDeleteGroup -/// Base class used only by the DeleteArray policy class. This stores the -/// number of elements in an array of shared objects. -//////////////////////////////////////////////////////////////////////////////// - -class DeleteArrayBase -{ -public: - - inline size_t GetArrayCount( void ) const { return m_itemCount; } - -protected: - - DeleteArrayBase( void ) : m_itemCount( 0 ) {} - - explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} - - DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} - - void Swap( DeleteArrayBase & rhs ); - - void OnInit( const void * p ) const; - - void OnCheckRange( size_t index ) const; - -private: - - size_t m_itemCount; - -}; - -} - -//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -2068,19 +2032,27 @@ return * GetPointer(); } + /** operator[] returns a reference to an modifiable object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ReferenceType operator [] ( size_t index ) { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); PointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } + /** operator[] returns a reference to a const object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ConstReferenceType operator [] ( size_t index ) const { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); ConstPointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 23:19:14 UTC (rev 1111) +++ trunk/src/StrongPtr.cpp 2011-09-20 23:25:41 UTC (rev 1112) @@ -15,9 +15,6 @@ #include <loki/StrongPtr.h> -#include <stdexcept> -#include <string> - #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -41,45 +38,6 @@ // ---------------------------------------------------------------------------- -void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) -{ - assert( NULL != this ); - - const size_t temp = m_itemCount; - m_itemCount = rhs.m_itemCount; - rhs.m_itemCount = temp; -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnInit( const void * p ) const -{ - assert( NULL != this ); - if ( NULL == p ) - { - assert( 0 == m_itemCount ); - } - else - { - assert( 0 < m_itemCount ); - } -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnCheckRange( size_t index ) const -{ - assert( NULL != this ); - - if ( index < m_itemCount ) - return; - - const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); - throw ::std::out_of_range( message ); -} - -// ---------------------------------------------------------------------------- - OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 23:19:21
|
Revision: 1111 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1111&view=rev Author: rich_sposato Date: 2011-09-20 23:19:14 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Back to revision 1109. Accidentally checked in more files than I intended. Revision Links: -------------- http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1109&view=rev Modified Paths: -------------- trunk/Loki.workspace trunk/include/loki/StrongPtr.h trunk/include/loki/ThreadLocal.h trunk/include/loki/flex/flex_string_shell.h trunk/src/StrongPtr.cpp trunk/test/LevelMutex/LevelMutex.cbp trunk/test/LevelMutex/MultiThreadTests.cpp trunk/test/LevelMutex/ThreadPool.cpp trunk/test/LevelMutex/main.cpp trunk/test/LockingPtr/LockingPtr.cbp trunk/test/SmartPtr/SmartPtr.cbp trunk/test/SmartPtr/base.h trunk/test/SmartPtr/main.cpp trunk/test/SmartPtr/strong.cpp trunk/test/ThreadLocal/ThreadLocal.cbp trunk/test/ThreadLocal/main.cpp Modified: trunk/Loki.workspace =================================================================== --- trunk/Loki.workspace 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/Loki.workspace 2011-09-20 23:19:14 UTC (rev 1111) @@ -2,46 +2,46 @@ <CodeBlocks_workspace_file> <Workspace title="Workspace"> <Project filename="Loki.cbp" active="1" /> - <Project filename="test/CachedFactory/CachedFactory.cbp"> + <Project filename="test\CachedFactory\CachedFactory.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Checker/Checker.cbp" /> - <Project filename="test/CheckReturn/CheckReturn.cbp" /> - <Project filename="test/DeletableSingleton/DeletableSingleton.cbp"> + <Project filename="test\Checker\Checker.cbp" /> + <Project filename="test\CheckReturn\CheckReturn.cbp" /> + <Project filename="test\DeletableSingleton\DeletableSingleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Factory/Factory.cbp" /> - <Project filename="test/flex_string/flex_string.cbp" /> - <Project filename="test/Function/Function.cbp" /> - <Project filename="test/LevelMutex/LevelMutex.cbp"> + <Project filename="test\Factory\Factory.cbp" /> + <Project filename="test\flex_string\flex_string.cbp" /> + <Project filename="test\Function\Function.cbp" /> + <Project filename="test\LevelMutex\LevelMutex.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/LockingPtr/LockingPtr.cbp" /> - <Project filename="test/Longevity/Longevity.cbp" /> - <Project filename="test/OrderedStatic/OrderedStatic.cbp"> + <Project filename="test\LockingPtr\LockingPtr.cbp" /> + <Project filename="test\Longevity\Longevity.cbp" /> + <Project filename="test\OrderedStatic\OrderedStatic.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Pimpl/Pimpl.cbp" /> - <Project filename="test/Register/Register.cbp" /> - <Project filename="test/RegressionTest/RegressionTest.cbp"> + <Project filename="test\Pimpl\Pimpl.cbp" /> + <Project filename="test\Register\Register.cbp" /> + <Project filename="test\RegressionTest\RegressionTest.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/SafeFormat/SafeFormat.cbp"> + <Project filename="test\SafeFormat\SafeFormat.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/ScopeGuard/ScopeGuard.cbp" /> - <Project filename="test/Singleton/Singleton.cbp"> + <Project filename="test\ScopeGuard\ScopeGuard.cbp" /> + <Project filename="test\Singleton\Singleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/SmallObj/SmallObj.cbp"> + <Project filename="test\SmallObj\SmallObj.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/SmallObj/DefaultAlloc.cbp" /> - <Project filename="test/SmartPtr/SmartPtr.cbp"> + <Project filename="test\SmallObj\DefaultAlloc.cbp" /> + <Project filename="test\SmartPtr\SmartPtr.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test/Visitor/Visitor.cbp" /> - <Project filename="test/SafeBits/SafeBits.cbp" /> - <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> + <Project filename="test\Visitor\Visitor.cbp" /> + <Project filename="test\SafeBits\SafeBits.cbp" /> + <Project filename="test\ThreadLocal\ThreadLocal.cbp" /> </Workspace> </CodeBlocks_workspace_file> Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/include/loki/StrongPtr.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -85,10 +85,7 @@ /// If you write your own policy, you must implement these 3 functions: /// -# void static Delete( const P * p ) /// -# static P * Default( void ) -/// -# Default constructor. -/// -# Copy constructor. -/// -# Templated copy constructor. -/// -# void Swap( YourDeletePolicy & ) +/// -# void Swap( YourResetPolicy & ) /// /// \par ResetPolicy /// A reset policy tells the ReleaseAll and ResetAll functions whether they @@ -238,7 +235,46 @@ inline void Swap( DeleteSingle & ) {} }; +namespace Private +{ + //////////////////////////////////////////////////////////////////////////////// +/// \class DeleteArrayBase +/// +/// \ingroup StrongPointerDeleteGroup +/// Base class used only by the DeleteArray policy class. This stores the +/// number of elements in an array of shared objects. +//////////////////////////////////////////////////////////////////////////////// + +class DeleteArrayBase +{ +public: + + inline size_t GetArrayCount( void ) const { return m_itemCount; } + +protected: + + DeleteArrayBase( void ) : m_itemCount( 0 ) {} + + explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} + + DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} + + void Swap( DeleteArrayBase & rhs ); + + void OnInit( const void * p ) const; + + void OnCheckRange( size_t index ) const; + +private: + + size_t m_itemCount; + +}; + +} + +//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -2032,27 +2068,19 @@ return * GetPointer(); } - /** operator[] returns a reference to an modifiable object. If the index is greater than or - equal to the number of elements, the function will throw a std::out_of_range exception. - This only works with DeleteArray policy. Any other policy will cause a compiler error. - */ ReferenceType operator [] ( size_t index ) { + KP::OnDereference( GetPointer() ); + DP::OnCheckRange( index ); PointerType p = GetPointer(); - KP::OnDereference( p ); - DP::OnCheckRange( index ); return p[ index ]; } - /** operator[] returns a reference to a const object. If the index is greater than or - equal to the number of elements, the function will throw a std::out_of_range exception. - This only works with DeleteArray policy. Any other policy will cause a compiler error. - */ ConstReferenceType operator [] ( size_t index ) const { + KP::OnDereference( GetPointer() ); + DP::OnCheckRange( index ); ConstPointerType p = GetPointer(); - KP::OnDereference( p ); - DP::OnCheckRange( index ); return p[ index ]; } Modified: trunk/include/loki/ThreadLocal.h =================================================================== --- trunk/include/loki/ThreadLocal.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/include/loki/ThreadLocal.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -28,29 +28,21 @@ // The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system. #if defined( __APPLE__ ) #warning "GCC for Apple does not allow thread_local storage, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #elif defined( __CYGWIN__ ) #if ( __GNUC__ <= 3 ) #warning "Older versions of GCC for Cygwin do not allow thread_local storage, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin. - #if ( __GNUC_MINOR__ < 4 ) - #warning "GCC versions before 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE - #else - #warning "Versions 4.4 through 4.6 of GCC implemented thread_local storage for some platforms, but not others. Run ThreadLocal test project." + #if ( __GNUC_MINOR__ == 4 ) + #warning "GCC version 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." + #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #endif - -#elif defined( _MSC_VER ) - #if ( _MSC_VER < 1300 ) - #warning "Only Visual Studio versions 7.0 and after support thread local storage properly, so you can not use some parts of Loki." - #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE - #endif -#endif +#endif #if defined( LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE ) && !defined( LOKI_THREAD_LOCAL ) @@ -65,7 +57,11 @@ you can't use some parts of Loki. */ #if defined( _MSC_VER ) - #define LOKI_THREAD_LOCAL __declspec( thread ) + #if ( _MSC_VER >= 1300 ) + #define LOKI_THREAD_LOCAL __declspec( thread ) + #else + #error "Only Visual Studio versions 7.0 and after supported." + #endif #elif ( __GNUC__ ) #define LOKI_THREAD_LOCAL __thread Modified: trunk/include/loki/flex/flex_string_shell.h =================================================================== --- trunk/include/loki/flex/flex_string_shell.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/include/loki/flex/flex_string_shell.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -1339,17 +1339,17 @@ typename flex_string<E, T, A, S>::value_type delim) { size_t nread = 0; - typename std::basic_istream<typename flex_string<E, T, A, S>::value_type, + typename basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>::sentry sentry(is, true); if (sentry) { - ::std::basic_streambuf<typename flex_string<E, T, A, S>::value_type, + basic_streambuf<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>* buf = is.rdbuf(); str.clear(); while (nread < str.max_size()) { int c1 = buf->sbumpc(); if (flex_string<E, T, A, S>::traits_type::eq_int_type(c1, flex_string<E, T, A, S>::traits_type::eof())) { - is.setstate(::std::ios_base::eofbit); + is.setstate(ios_base::eofbit); break; } else { @@ -1363,7 +1363,7 @@ } } if (nread == 0 || nread >= str.max_size()) - is.setstate(::std::ios_base::failbit); + is.setstate(ios_base::failbit); return is; } Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/src/StrongPtr.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -15,6 +15,9 @@ #include <loki/StrongPtr.h> +#include <stdexcept> +#include <string> + #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -38,6 +41,45 @@ // ---------------------------------------------------------------------------- +void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) +{ + assert( NULL != this ); + + const size_t temp = m_itemCount; + m_itemCount = rhs.m_itemCount; + rhs.m_itemCount = temp; +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnInit( const void * p ) const +{ + assert( NULL != this ); + if ( NULL == p ) + { + assert( 0 == m_itemCount ); + } + else + { + assert( 0 < m_itemCount ); + } +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnCheckRange( size_t index ) const +{ + assert( NULL != this ); + + if ( index < m_itemCount ) + return; + + const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); + throw ::std::out_of_range( message ); +} + +// ---------------------------------------------------------------------------- + OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) Modified: trunk/test/LevelMutex/LevelMutex.cbp =================================================================== --- trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -6,24 +6,24 @@ <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="obj/Debug_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="obj\Debug_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-W" /> <Add option="-g" /> - <Add option="-W" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki_D.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj/Release_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="obj\Release_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -31,33 +31,33 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj/Debug_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_Cygwin/" /> + <Option output="obj\Debug_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki_D.a" /> - <Add library="../../../PThreads/lib/pthreadVC2.lib" /> + <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj/Release_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_Cygwin/" /> + <Option output="obj\Release_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -65,12 +65,12 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include" /> - <Add directory="../../include/loki" /> + <Add directory="..\..\include" /> + <Add directory="..\..\include\loki" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki.a" /> - <Add library="../../../PThreads/lib/pthreadVC2.lib" /> + <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> </Linker> </Target> </Build> Modified: trunk/test/LevelMutex/MultiThreadTests.cpp =================================================================== --- trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -4,9 +4,9 @@ // Copyright (c) 2008, 2009 Richard Sposato // The copyright on this file is protected under the terms of the MIT license. // -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // // The author makes no representations about the suitability of this software @@ -22,7 +22,7 @@ #include "MultiThreadTests.hpp" #include <assert.h> -//#include <process.h> +#include <process.h> #include <stdlib.h> #include <time.h> @@ -239,8 +239,6 @@ void MultiThreadSimpleTest( void ) { - cout << "Starting MultiThreadSimpleTest." << endl; - Thing::Init( 0 ); const unsigned int threadCount = 5; ThreadPool pool( threadCount ); @@ -264,8 +262,6 @@ pool.JoinAll(); Thing::Destroy(); - - cout << "Finished MultiThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -303,17 +299,13 @@ void MultiThreadTryLockTest( void ) { - cout << "Starting MultiThreadTryLockTest." << endl; - static const unsigned int threadCount = 3; Thing::Init( 0 ); volatile Thing & thing = Thing::GetIt(); volatile SleepMutex & mutex = thing.GetMutex(); cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl; - cout << "Press enter key to continue." << endl; - char theKey = 0; - cin.get( theKey ); + ::system( "pause" ); // First step is to lock the mutex in the main thread so no child thread // can ever lock it, change the value, or anything like that. MutexErrors::Type result = mutex.Lock(); @@ -321,46 +313,36 @@ bool okay = mutex.IsLockedByCurrentThread(); assert( okay ); thing.SetValue( threadCount ); - + ThreadPool pool( threadCount ); + for ( unsigned int ii = 0; ii < threadCount; ++ii ) { - ThreadPool pool( threadCount ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) - { - void * p = reinterpret_cast< void * >( ii ); - pool.Start( TryLockThread, p ); - } - pool.JoinAll(); + void * p = reinterpret_cast< void * >( ii ); + pool.Start( TryLockThread, p ); } + pool.JoinAll(); + const unsigned int value = thing.GetValue(); + assert( value == threadCount ); + result = mutex.Unlock(); + assert( MutexErrors::Success == result ); + okay = !mutex.IsLockedByCurrentThread(); + assert( okay ); + okay = !mutex.IsLocked(); + assert( okay ); - const unsigned int value = thing.GetValue(); - assert( value == threadCount ); - result = mutex.Unlock(); - assert( MutexErrors::Success == result ); - okay = !mutex.IsLockedByCurrentThread(); - assert( okay ); - okay = !mutex.IsLocked(); - assert( okay ); - Thing::Destroy(); - - cout << "Finished MultiThreadTryLockTest." << endl; } // ---------------------------------------------------------------------------- void MultiThreadReentrantTest( void ) { - cout << "Starting MultiThreadReentrantTest." << endl; - Thing::Init( 0 ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); ThreadPool pool( threadCount ); cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl; - cout << "Press enter key to continue." << endl; - char theKey = 0; - cin.get( theKey ); + ::system( "pause" ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -370,8 +352,7 @@ TestResults::GetIt()->OutputResults(); cout << endl << "Doing thread-unsafe value test. This test may fail." << endl; - cout << "Press enter key to continue." << endl; - cin.get( theKey ); + ::system( "pause" ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -382,8 +363,6 @@ TestResults::Destroy(); Thing::Destroy(); - - cout << "Finished MultiThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -667,8 +646,6 @@ void MultiThreadMultiLockTest( void ) { - cout << "Starting MultiThreadMultiLockTest." << endl; - Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -697,8 +674,6 @@ TestResults::Destroy(); Thing::DestroyPool(); - - cout << "Finished MultiThreadMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -833,8 +808,6 @@ void MultiThreadRandomMultiLockTest( void ) { - cout << "Starting MultiThreadRandomMultiLockTest." << endl; - Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -863,8 +836,6 @@ TestResults::Destroy(); Thing::DestroyPool(); - - cout << "Finished MultiThreadRandomMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -965,8 +936,6 @@ void MultiThreadHierarchySingleLockTest( void ) { - cout << "Starting MultiThreadHierarchySingleLockTest." << endl; - LevelThing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -995,8 +964,6 @@ TestResults::Destroy(); LevelThing::DestroyPool(); - - cout << "Finished MultiThreadHierarchySingleLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -1098,8 +1065,6 @@ void MultiThreadHierarchyMultiLockTest( void ) { - cout << "Starting MultiThreadHierarchyMultiLockTest." << endl; - MultiLevelPool::MakePool( 10, thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -1128,8 +1093,6 @@ TestResults::Destroy(); MultiLevelPool::DestroyPool(); - - cout << "Finished MultiThreadHierarchyMultiLockTest." << endl; } // ---------------------------------------------------------------------------- Modified: trunk/test/LevelMutex/ThreadPool.cpp =================================================================== --- trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -20,7 +20,7 @@ #include <assert.h> -//#include <process.h> +#include <process.h> #if !defined( _MSC_VER ) #include <unistd.h> // needed for the usleep function. #endif @@ -86,13 +86,11 @@ bool Thread::WaitForThread( void ) volatile { assert( IsValid( m_owner ) ); - const volatile Thread * current = Thread::GetCurrentThread(); if ( this == current ) return false; if ( m_status == Thread::Dead ) return false; - while ( this->m_status == Thread::Active ) { // Call the wait policy. @@ -102,8 +100,6 @@ ::usleep( 1000 ); #endif } - - m_status = Thread::Idle; return true; } Modified: trunk/test/LevelMutex/main.cpp =================================================================== --- trunk/test/LevelMutex/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LevelMutex/main.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -48,8 +48,6 @@ void SingleThreadSimpleTest( void ) { - cout << "Starting SingleThreadSimpleTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -173,8 +171,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -182,8 +178,6 @@ void SingleThreadReentrantTest( void ) { - cout << "Starting SingleThreadReentrantTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -289,8 +283,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -298,8 +290,6 @@ void SingleThreadSimpleMultiLockTest( void ) { - cout << "Starting SingleThreadSimpleMultiLockTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -491,8 +481,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadSimpleMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -500,8 +488,6 @@ void SingleThreadExceptionTest( void ) { - cout << "Starting SingleThreadExceptionTest." << endl; - const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -650,8 +636,6 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); - - cout << "Finished SingleThreadExceptionTest." << endl; } // ---------------------------------------------------------------------------- @@ -676,7 +660,6 @@ MultiThreadSimpleTest(); MultiThreadTryLockTest(); - cout << "main 679" << endl; MultiThreadReentrantTest(); MultiThreadMultiLockTest(); MultiThreadRandomMultiLockTest(); Modified: trunk/test/LockingPtr/LockingPtr.cbp =================================================================== --- trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -3,27 +3,26 @@ <FileVersion major="1" minor="6" /> <Project> <Option title="LockingPtr" /> - <Option compiler="gcc" /> + <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="obj/Debug_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="obj\Debug_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> - <Add option="-g" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add option="-g" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki_D.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki_D.a" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj/Release_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="obj\Release_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -31,44 +30,43 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki.a" /> - <Add library="/usr/lib/libpthread.so" /> + <Add library="..\..\lib\GCC\Loki.a" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj/Debug_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_Cygwin/" /> + <Option output="obj\Debug_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_Cygwin\" /> <Option type="1" /> - <Option compiler="gcc" /> + <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki_D.a" /> + <Add library="..\..\lib\Cygwin\Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj/Release_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_Cygwin/" /> + <Option output="obj\Release_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_Cygwin\" /> <Option type="1" /> - <Option compiler="gcc" /> + <Option compiler="cygwin" /> <Compiler> <Add option="-fexpensive-optimizations" /> <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki.a" /> + <Add library="..\..\lib\Cygwin\Loki.a" /> </Linker> </Target> </Build> Modified: trunk/test/SmartPtr/SmartPtr.cbp =================================================================== --- trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -6,25 +6,23 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="bin/Debug_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="bin\Debug_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> - <Add option="-g" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add option="-g" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki_D.a" /> - <Add library="/usr/lib/libpthread.so" /> - <Add library="/usr/lib/libc.so" /> + <Add library="..\..\lib\GCC\Loki_D.a" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="bin/Release_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="bin\Release_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -32,33 +30,31 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/GCC/Loki.a" /> - <Add library="/usr/lib/libpthread.so" /> - <Add library="/usr/lib/libc.so" /> + <Add library="..\..\lib\GCC\Loki.a" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="bin/Debug_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_Cygwin/" /> + <Option output="bin\Debug_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki_D.a" /> + <Add library="..\..\lib\Cygwin\Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="bin/Release_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_Cygwin/" /> + <Option output="bin\Release_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_Cygwin\" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -66,11 +62,11 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="../../include/loki" /> - <Add directory="../../include" /> + <Add directory="..\..\include\loki" /> + <Add directory="..\..\include" /> </Compiler> <Linker> - <Add library="../../lib/Cygwin/Loki.a" /> + <Add library="..\..\lib\Cygwin\Loki.a" /> </Linker> </Target> </Build> @@ -78,7 +74,6 @@ <Unit filename="base.h"> <Option target="<{~None~}>" /> </Unit> - <Unit filename="colvin_gibbons_trick.cpp" /> <Unit filename="main.cpp" /> <Unit filename="strong.cpp" /> <Extensions> Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/base.h 2011-09-20 23:19:14 UTC (rev 1111) @@ -73,11 +73,10 @@ return s_destructions; } -protected: - BaseClass( const BaseClass & that ) : m_refCount( that.m_refCount ) {} - private: /// Not implemented. + BaseClass( const BaseClass & ); + /// Not implemented. BaseClass & operator = ( const BaseClass & ); static unsigned int s_constructions; @@ -111,45 +110,7 @@ } }; -// ---------------------------------------------------------------------------- -/** @class Feline - The feline family of classes are to test dynamic_cast. Also used to test - pointers to arrays of objects. - */ -class Feline : public BaseClass -{ -public: - virtual ~Feline() {} - virtual Feline * Clone( void ) const = 0; -}; - -class Lion : public Feline -{ -public: - virtual ~Lion() {} - virtual Lion * Clone( void ) const { return new Lion( *this ); } -}; - -class Tiger : public Feline -{ -public: - Tiger( void ) : m_stripes( 100 ) {} - virtual ~Tiger() {} - virtual Tiger * Clone( void ) const { return new Tiger( *this ); } - unsigned int GetStripes( void ) const { return m_stripes; } - void SetStripes( unsigned int s ) { m_stripes = s; } -private: - unsigned int m_stripes; -}; - -class Dog -{ -public: - virtual ~Dog() {} - virtual Dog * Clone( void ) const { return new Dog( *this ); } -}; - - // ---------------------------------------------------------------------------- /** @class MimicCOM Acts like a COM object by having an intrusive ref count. Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/main.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -1205,6 +1205,75 @@ // ---------------------------------------------------------------------------- +namespace +{ + + class Feline + { + public: + + static inline bool AllDestroyed( void ) + { + return ( s_constructions == s_destructions ); + } + + static inline bool ExtraConstructions( void ) + { + return ( s_constructions > s_destructions ); + } + + static inline bool ExtraDestructions( void ) + { + return ( s_constructions < s_destructions ); + } + + static inline unsigned int GetCtorCount( void ) + { + return s_constructions; + } + + static inline unsigned int GetDtorCount( void ) + { + return s_destructions; + } + + Feline( void ) { s_constructions++; } + virtual ~Feline() { s_destructions++; } + virtual Feline * Clone( void ) const = 0; + + private: + static unsigned int s_constructions; + static unsigned int s_destructions; + }; + + unsigned int Feline::s_constructions = 0; + unsigned int Feline::s_destructions = 0; + + class Tiger : public Feline + { + public: + virtual ~Tiger() {} + virtual Tiger * Clone( void ) const { return new Tiger( *this ); } + }; + + class Lion : public Feline + { + public: + virtual ~Lion() {} + virtual Lion * Clone( void ) const { return new Lion( *this ); } + }; + + class Dog + { + public: + virtual ~Dog() {} + virtual Dog * Clone( void ) const { return new Dog( *this ); } + }; + +} + +// ---------------------------------------------------------------------------- + void DoSmartPtrDynamicCastTests( void ) { cout << "Starting DoSmartPtrDynamicCastTests." << endl; @@ -1290,9 +1359,9 @@ assert( !pDog ); } - assert( BaseClass::AllDestroyed() ); - assert( !BaseClass::ExtraConstructions() ); - assert( !BaseClass::ExtraDestructions() ); + assert( Feline::AllDestroyed() ); + assert( !Feline::ExtraConstructions() ); + assert( !Feline::ExtraDestructions() ); cout << "Finished DoSmartPtrDynamicCastTests." << endl; } @@ -1449,161 +1518,6 @@ // ---------------------------------------------------------------------------- -/// Use these typedefs to test DeleteArray policy. - -typedef Loki::SmartPtr< Tiger, RefCounted, DisallowConversion, - AssertCheck, ArrayStorage, DontPropagateConst > - TigerArray_RefCounted_ptr; - -typedef Loki::SmartPtr< Tiger, RefLinked, DisallowConversion, - AssertCheck, ArrayStorage, DontPropagateConst > - TigerArray_2RefLinks_ptr; - -// ---------------------------------------------------------------------------- - -void DoSmartArrayTests( void ) -{ - cout << "Starting DoSmartArrayTests." << endl; - - { - // test default construction. - TigerArray_RefCounted_ptr sp1; - assert( !sp1 ); - assert( 0 == sp1.GetArrayCount() ); - - // test assignment. - sp1.Assign( new Tiger[ 8 ], 8 ); - assert( sp1 ); - assert( 8 == sp1.GetArrayCount() ); - sp1[ 0 ].SetStripes( 8 ); - sp1[ 1 ].SetStripes( 16 ); - sp1[ 2 ].SetStripes( 24 ); - sp1[ 3 ].SetStripes( 32 ); - sp1[ 4 ].SetStripes( 40); - sp1[ 5 ].SetStripes( 48 ); - sp1[ 6 ].SetStripes( 56 ); - sp1[ 7 ].SetStripes( 64 ); - - // test initialization construction. - TigerArray_RefCounted_ptr sp2( new Tiger[ 4 ], 4 ); - assert( sp2 ); - assert( 4 == sp2.GetArrayCount() ); - sp2[ 0 ].SetStripes( 5 ); - sp2[ 1 ].SetStripes( 10 ); - sp2[ 2 ].SetStripes( 15 ); - sp2[ 3 ].SetStripes( 20 ); - - // test range checking. - try - { - Tiger & p4 = sp2[ 4 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - // test range checking. - try - { - Tiger & p8 = sp1[ 8 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - // test swap. - sp2.Swap( sp1 ); - assert( sp1 ); - assert( sp2 ); - // test checking of item count. - assert( 4 == sp1.GetArrayCount() ); - assert( 8 == sp2.GetArrayCount() ); - - // test that operator[] returns reference to - assert( 5 == sp1[ 0 ].GetStripes() ); - assert( 10 == sp1[ 1 ].GetStripes() ); - assert( 15 == sp1[ 2 ].GetStripes() ); - assert( 20 == sp1[ 3 ].GetStripes() ); - assert( 8 == sp2[ 0 ].GetStripes() ); - assert( 16 == sp2[ 1 ].GetStripes() ); - assert( 24 == sp2[ 2 ].GetStripes() ); - assert( 32 == sp2[ 3 ].GetStripes() ); - assert( 40 == sp2[ 4 ].GetStripes() ); - assert( 48 == sp2[ 5 ].GetStripes() ); - assert( 56 == sp2[ 6 ].GetStripes() ); - assert( 64 == sp2[ 7 ].GetStripes() ); - - try - { - Tiger & p4 = sp1[ 4 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - try - { - Tiger & p8 = sp2[ 8 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - const TigerArray_RefCounted_ptr sp3( sp1 ); - assert( sp3 == sp1 ); - assert( sp3.GetArrayCount() == sp1.GetArrayCount() ); - try - { - const Tiger & p4 = sp3[ 4 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - const TigerArray_RefCounted_ptr sp5( sp2 ); - assert( sp5 == sp2 ); - assert( sp5.GetArrayCount() == sp2.GetArrayCount() ); - try - { - const Tiger & p8 = sp5[ 8 ]; - assert( false ); - } - catch ( const ::std::out_of_range & ex ) - { - assert( true ); - } - - sp2 = sp1; - assert( sp1 == sp2 ); - assert( sp3 == sp2 ); - assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); - assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); - assert( sp1 != sp5 ); - assert( sp2 != sp5 ); - assert( sp3 != sp5 ); - assert( sp1.GetArrayCount() != sp5.GetArrayCount() ); - assert( sp2.GetArrayCount() != sp5.GetArrayCount() ); - assert( sp3.GetArrayCount() != sp5.GetArrayCount() ); - } - - assert( BaseClass::AllDestroyed() ); - assert( !BaseClass::ExtraConstructions() ); - assert( !BaseClass::ExtraDestructions() ); - cout << "Finished DoSmartArrayTests." << endl; -} - -// ---------------------------------------------------------------------------- - int main( int argc, const char * argv[] ) { bool doThreadTest = false; @@ -1642,7 +1556,6 @@ DoSmartPtrDynamicCastTests(); DoStrongPtrDynamicCastTests(); DoStrongArrayTests(); - DoSmartArrayTests(); #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) if ( doThreadTest ) Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/SmartPtr/strong.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -1778,6 +1778,42 @@ // ---------------------------------------------------------------------------- +namespace +{ + + class Feline : public BaseClass + { + public: + virtual ~Feline() {} + }; + + class Lion : public Feline + { + public: + virtual ~Lion() {} + }; + + class Tiger : public Feline + { + public: + Tiger( void ) : m_stripes( 100 ) {} + virtual ~Tiger() {} + unsigned int GetStripes( void ) const { return m_stripes; } + void SetStripes( unsigned int s ) { m_stripes = s; } + private: + unsigned int m_stripes; + }; + + class Dog + { + public: + virtual ~Dog() {} + }; + +} + +// ---------------------------------------------------------------------------- + void DoStrongPtrDynamicCastTests( void ) { typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr; Modified: trunk/test/ThreadLocal/ThreadLocal.cbp =================================================================== --- trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 23:19:14 UTC (rev 1111) @@ -7,37 +7,28 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj/Debug_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Debug_GCC/" /> + <Option output="obj\Debug_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Debug_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-Wmain" /> <Add option="-pedantic" /> - <Add option="-g" /> <Add option="-W" /> - <Add directory="../../include" /> + <Add option="-g" /> + <Add directory="..\..\include" /> </Compiler> - <Linker> - <Add library="/usr/lib/libpthread.so" /> - <Add library="/usr/lib/libc.so" /> - </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj/Release_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj/Release_GCC/" /> + <Option output="obj\Release_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\Release_GCC\" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-O2" /> - <Add option="-Wmain" /> - <Add option="-pedantic" /> - <Add option="-W" /> - <Add directory="../../include" /> </Compiler> <Linker> <Add option="-s" /> - <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> </Build> @@ -50,7 +41,6 @@ <code_completion /> <debugger /> <lib_finder disable_auto="1" /> - <envvars /> </Extensions> </Project> </CodeBlocks_project_file> Modified: trunk/test/ThreadLocal/main.cpp =================================================================== --- trunk/test/ThreadLocal/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) +++ trunk/test/ThreadLocal/main.cpp 2011-09-20 23:19:14 UTC (rev 1111) @@ -26,8 +26,19 @@ #include <sstream> #include <iostream> -#include <stdlib.h> +using namespace ::std; + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + #if defined(_WIN32) #include <process.h> @@ -45,8 +56,6 @@ #else - #include <pthread.h> - #define LOKI_pthread_t \ pthread_t #define LOKI_pthread_create(handle,attr,func,arg) \ @@ -56,19 +65,6 @@ #endif - -using namespace ::std; - -#if !defined( NULL ) - #define NULL 0 -#endif - -// define nullptr even though new compilers will have this keyword just so we -// have a consistent and easy way of identifying which uses of 0 mean null. -#if !defined( nullptr ) - #define nullptr NULL -#endif - // ---------------------------------------------------------------------------- class Thread @@ -368,10 +364,7 @@ // ---------------------------------------------------------------------------- int main( int argc, const char * const argv[] ) -{ - (void)argc; - (void)argv; - +{ bool okay = true; cout << "Starting ThreadLocal tests." << endl; cout << "If any tests fail, or any assertions fail," << endl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 22:34:32
|
Revision: 1110 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1110&view=rev Author: rich_sposato Date: 2011-09-20 22:34:24 +0000 (Tue, 20 Sep 2011) Log Message: ----------- A little cleanup. Moved class to SmartPtr.cpp and SmartPtr.h files. Modified Paths: -------------- trunk/Loki.workspace trunk/include/loki/StrongPtr.h trunk/include/loki/ThreadLocal.h trunk/include/loki/flex/flex_string_shell.h trunk/src/StrongPtr.cpp trunk/test/LevelMutex/LevelMutex.cbp trunk/test/LevelMutex/MultiThreadTests.cpp trunk/test/LevelMutex/ThreadPool.cpp trunk/test/LevelMutex/main.cpp trunk/test/LockingPtr/LockingPtr.cbp trunk/test/SmartPtr/SmartPtr.cbp trunk/test/SmartPtr/base.h trunk/test/SmartPtr/main.cpp trunk/test/SmartPtr/strong.cpp trunk/test/ThreadLocal/ThreadLocal.cbp trunk/test/ThreadLocal/main.cpp Modified: trunk/Loki.workspace =================================================================== --- trunk/Loki.workspace 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/Loki.workspace 2011-09-20 22:34:24 UTC (rev 1110) @@ -2,46 +2,46 @@ <CodeBlocks_workspace_file> <Workspace title="Workspace"> <Project filename="Loki.cbp" active="1" /> - <Project filename="test\CachedFactory\CachedFactory.cbp"> + <Project filename="test/CachedFactory/CachedFactory.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Checker\Checker.cbp" /> - <Project filename="test\CheckReturn\CheckReturn.cbp" /> - <Project filename="test\DeletableSingleton\DeletableSingleton.cbp"> + <Project filename="test/Checker/Checker.cbp" /> + <Project filename="test/CheckReturn/CheckReturn.cbp" /> + <Project filename="test/DeletableSingleton/DeletableSingleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Factory\Factory.cbp" /> - <Project filename="test\flex_string\flex_string.cbp" /> - <Project filename="test\Function\Function.cbp" /> - <Project filename="test\LevelMutex\LevelMutex.cbp"> + <Project filename="test/Factory/Factory.cbp" /> + <Project filename="test/flex_string/flex_string.cbp" /> + <Project filename="test/Function/Function.cbp" /> + <Project filename="test/LevelMutex/LevelMutex.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\LockingPtr\LockingPtr.cbp" /> - <Project filename="test\Longevity\Longevity.cbp" /> - <Project filename="test\OrderedStatic\OrderedStatic.cbp"> + <Project filename="test/LockingPtr/LockingPtr.cbp" /> + <Project filename="test/Longevity/Longevity.cbp" /> + <Project filename="test/OrderedStatic/OrderedStatic.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Pimpl\Pimpl.cbp" /> - <Project filename="test\Register\Register.cbp" /> - <Project filename="test\RegressionTest\RegressionTest.cbp"> + <Project filename="test/Pimpl/Pimpl.cbp" /> + <Project filename="test/Register/Register.cbp" /> + <Project filename="test/RegressionTest/RegressionTest.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SafeFormat\SafeFormat.cbp"> + <Project filename="test/SafeFormat/SafeFormat.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\ScopeGuard\ScopeGuard.cbp" /> - <Project filename="test\Singleton\Singleton.cbp"> + <Project filename="test/ScopeGuard/ScopeGuard.cbp" /> + <Project filename="test/Singleton/Singleton.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SmallObj\SmallObj.cbp"> + <Project filename="test/SmallObj/SmallObj.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\SmallObj\DefaultAlloc.cbp" /> - <Project filename="test\SmartPtr\SmartPtr.cbp"> + <Project filename="test/SmallObj/DefaultAlloc.cbp" /> + <Project filename="test/SmartPtr/SmartPtr.cbp"> <Depends filename="Loki.cbp" /> </Project> - <Project filename="test\Visitor\Visitor.cbp" /> - <Project filename="test\SafeBits\SafeBits.cbp" /> - <Project filename="test\ThreadLocal\ThreadLocal.cbp" /> + <Project filename="test/Visitor/Visitor.cbp" /> + <Project filename="test/SafeBits/SafeBits.cbp" /> + <Project filename="test/ThreadLocal/ThreadLocal.cbp" /> </Workspace> </CodeBlocks_workspace_file> Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/include/loki/StrongPtr.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -85,7 +85,10 @@ /// If you write your own policy, you must implement these 3 functions: /// -# void static Delete( const P * p ) /// -# static P * Default( void ) -/// -# void Swap( YourResetPolicy & ) +/// -# Default constructor. +/// -# Copy constructor. +/// -# Templated copy constructor. +/// -# void Swap( YourDeletePolicy & ) /// /// \par ResetPolicy /// A reset policy tells the ReleaseAll and ResetAll functions whether they @@ -235,46 +238,7 @@ inline void Swap( DeleteSingle & ) {} }; -namespace Private -{ - //////////////////////////////////////////////////////////////////////////////// -/// \class DeleteArrayBase -/// -/// \ingroup StrongPointerDeleteGroup -/// Base class used only by the DeleteArray policy class. This stores the -/// number of elements in an array of shared objects. -//////////////////////////////////////////////////////////////////////////////// - -class DeleteArrayBase -{ -public: - - inline size_t GetArrayCount( void ) const { return m_itemCount; } - -protected: - - DeleteArrayBase( void ) : m_itemCount( 0 ) {} - - explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} - - DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} - - void Swap( DeleteArrayBase & rhs ); - - void OnInit( const void * p ) const; - - void OnCheckRange( size_t index ) const; - -private: - - size_t m_itemCount; - -}; - -} - -//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -2068,19 +2032,27 @@ return * GetPointer(); } + /** operator[] returns a reference to an modifiable object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ReferenceType operator [] ( size_t index ) { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); PointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } + /** operator[] returns a reference to a const object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ ConstReferenceType operator [] ( size_t index ) const { - KP::OnDereference( GetPointer() ); - DP::OnCheckRange( index ); ConstPointerType p = GetPointer(); + KP::OnDereference( p ); + DP::OnCheckRange( index ); return p[ index ]; } Modified: trunk/include/loki/ThreadLocal.h =================================================================== --- trunk/include/loki/ThreadLocal.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/include/loki/ThreadLocal.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -28,21 +28,29 @@ // The __APPLE__ macro does not refer to a compiler, but to the Apple OSX operating system. #if defined( __APPLE__ ) #warning "GCC for Apple does not allow thread_local storage, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #elif defined( __CYGWIN__ ) #if ( __GNUC__ <= 3 ) #warning "Older versions of GCC for Cygwin do not allow thread_local storage, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE #endif #elif ( __GNUC__ == 4 ) // GNU versions other than Cygwin. - #if ( __GNUC_MINOR__ == 4 ) - #warning "GCC version 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." - #undef COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #if ( __GNUC_MINOR__ < 4 ) + #warning "GCC versions before 4.4 implements thread_local storage incorrectly, so you can not use some parts of Loki." + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #else + #warning "Versions 4.4 through 4.6 of GCC implemented thread_local storage for some platforms, but not others. Run ThreadLocal test project." #endif #endif -#endif + +#elif defined( _MSC_VER ) + #if ( _MSC_VER < 1300 ) + #warning "Only Visual Studio versions 7.0 and after support thread local storage properly, so you can not use some parts of Loki." + #undef LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE + #endif +#endif #if defined( LOKI_THINKS_COMPILER_ALLOWS_THREAD_LOCAL_STORAGE ) && !defined( LOKI_THREAD_LOCAL ) @@ -57,11 +65,7 @@ you can't use some parts of Loki. */ #if defined( _MSC_VER ) - #if ( _MSC_VER >= 1300 ) - #define LOKI_THREAD_LOCAL __declspec( thread ) - #else - #error "Only Visual Studio versions 7.0 and after supported." - #endif + #define LOKI_THREAD_LOCAL __declspec( thread ) #elif ( __GNUC__ ) #define LOKI_THREAD_LOCAL __thread Modified: trunk/include/loki/flex/flex_string_shell.h =================================================================== --- trunk/include/loki/flex/flex_string_shell.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/include/loki/flex/flex_string_shell.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -1339,17 +1339,17 @@ typename flex_string<E, T, A, S>::value_type delim) { size_t nread = 0; - typename basic_istream<typename flex_string<E, T, A, S>::value_type, + typename std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>::sentry sentry(is, true); if (sentry) { - basic_streambuf<typename flex_string<E, T, A, S>::value_type, + ::std::basic_streambuf<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>* buf = is.rdbuf(); str.clear(); while (nread < str.max_size()) { int c1 = buf->sbumpc(); if (flex_string<E, T, A, S>::traits_type::eq_int_type(c1, flex_string<E, T, A, S>::traits_type::eof())) { - is.setstate(ios_base::eofbit); + is.setstate(::std::ios_base::eofbit); break; } else { @@ -1363,7 +1363,7 @@ } } if (nread == 0 || nread >= str.max_size()) - is.setstate(ios_base::failbit); + is.setstate(::std::ios_base::failbit); return is; } Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/src/StrongPtr.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -15,9 +15,6 @@ #include <loki/StrongPtr.h> -#include <stdexcept> -#include <string> - #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -41,45 +38,6 @@ // ---------------------------------------------------------------------------- -void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) -{ - assert( NULL != this ); - - const size_t temp = m_itemCount; - m_itemCount = rhs.m_itemCount; - rhs.m_itemCount = temp; -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnInit( const void * p ) const -{ - assert( NULL != this ); - if ( NULL == p ) - { - assert( 0 == m_itemCount ); - } - else - { - assert( 0 < m_itemCount ); - } -} - -// ---------------------------------------------------------------------------- - -void DeleteArrayBase::OnCheckRange( size_t index ) const -{ - assert( NULL != this ); - - if ( index < m_itemCount ) - return; - - const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); - throw ::std::out_of_range( message ); -} - -// ---------------------------------------------------------------------------- - OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) Modified: trunk/test/LevelMutex/LevelMutex.cbp =================================================================== --- trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/LevelMutex.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -6,24 +6,24 @@ <Option compiler="cygwin" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -31,33 +31,33 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/GCC/Loki.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj\Debug_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="obj/Debug_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> + <Add library="../../../PThreads/lib/pthreadVC2.lib" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj\Release_Cygwin\LevelMutex" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="obj/Release_Cygwin/LevelMutex" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -65,12 +65,12 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include" /> - <Add directory="..\..\include\loki" /> + <Add directory="../../include" /> + <Add directory="../../include/loki" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> - <Add library="..\..\..\PThreads\lib\pthreadVC2.lib" /> + <Add library="../../lib/Cygwin/Loki.a" /> + <Add library="../../../PThreads/lib/pthreadVC2.lib" /> </Linker> </Target> </Build> Modified: trunk/test/LevelMutex/MultiThreadTests.cpp =================================================================== --- trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/MultiThreadTests.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -4,9 +4,9 @@ // Copyright (c) 2008, 2009 Richard Sposato // The copyright on this file is protected under the terms of the MIT license. // -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // // The author makes no representations about the suitability of this software @@ -22,7 +22,7 @@ #include "MultiThreadTests.hpp" #include <assert.h> -#include <process.h> +//#include <process.h> #include <stdlib.h> #include <time.h> @@ -239,6 +239,8 @@ void MultiThreadSimpleTest( void ) { + cout << "Starting MultiThreadSimpleTest." << endl; + Thing::Init( 0 ); const unsigned int threadCount = 5; ThreadPool pool( threadCount ); @@ -262,6 +264,8 @@ pool.JoinAll(); Thing::Destroy(); + + cout << "Finished MultiThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -299,13 +303,17 @@ void MultiThreadTryLockTest( void ) { + cout << "Starting MultiThreadTryLockTest." << endl; + static const unsigned int threadCount = 3; Thing::Init( 0 ); volatile Thing & thing = Thing::GetIt(); volatile SleepMutex & mutex = thing.GetMutex(); cout << endl << "Doing multi-threaded TryLock test. This test should not deadlock." << endl; - ::system( "pause" ); + cout << "Press enter key to continue." << endl; + char theKey = 0; + cin.get( theKey ); // First step is to lock the mutex in the main thread so no child thread // can ever lock it, change the value, or anything like that. MutexErrors::Type result = mutex.Lock(); @@ -313,36 +321,46 @@ bool okay = mutex.IsLockedByCurrentThread(); assert( okay ); thing.SetValue( threadCount ); - ThreadPool pool( threadCount ); - for ( unsigned int ii = 0; ii < threadCount; ++ii ) + { - void * p = reinterpret_cast< void * >( ii ); - pool.Start( TryLockThread, p ); + ThreadPool pool( threadCount ); + for ( unsigned int ii = 0; ii < threadCount; ++ii ) + { + void * p = reinterpret_cast< void * >( ii ); + pool.Start( TryLockThread, p ); + } + pool.JoinAll(); } - pool.JoinAll(); - const unsigned int value = thing.GetValue(); - assert( value == threadCount ); - result = mutex.Unlock(); - assert( MutexErrors::Success == result ); - okay = !mutex.IsLockedByCurrentThread(); - assert( okay ); - okay = !mutex.IsLocked(); - assert( okay ); + const unsigned int value = thing.GetValue(); + assert( value == threadCount ); + result = mutex.Unlock(); + assert( MutexErrors::Success == result ); + okay = !mutex.IsLockedByCurrentThread(); + assert( okay ); + okay = !mutex.IsLocked(); + assert( okay ); + Thing::Destroy(); + + cout << "Finished MultiThreadTryLockTest." << endl; } // ---------------------------------------------------------------------------- void MultiThreadReentrantTest( void ) { + cout << "Starting MultiThreadReentrantTest." << endl; + Thing::Init( 0 ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); ThreadPool pool( threadCount ); cout << endl << "Doing thread-safe value test. This test should pass and not deadlock." << endl; - ::system( "pause" ); + cout << "Press enter key to continue." << endl; + char theKey = 0; + cin.get( theKey ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -352,7 +370,8 @@ TestResults::GetIt()->OutputResults(); cout << endl << "Doing thread-unsafe value test. This test may fail." << endl; - ::system( "pause" ); + cout << "Press enter key to continue." << endl; + cin.get( theKey ); for ( unsigned int ii = 0; ii < threadCount; ++ii ) { void * p = reinterpret_cast< void * >( ii ); @@ -363,6 +382,8 @@ TestResults::Destroy(); Thing::Destroy(); + + cout << "Finished MultiThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -646,6 +667,8 @@ void MultiThreadMultiLockTest( void ) { + cout << "Starting MultiThreadMultiLockTest." << endl; + Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -674,6 +697,8 @@ TestResults::Destroy(); Thing::DestroyPool(); + + cout << "Finished MultiThreadMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -808,6 +833,8 @@ void MultiThreadRandomMultiLockTest( void ) { + cout << "Starting MultiThreadRandomMultiLockTest." << endl; + Thing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -836,6 +863,8 @@ TestResults::Destroy(); Thing::DestroyPool(); + + cout << "Finished MultiThreadRandomMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -936,6 +965,8 @@ void MultiThreadHierarchySingleLockTest( void ) { + cout << "Starting MultiThreadHierarchySingleLockTest." << endl; + LevelThing::MakePool( thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -964,6 +995,8 @@ TestResults::Destroy(); LevelThing::DestroyPool(); + + cout << "Finished MultiThreadHierarchySingleLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -1065,6 +1098,8 @@ void MultiThreadHierarchyMultiLockTest( void ) { + cout << "Starting MultiThreadHierarchyMultiLockTest." << endl; + MultiLevelPool::MakePool( 10, thingCount ); const unsigned int threadCount = 8; TestResults::Create( threadCount ); @@ -1093,6 +1128,8 @@ TestResults::Destroy(); MultiLevelPool::DestroyPool(); + + cout << "Finished MultiThreadHierarchyMultiLockTest." << endl; } // ---------------------------------------------------------------------------- Modified: trunk/test/LevelMutex/ThreadPool.cpp =================================================================== --- trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/ThreadPool.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -20,7 +20,7 @@ #include <assert.h> -#include <process.h> +//#include <process.h> #if !defined( _MSC_VER ) #include <unistd.h> // needed for the usleep function. #endif @@ -86,11 +86,13 @@ bool Thread::WaitForThread( void ) volatile { assert( IsValid( m_owner ) ); + const volatile Thread * current = Thread::GetCurrentThread(); if ( this == current ) return false; if ( m_status == Thread::Dead ) return false; + while ( this->m_status == Thread::Active ) { // Call the wait policy. @@ -100,6 +102,8 @@ ::usleep( 1000 ); #endif } + + m_status = Thread::Idle; return true; } Modified: trunk/test/LevelMutex/main.cpp =================================================================== --- trunk/test/LevelMutex/main.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LevelMutex/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -48,6 +48,8 @@ void SingleThreadSimpleTest( void ) { + cout << "Starting SingleThreadSimpleTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -171,6 +173,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadSimpleTest." << endl; } // ---------------------------------------------------------------------------- @@ -178,6 +182,8 @@ void SingleThreadReentrantTest( void ) { + cout << "Starting SingleThreadReentrantTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -283,6 +289,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadReentrantTest." << endl; } // ---------------------------------------------------------------------------- @@ -290,6 +298,8 @@ void SingleThreadSimpleMultiLockTest( void ) { + cout << "Starting SingleThreadSimpleMultiLockTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -481,6 +491,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadSimpleMultiLockTest." << endl; } // ---------------------------------------------------------------------------- @@ -488,6 +500,8 @@ void SingleThreadExceptionTest( void ) { + cout << "Starting SingleThreadExceptionTest." << endl; + const unsigned int priorLevel = GetCurrentThreadsLevel(); const unsigned int priorLockCount = CountLocksInCurrentThread(); const unsigned int priorMutexCount = CountMutexesInCurrentThread(); @@ -636,6 +650,8 @@ assert( okay ); okay = ( CountMutexesAtCurrentLevel() == priorLevelMutexCount ); assert( okay ); + + cout << "Finished SingleThreadExceptionTest." << endl; } // ---------------------------------------------------------------------------- @@ -660,6 +676,7 @@ MultiThreadSimpleTest(); MultiThreadTryLockTest(); + cout << "main 679" << endl; MultiThreadReentrantTest(); MultiThreadMultiLockTest(); MultiThreadRandomMultiLockTest(); Modified: trunk/test/LockingPtr/LockingPtr.cbp =================================================================== --- trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/LockingPtr/LockingPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -3,26 +3,27 @@ <FileVersion major="1" minor="6" /> <Project> <Option title="LockingPtr" /> - <Option compiler="cygwin" /> + <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -30,43 +31,44 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="../../lib/GCC/Loki.a" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="obj\Debug_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="obj/Debug_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> - <Option compiler="cygwin" /> + <Option compiler="gcc" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="obj\Release_Cygwin\LockingPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="obj/Release_Cygwin/LockingPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> - <Option compiler="cygwin" /> + <Option compiler="gcc" /> <Compiler> <Add option="-fexpensive-optimizations" /> <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="../../lib/Cygwin/Loki.a" /> </Linker> </Target> </Build> Modified: trunk/test/SmartPtr/SmartPtr.cbp =================================================================== --- trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/SmartPtr.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -6,23 +6,25 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="bin\Debug_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="bin/Debug_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki_D.a" /> + <Add library="../../lib/GCC/Loki_D.a" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> </Linker> </Target> <Target title="Release_GCC"> - <Option output="bin\Release_GCC\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="bin/Release_GCC/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> @@ -30,31 +32,33 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\GCC\Loki.a" /> + <Add library="../../lib/GCC/Loki.a" /> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> </Linker> </Target> <Target title="Debug_Cygwin"> - <Option output="bin\Debug_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_Cygwin\" /> + <Option output="bin/Debug_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> <Add option="-W" /> <Add option="-g" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki_D.a" /> + <Add library="../../lib/Cygwin/Loki_D.a" /> </Linker> </Target> <Target title="Release_Cygwin"> - <Option output="bin\Release_Cygwin\SmartPtr" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_Cygwin\" /> + <Option output="bin/Release_Cygwin/SmartPtr" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_Cygwin/" /> <Option type="1" /> <Option compiler="cygwin" /> <Compiler> @@ -62,11 +66,11 @@ <Add option="-Os" /> <Add option="-O3" /> <Add option="-W" /> - <Add directory="..\..\include\loki" /> - <Add directory="..\..\include" /> + <Add directory="../../include/loki" /> + <Add directory="../../include" /> </Compiler> <Linker> - <Add library="..\..\lib\Cygwin\Loki.a" /> + <Add library="../../lib/Cygwin/Loki.a" /> </Linker> </Target> </Build> @@ -74,6 +78,7 @@ <Unit filename="base.h"> <Option target="<{~None~}>" /> </Unit> + <Unit filename="colvin_gibbons_trick.cpp" /> <Unit filename="main.cpp" /> <Unit filename="strong.cpp" /> <Extensions> Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/base.h 2011-09-20 22:34:24 UTC (rev 1110) @@ -73,10 +73,11 @@ return s_destructions; } +protected: + BaseClass( const BaseClass & that ) : m_refCount( that.m_refCount ) {} + private: /// Not implemented. - BaseClass( const BaseClass & ); - /// Not implemented. BaseClass & operator = ( const BaseClass & ); static unsigned int s_constructions; @@ -110,7 +111,45 @@ } }; +// ---------------------------------------------------------------------------- +/** @class Feline - The feline family of classes are to test dynamic_cast. Also used to test + pointers to arrays of objects. + */ +class Feline : public BaseClass +{ +public: + virtual ~Feline() {} + virtual Feline * Clone( void ) const = 0; +}; + +class Lion : public Feline +{ +public: + virtual ~Lion() {} + virtual Lion * Clone( void ) const { return new Lion( *this ); } +}; + +class Tiger : public Feline +{ +public: + Tiger( void ) : m_stripes( 100 ) {} + virtual ~Tiger() {} + virtual Tiger * Clone( void ) const { return new Tiger( *this ); } + unsigned int GetStripes( void ) const { return m_stripes; } + void SetStripes( unsigned int s ) { m_stripes = s; } +private: + unsigned int m_stripes; +}; + +class Dog +{ +public: + virtual ~Dog() {} + virtual Dog * Clone( void ) const { return new Dog( *this ); } +}; + + // ---------------------------------------------------------------------------- /** @class MimicCOM Acts like a COM object by having an intrusive ref count. Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -1205,75 +1205,6 @@ // ---------------------------------------------------------------------------- -namespace -{ - - class Feline - { - public: - - static inline bool AllDestroyed( void ) - { - return ( s_constructions == s_destructions ); - } - - static inline bool ExtraConstructions( void ) - { - return ( s_constructions > s_destructions ); - } - - static inline bool ExtraDestructions( void ) - { - return ( s_constructions < s_destructions ); - } - - static inline unsigned int GetCtorCount( void ) - { - return s_constructions; - } - - static inline unsigned int GetDtorCount( void ) - { - return s_destructions; - } - - Feline( void ) { s_constructions++; } - virtual ~Feline() { s_destructions++; } - virtual Feline * Clone( void ) const = 0; - - private: - static unsigned int s_constructions; - static unsigned int s_destructions; - }; - - unsigned int Feline::s_constructions = 0; - unsigned int Feline::s_destructions = 0; - - class Tiger : public Feline - { - public: - virtual ~Tiger() {} - virtual Tiger * Clone( void ) const { return new Tiger( *this ); } - }; - - class Lion : public Feline - { - public: - virtual ~Lion() {} - virtual Lion * Clone( void ) const { return new Lion( *this ); } - }; - - class Dog - { - public: - virtual ~Dog() {} - virtual Dog * Clone( void ) const { return new Dog( *this ); } - }; - -} - -// ---------------------------------------------------------------------------- - void DoSmartPtrDynamicCastTests( void ) { cout << "Starting DoSmartPtrDynamicCastTests." << endl; @@ -1359,9 +1290,9 @@ assert( !pDog ); } - assert( Feline::AllDestroyed() ); - assert( !Feline::ExtraConstructions() ); - assert( !Feline::ExtraDestructions() ); + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); cout << "Finished DoSmartPtrDynamicCastTests." << endl; } @@ -1518,6 +1449,161 @@ // ---------------------------------------------------------------------------- +/// Use these typedefs to test DeleteArray policy. + +typedef Loki::SmartPtr< Tiger, RefCounted, DisallowConversion, + AssertCheck, ArrayStorage, DontPropagateConst > + TigerArray_RefCounted_ptr; + +typedef Loki::SmartPtr< Tiger, RefLinked, DisallowConversion, + AssertCheck, ArrayStorage, DontPropagateConst > + TigerArray_2RefLinks_ptr; + +// ---------------------------------------------------------------------------- + +void DoSmartArrayTests( void ) +{ + cout << "Starting DoSmartArrayTests." << endl; + + { + // test default construction. + TigerArray_RefCounted_ptr sp1; + assert( !sp1 ); + assert( 0 == sp1.GetArrayCount() ); + + // test assignment. + sp1.Assign( new Tiger[ 8 ], 8 ); + assert( sp1 ); + assert( 8 == sp1.GetArrayCount() ); + sp1[ 0 ].SetStripes( 8 ); + sp1[ 1 ].SetStripes( 16 ); + sp1[ 2 ].SetStripes( 24 ); + sp1[ 3 ].SetStripes( 32 ); + sp1[ 4 ].SetStripes( 40); + sp1[ 5 ].SetStripes( 48 ); + sp1[ 6 ].SetStripes( 56 ); + sp1[ 7 ].SetStripes( 64 ); + + // test initialization construction. + TigerArray_RefCounted_ptr sp2( new Tiger[ 4 ], 4 ); + assert( sp2 ); + assert( 4 == sp2.GetArrayCount() ); + sp2[ 0 ].SetStripes( 5 ); + sp2[ 1 ].SetStripes( 10 ); + sp2[ 2 ].SetStripes( 15 ); + sp2[ 3 ].SetStripes( 20 ); + + // test range checking. + try + { + Tiger & p4 = sp2[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test range checking. + try + { + Tiger & p8 = sp1[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test swap. + sp2.Swap( sp1 ); + assert( sp1 ); + assert( sp2 ); + // test checking of item count. + assert( 4 == sp1.GetArrayCount() ); + assert( 8 == sp2.GetArrayCount() ); + + // test that operator[] returns reference to + assert( 5 == sp1[ 0 ].GetStripes() ); + assert( 10 == sp1[ 1 ].GetStripes() ); + assert( 15 == sp1[ 2 ].GetStripes() ); + assert( 20 == sp1[ 3 ].GetStripes() ); + assert( 8 == sp2[ 0 ].GetStripes() ); + assert( 16 == sp2[ 1 ].GetStripes() ); + assert( 24 == sp2[ 2 ].GetStripes() ); + assert( 32 == sp2[ 3 ].GetStripes() ); + assert( 40 == sp2[ 4 ].GetStripes() ); + assert( 48 == sp2[ 5 ].GetStripes() ); + assert( 56 == sp2[ 6 ].GetStripes() ); + assert( 64 == sp2[ 7 ].GetStripes() ); + + try + { + Tiger & p4 = sp1[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + try + { + Tiger & p8 = sp2[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_RefCounted_ptr sp3( sp1 ); + assert( sp3 == sp1 ); + assert( sp3.GetArrayCount() == sp1.GetArrayCount() ); + try + { + const Tiger & p4 = sp3[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_RefCounted_ptr sp5( sp2 ); + assert( sp5 == sp2 ); + assert( sp5.GetArrayCount() == sp2.GetArrayCount() ); + try + { + const Tiger & p8 = sp5[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + sp2 = sp1; + assert( sp1 == sp2 ); + assert( sp3 == sp2 ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp1 != sp5 ); + assert( sp2 != sp5 ); + assert( sp3 != sp5 ); + assert( sp1.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp2.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp3.GetArrayCount() != sp5.GetArrayCount() ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoSmartArrayTests." << endl; +} + +// ---------------------------------------------------------------------------- + int main( int argc, const char * argv[] ) { bool doThreadTest = false; @@ -1556,6 +1642,7 @@ DoSmartPtrDynamicCastTests(); DoStrongPtrDynamicCastTests(); DoStrongArrayTests(); + DoSmartArrayTests(); #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) if ( doThreadTest ) Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/SmartPtr/strong.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -1778,42 +1778,6 @@ // ---------------------------------------------------------------------------- -namespace -{ - - class Feline : public BaseClass - { - public: - virtual ~Feline() {} - }; - - class Lion : public Feline - { - public: - virtual ~Lion() {} - }; - - class Tiger : public Feline - { - public: - Tiger( void ) : m_stripes( 100 ) {} - virtual ~Tiger() {} - unsigned int GetStripes( void ) const { return m_stripes; } - void SetStripes( unsigned int s ) { m_stripes = s; } - private: - unsigned int m_stripes; - }; - - class Dog - { - public: - virtual ~Dog() {} - }; - -} - -// ---------------------------------------------------------------------------- - void DoStrongPtrDynamicCastTests( void ) { typedef ::Loki::StrongPtr< Feline, true, ::Loki::TwoRefCounts > FelineCountPtr; Modified: trunk/test/ThreadLocal/ThreadLocal.cbp =================================================================== --- trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/ThreadLocal/ThreadLocal.cbp 2011-09-20 22:34:24 UTC (rev 1110) @@ -7,28 +7,37 @@ <Option compiler="gcc" /> <Build> <Target title="Debug_GCC"> - <Option output="obj\Debug_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Debug_GCC\" /> + <Option output="obj/Debug_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Debug_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-Wmain" /> <Add option="-pedantic" /> + <Add option="-g" /> <Add option="-W" /> - <Add option="-g" /> - <Add directory="..\..\include" /> + <Add directory="../../include" /> </Compiler> + <Linker> + <Add library="/usr/lib/libpthread.so" /> + <Add library="/usr/lib/libc.so" /> + </Linker> </Target> <Target title="Release_GCC"> - <Option output="obj\Release_GCC\ThreadLocal" prefix_auto="1" extension_auto="1" /> - <Option object_output="obj\Release_GCC\" /> + <Option output="obj/Release_GCC/ThreadLocal" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj/Release_GCC/" /> <Option type="1" /> <Option compiler="gcc" /> <Compiler> <Add option="-O2" /> + <Add option="-Wmain" /> + <Add option="-pedantic" /> + <Add option="-W" /> + <Add directory="../../include" /> </Compiler> <Linker> <Add option="-s" /> + <Add library="/usr/lib/libpthread.so" /> </Linker> </Target> </Build> @@ -41,6 +50,7 @@ <code_completion /> <debugger /> <lib_finder disable_auto="1" /> + <envvars /> </Extensions> </Project> </CodeBlocks_project_file> Modified: trunk/test/ThreadLocal/main.cpp =================================================================== --- trunk/test/ThreadLocal/main.cpp 2011-09-20 22:33:34 UTC (rev 1109) +++ trunk/test/ThreadLocal/main.cpp 2011-09-20 22:34:24 UTC (rev 1110) @@ -26,19 +26,8 @@ #include <sstream> #include <iostream> +#include <stdlib.h> -using namespace ::std; - -#if !defined( NULL ) - #define NULL 0 -#endif - -// define nullptr even though new compilers will have this keyword just so we -// have a consistent and easy way of identifying which uses of 0 mean null. -#if !defined( nullptr ) - #define nullptr NULL -#endif - #if defined(_WIN32) #include <process.h> @@ -56,6 +45,8 @@ #else + #include <pthread.h> + #define LOKI_pthread_t \ pthread_t #define LOKI_pthread_create(handle,attr,func,arg) \ @@ -65,6 +56,19 @@ #endif + +using namespace ::std; + +#if !defined( NULL ) + #define NULL 0 +#endif + +// define nullptr even though new compilers will have this keyword just so we +// have a consistent and easy way of identifying which uses of 0 mean null. +#if !defined( nullptr ) + #define nullptr NULL +#endif + // ---------------------------------------------------------------------------- class Thread @@ -364,7 +368,10 @@ // ---------------------------------------------------------------------------- int main( int argc, const char * const argv[] ) -{ +{ + (void)argc; + (void)argv; + bool okay = true; cout << "Starting ThreadLocal tests." << endl; cout << "If any tests fail, or any assertions fail," << endl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 22:33:40
|
Revision: 1109 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1109&view=rev Author: rich_sposato Date: 2011-09-20 22:33:34 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added array handling to SmartPtr. Modified Paths: -------------- trunk/include/loki/SmartPtr.h trunk/src/SmartPtr.cpp Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-20 18:38:13 UTC (rev 1108) +++ trunk/include/loki/SmartPtr.h 2011-09-20 22:33:34 UTC (rev 1109) @@ -355,7 +355,46 @@ inline typename LockedStorage<T>::StoredType& GetImplRef(LockedStorage<T>& sp) { return sp.pointee_; } + namespace Private + { + //////////////////////////////////////////////////////////////////////////////// + /// \class DeleteArrayBase + /// + /// \ingroup StrongPointerDeleteGroup + /// Base class used only by the DeleteArray policy class. This stores the + /// number of elements in an array of shared objects. + //////////////////////////////////////////////////////////////////////////////// + + class DeleteArrayBase + { + public: + + inline size_t GetArrayCount( void ) const { return m_itemCount; } + + protected: + + DeleteArrayBase( void ) : m_itemCount( 0 ) {} + + explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} + + DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} + + void Swap( DeleteArrayBase & rhs ); + + void OnInit( const void * p ) const; + + void OnCheckRange( size_t index ) const; + + private: + + size_t m_itemCount; + + }; + + } + + //////////////////////////////////////////////////////////////////////////////// /// \class ArrayStorage /// @@ -365,7 +404,7 @@ template <class T> - class ArrayStorage + class ArrayStorage : public ::Loki::Private::DeleteArrayBase { public: @@ -376,26 +415,30 @@ protected: - ArrayStorage() : pointee_(Default()) + ArrayStorage() : DeleteArrayBase(), pointee_(Default()) {} // The storage policy doesn't initialize the stored pointer // which will be initialized by the OwnershipPolicy's Clone fn - ArrayStorage(const ArrayStorage&) : pointee_(0) + ArrayStorage( const ArrayStorage & that ) : DeleteArrayBase( that ), pointee_( 0 ) {} template <class U> - ArrayStorage(const ArrayStorage<U>&) : pointee_(0) + ArrayStorage( const ArrayStorage< U >& that ) : DeleteArrayBase( that ), pointee_( 0 ) {} - explicit ArrayStorage(const StoredType& p) : pointee_(p) {} + ArrayStorage( const StoredType & p, size_t count ) : DeleteArrayBase( count ), + pointee_( p ) {} PointerType operator->() const { return pointee_; } ReferenceType operator*() const { return *pointee_; } - void Swap(ArrayStorage& rhs) - { std::swap(pointee_, rhs.pointee_); } + void Swap( ArrayStorage & rhs ) + { + DeleteArrayBase::Swap( rhs ); + ::std::swap( pointee_, rhs.pointee_ ); + } // Accessors template <class F> @@ -844,6 +887,8 @@ NoCheck() {} + NoCheck( const NoCheck & ) {} + template <class P1> NoCheck(const NoCheck<P1>&) {} @@ -878,6 +923,8 @@ AssertCheck() {} + AssertCheck( const AssertCheck & ) {} + template <class P1> AssertCheck(const AssertCheck<P1>&) {} @@ -916,6 +963,8 @@ AssertCheckStrict() {} + AssertCheckStrict( const AssertCheckStrict & ) {} + template <class U> AssertCheckStrict(const AssertCheckStrict<U>&) {} @@ -972,6 +1021,8 @@ RejectNullStatic() {} + RejectNullStatic( const RejectNullStatic & ) {} + template <class P1> RejectNullStatic(const RejectNullStatic<P1>&) {} @@ -1022,6 +1073,8 @@ RejectNull() {} + RejectNull( const RejectNull & ) {} + template <class P1> RejectNull(const RejectNull<P1>&) {} @@ -1058,6 +1111,8 @@ RejectNullStrict() {} + RejectNullStrict( const RejectNullStrict & ) {} + template <class P1> RejectNullStrict(const RejectNullStrict<P1>&) {} @@ -1245,6 +1300,16 @@ KP::OnInit(GetImpl(*this)); } + /** This constructor was designed to only work with the ArrayStorage policy. Using it with + any other Delete policies will cause compiler errors. Call it with this syntax: + "ThingyPtr sp2( new Thingy[ 4 ], 4 );" so SmartPtr can do range checking on the number of elements. + */ + SmartPtr( ImplicitArg p, size_t itemCount ) : SP( p, itemCount ) + { + KP::OnInit( GetImpl( *this ) ); + SP::OnInit( GetImpl( *this ) ); + } + SmartPtr(CopyArg& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { KP::OnDereference( GetImpl( rhs ) ); @@ -1333,6 +1398,21 @@ return *this; } + /** This function is equivalent to an assignment operator for SmartPtr's that use the + DeleteArray policy where the programmer needs to write the equivalent of "sp = new P;". + With DeleteArray, the programmer should write "sp.Assign( new [5] Thingy, 5 );" so the + SmartPtr knows how many elements are in the array. + */ + SmartPtr & Assign( T * p, size_t itemCount ) + { + if ( GetImpl( *this ) != p ) + { + SmartPtr temp( p, itemCount ); + Swap( temp ); + } + return *this; + } + void Swap(SmartPtr& rhs) { OP::Swap(rhs); @@ -1465,6 +1545,30 @@ return SP::operator*(); } + /** operator[] returns a reference to an modifiable object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ + ReferenceType operator [] ( size_t index ) + { + PointerType p = SP::operator->(); + KP::OnDereference( p ); + SP::OnCheckRange( index ); + return p[ index ]; + } + + /** operator[] returns a reference to a const object. If the index is greater than or + equal to the number of elements, the function will throw a std::out_of_range exception. + This only works with DeleteArray policy. Any other policy will cause a compiler error. + */ + ConstReferenceType operator [] ( size_t index ) const + { + ConstPointerType p = SP::operator->(); + KP::OnDereference( p ); + SP::OnCheckRange( index ); + return p[ index ]; + } + bool operator!() const // Enables "if (!sp) ..." { return GetImpl(*this) == 0; } Modified: trunk/src/SmartPtr.cpp =================================================================== --- trunk/src/SmartPtr.cpp 2011-09-20 18:38:13 UTC (rev 1108) +++ trunk/src/SmartPtr.cpp 2011-09-20 22:33:34 UTC (rev 1109) @@ -21,6 +21,9 @@ #include <cassert> +#include <stdexcept> +#include <string> + //#define DO_EXTRA_LOKI_TESTS #ifdef DO_EXTRA_LOKI_TESTS #include <iostream> @@ -37,6 +40,45 @@ // ---------------------------------------------------------------------------- +void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) +{ + assert( NULL != this ); + + const size_t temp = m_itemCount; + m_itemCount = rhs.m_itemCount; + rhs.m_itemCount = temp; +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnInit( const void * p ) const +{ + assert( NULL != this ); + if ( NULL == p ) + { + assert( 0 == m_itemCount ); + } + else + { + assert( 0 < m_itemCount ); + } +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnCheckRange( size_t index ) const +{ + assert( NULL != this ); + + if ( index < m_itemCount ) + return; + + const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); + throw ::std::out_of_range( message ); +} + +// ---------------------------------------------------------------------------- + RefLinkedBase::RefLinkedBase( const RefLinkedBase & rhs ) : prev_( &rhs ), next_( rhs.next_ ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 18:38:19
|
Revision: 1108 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1108&view=rev Author: rich_sposato Date: 2011-09-20 18:38:13 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added comment about delete this. Modified Paths: -------------- trunk/test/SmartPtr/base.h Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-20 18:36:12 UTC (rev 1107) +++ trunk/test/SmartPtr/base.h 2011-09-20 18:38:13 UTC (rev 1108) @@ -37,7 +37,7 @@ assert( 0 < m_refCount ); --m_refCount; if ( 0 == m_refCount ) - delete this; + delete this; // Don't even ask me how much I dislike seeing "delete this;"! } // This function is used only for the DeepCopy policy. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 18:36:18
|
Revision: 1107 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1107&view=rev Author: rich_sposato Date: 2011-09-20 18:36:12 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added ability for StrongPtr to handle arrays. Modified Paths: -------------- trunk/test/SmartPtr/main.cpp Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-20 17:52:11 UTC (rev 1106) +++ trunk/test/SmartPtr/main.cpp 2011-09-20 18:36:12 UTC (rev 1107) @@ -36,6 +36,7 @@ extern void DoStrongForwardReferenceTest( void ); extern void DoStrongCompareTests( void ); extern void DoStrongPtrDynamicCastTests( void ); +extern void DoStrongArrayTests( void ); extern void DoLockedPtrTest( void ); extern void DoLockedStorageTest( void ); @@ -1546,7 +1547,7 @@ DoRefLinkSwapTests(); DoComRefTest(); - TryColvinGibbonsTrick(); + TryColvinGibbonsTrick(); DoStrongConstTests(); DoConstConversionTests(); @@ -1554,6 +1555,7 @@ DoInheritanceConversionTests(); DoSmartPtrDynamicCastTests(); DoStrongPtrDynamicCastTests(); + DoStrongArrayTests(); #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) if ( doThreadTest ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 17:52:17
|
Revision: 1106 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1106&view=rev Author: rich_sposato Date: 2011-09-20 17:52:11 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added ability for StrongPtr to handle arrays. Modified Paths: -------------- trunk/test/SmartPtr/strong.cpp Modified: trunk/test/SmartPtr/strong.cpp =================================================================== --- trunk/test/SmartPtr/strong.cpp 2011-09-20 17:51:46 UTC (rev 1105) +++ trunk/test/SmartPtr/strong.cpp 2011-09-20 17:52:11 UTC (rev 1106) @@ -1781,7 +1781,7 @@ namespace { - class Feline + class Feline : public BaseClass { public: virtual ~Feline() {} @@ -1796,7 +1796,12 @@ class Tiger : public Feline { public: + Tiger( void ) : m_stripes( 100 ) {} virtual ~Tiger() {} + unsigned int GetStripes( void ) const { return m_stripes; } + void SetStripes( unsigned int s ) { m_stripes = s; } + private: + unsigned int m_stripes; }; class Dog @@ -2089,3 +2094,164 @@ // this will not compile: //int i = f1.i; } + +// ---------------------------------------------------------------------------- + +/// Use these typedefs to test DeleteArray policy. + +typedef Loki::StrongPtr< Tiger, true, TwoRefCounts, DisallowConversion, + AssertCheck, CantResetWithStrong, DeleteArray, DontPropagateConst > + TigerArray_2RefCounts_ptr; + +typedef Loki::StrongPtr< Tiger, true, TwoRefLinks, DisallowConversion, + AssertCheck, CantResetWithStrong, DeleteArray, DontPropagateConst > + TigerArray_2RefLinks_ptr; + +typedef Loki::StrongPtr< Tiger, true, LockableTwoRefCounts, DisallowConversion, + AssertCheck, CantResetWithStrong, DeleteArray, DontPropagateConst > + TigerArray_Lock2RefCounts_ptr; + +// ---------------------------------------------------------------------------- + +void DoStrongArrayTests( void ) +{ + cout << "Starting DoStrongArrayTests." << endl; + + { + // test default construction. + TigerArray_2RefCounts_ptr sp1; + assert( !sp1 ); + assert( 0 == sp1.GetArrayCount() ); + + // test assignment. + sp1.Assign( new Tiger[ 8 ], 8 ); + assert( sp1 ); + assert( 8 == sp1.GetArrayCount() ); + sp1[ 0 ].SetStripes( 8 ); + sp1[ 1 ].SetStripes( 16 ); + sp1[ 2 ].SetStripes( 24 ); + sp1[ 3 ].SetStripes( 32 ); + sp1[ 4 ].SetStripes( 40); + sp1[ 5 ].SetStripes( 48 ); + sp1[ 6 ].SetStripes( 56 ); + sp1[ 7 ].SetStripes( 64 ); + + // test initialization construction. + TigerArray_2RefCounts_ptr sp2( new Tiger[ 4 ], 4 ); + assert( sp2 ); + assert( 4 == sp2.GetArrayCount() ); + sp2[ 0 ].SetStripes( 5 ); + sp2[ 1 ].SetStripes( 10 ); + sp2[ 2 ].SetStripes( 15 ); + sp2[ 3 ].SetStripes( 20 ); + + // test range checking. + try + { + Tiger & p4 = sp2[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test range checking. + try + { + Tiger & p8 = sp1[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + // test swap. + sp2.Swap( sp1 ); + assert( sp1 ); + assert( sp2 ); + // test checking of item count. + assert( 4 == sp1.GetArrayCount() ); + assert( 8 == sp2.GetArrayCount() ); + + // test that operator[] returns reference to + assert( 5 == sp1[ 0 ].GetStripes() ); + assert( 10 == sp1[ 1 ].GetStripes() ); + assert( 15 == sp1[ 2 ].GetStripes() ); + assert( 20 == sp1[ 3 ].GetStripes() ); + assert( 8 == sp2[ 0 ].GetStripes() ); + assert( 16 == sp2[ 1 ].GetStripes() ); + assert( 24 == sp2[ 2 ].GetStripes() ); + assert( 32 == sp2[ 3 ].GetStripes() ); + assert( 40 == sp2[ 4 ].GetStripes() ); + assert( 48 == sp2[ 5 ].GetStripes() ); + assert( 56 == sp2[ 6 ].GetStripes() ); + assert( 64 == sp2[ 7 ].GetStripes() ); + + try + { + Tiger & p4 = sp1[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + try + { + Tiger & p8 = sp2[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_2RefCounts_ptr sp3( sp1 ); + assert( sp3 == sp1 ); + assert( sp3.GetArrayCount() == sp1.GetArrayCount() ); + try + { + const Tiger & p4 = sp3[ 4 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + const TigerArray_2RefCounts_ptr sp5( sp2 ); + assert( sp5 == sp2 ); + assert( sp5.GetArrayCount() == sp2.GetArrayCount() ); + try + { + const Tiger & p8 = sp5[ 8 ]; + assert( false ); + } + catch ( const ::std::out_of_range & ex ) + { + assert( true ); + } + + sp2 = sp1; + assert( sp1 == sp2 ); + assert( sp3 == sp2 ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp2.GetArrayCount() == sp1.GetArrayCount() ); + assert( sp1 != sp5 ); + assert( sp2 != sp5 ); + assert( sp3 != sp5 ); + assert( sp1.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp2.GetArrayCount() != sp5.GetArrayCount() ); + assert( sp3.GetArrayCount() != sp5.GetArrayCount() ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoStrongArrayTests." << endl; +} + +// ---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 17:51:52
|
Revision: 1105 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1105&view=rev Author: rich_sposato Date: 2011-09-20 17:51:46 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added ability for StrongPtr to handle arrays. Modified Paths: -------------- trunk/src/StrongPtr.cpp Modified: trunk/src/StrongPtr.cpp =================================================================== --- trunk/src/StrongPtr.cpp 2011-09-20 17:51:26 UTC (rev 1104) +++ trunk/src/StrongPtr.cpp 2011-09-20 17:51:46 UTC (rev 1105) @@ -15,6 +15,9 @@ #include <loki/StrongPtr.h> +#include <stdexcept> +#include <string> + #include <memory.h> #ifdef DO_EXTRA_LOKI_TESTS #include <cassert> @@ -38,6 +41,45 @@ // ---------------------------------------------------------------------------- +void DeleteArrayBase::Swap( DeleteArrayBase & rhs ) +{ + assert( NULL != this ); + + const size_t temp = m_itemCount; + m_itemCount = rhs.m_itemCount; + rhs.m_itemCount = temp; +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnInit( const void * p ) const +{ + assert( NULL != this ); + if ( NULL == p ) + { + assert( 0 == m_itemCount ); + } + else + { + assert( 0 < m_itemCount ); + } +} + +// ---------------------------------------------------------------------------- + +void DeleteArrayBase::OnCheckRange( size_t index ) const +{ + assert( NULL != this ); + + if ( index < m_itemCount ) + return; + + const ::std::string message( "index out of range in ::Loki::DeleteArrayBase::OnCheckRange" ); + throw ::std::out_of_range( message ); +} + +// ---------------------------------------------------------------------------- + OneOwnerRefCountInfo::OneOwnerRefCountInfo( SingleOwnerRefCount * ptr ) : m_pointer( NULL ) , m_strongPtr( ptr ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-20 17:51:32
|
Revision: 1104 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1104&view=rev Author: rich_sposato Date: 2011-09-20 17:51:26 +0000 (Tue, 20 Sep 2011) Log Message: ----------- Added ability for StrongPtr to handle arrays. Modified Paths: -------------- trunk/include/loki/StrongPtr.h Modified: trunk/include/loki/StrongPtr.h =================================================================== --- trunk/include/loki/StrongPtr.h 2011-09-17 02:25:43 UTC (rev 1103) +++ trunk/include/loki/StrongPtr.h 2011-09-20 17:51:26 UTC (rev 1104) @@ -134,7 +134,15 @@ template < class P > class DeleteUsingFree { -public: +protected: + + inline DeleteUsingFree( void ) {} + + inline DeleteUsingFree( const DeleteUsingFree & ) {} + + template < class P1 > + inline DeleteUsingFree( const DeleteUsingFree< P1 > & ) {} + inline void static Delete( const P * p ) { if ( 0 != p ) @@ -165,7 +173,15 @@ template < class P > class DeleteNothing { -public: +protected: + + inline DeleteNothing( void ) {} + + inline DeleteNothing( const DeleteNothing & ) {} + + template < class P1 > + inline DeleteNothing( const DeleteNothing< P1 > & ) {} + inline static void Delete( const P * ) { // Do nothing at all! @@ -177,6 +193,7 @@ } inline void Swap( DeleteNothing & ) {} + }; //////////////////////////////////////////////////////////////////////////////// @@ -190,7 +207,15 @@ template < class P > class DeleteSingle { -public: +protected: + + inline DeleteSingle( void ) {} + + inline DeleteSingle( const DeleteSingle & ) {} + + template < class P1 > + inline DeleteSingle( const DeleteSingle< P1 > & ) {} + inline static void Delete( const P * p ) { /** @note If you see an error message about a negative subscript, that @@ -210,7 +235,46 @@ inline void Swap( DeleteSingle & ) {} }; +namespace Private +{ + //////////////////////////////////////////////////////////////////////////////// +/// \class DeleteArrayBase +/// +/// \ingroup StrongPointerDeleteGroup +/// Base class used only by the DeleteArray policy class. This stores the +/// number of elements in an array of shared objects. +//////////////////////////////////////////////////////////////////////////////// + +class DeleteArrayBase +{ +public: + + inline size_t GetArrayCount( void ) const { return m_itemCount; } + +protected: + + DeleteArrayBase( void ) : m_itemCount( 0 ) {} + + explicit DeleteArrayBase( size_t itemCount ) : m_itemCount( itemCount ) {} + + DeleteArrayBase( const DeleteArrayBase & that ) : m_itemCount( that.m_itemCount ) {} + + void Swap( DeleteArrayBase & rhs ); + + void OnInit( const void * p ) const; + + void OnCheckRange( size_t index ) const; + +private: + + size_t m_itemCount; + +}; + +} + +//////////////////////////////////////////////////////////////////////////////// /// \class DeleteArray /// /// \ingroup StrongPointerDeleteGroup @@ -219,9 +283,19 @@ //////////////////////////////////////////////////////////////////////////////// template < class P > -class DeleteArray +class DeleteArray : public ::Loki::Private::DeleteArrayBase { public: + + DeleteArray( void ) : DeleteArrayBase() {} + + explicit DeleteArray( size_t itemCount ) : DeleteArrayBase( itemCount ) {} + + DeleteArray( const DeleteArray & that ) : DeleteArrayBase( that ) {} + + template < class P1 > + inline DeleteArray( const DeleteArray< P1 > & that ) : DeleteArrayBase( that ) {} + inline static void Delete( const P * p ) { /** @note If you see an error message about a negative subscript, that @@ -238,7 +312,6 @@ return 0; } - inline void Swap( DeleteArray & ) {} }; //////////////////////////////////////////////////////////////////////////////// @@ -1653,21 +1726,32 @@ public: - StrongPtr( void ) : OP( Strong ) + StrongPtr( void ) : OP( Strong ), DP() { KP::OnDefault( GetPointer() ); } - explicit StrongPtr( ExplicitArg p ) : OP( p, Strong ) + explicit StrongPtr( ExplicitArg p ) : OP( p, Strong ), DP() { KP::OnInit( GetPointer() ); } - StrongPtr( ImplicitArg p ) : OP( p, Strong ) + StrongPtr( ImplicitArg p ) : OP( p, Strong ), DP() { KP::OnInit( GetPointer() ); } + /** This constructor was designed to only work with the DeleteArray policy. Using it with any + other Delete policies will cause compiler errors. Call it with this syntax: + "ThingyPtr sp2( new Thingy[ 4 ], 4 );" so the StrongPtr knows how many elements are in the + array for range checking. + */ + StrongPtr( ImplicitArg p, size_t itemCount ) : OP( p, Strong ), DP( itemCount ) + { + KP::OnInit( GetPointer() ); + DP::OnInit( GetPointer() ); + } + StrongPtr( const StrongPtr & rhs ) : OP( rhs, Strong ), CP( rhs ), KP( rhs ), DP( rhs ) { @@ -1686,7 +1770,7 @@ > StrongPtr( const StrongPtr< T1, S1, OP1, CP1, KP1, RP1, DP1, CNP1 > & rhs ) - : OP( rhs, Strong ) + : OP( rhs, Strong ), CP( rhs ), DP( rhs ) { } @@ -1703,7 +1787,7 @@ > StrongPtr( StrongPtr< T1, S1, OP1, CP1, KP1, RP1, DP1, CNP1 > & rhs ) - : OP( rhs, Strong ) + : OP( rhs, Strong ), CP( rhs ), DP( rhs ) { } @@ -1737,6 +1821,21 @@ return *this; } + /** This function is equivalent to an assignment operator for StrongPtr's that use the + DeleteArray policy where the programmer needs to write the equivalent of "sp = new P;". + With DeleteArray, the programmer should write "sp.Assign( new [5] Thingy, 5 );" so the + StrongPtr knows how many elements are in the array. + */ + StrongPtr & Assign( T * p, size_t itemCount ) + { + if ( GetPointer() != p ) + { + StrongPtr temp( p, itemCount ); + Swap( temp ); + } + return *this; + } + template < typename T1, @@ -1969,6 +2068,22 @@ return * GetPointer(); } + ReferenceType operator [] ( size_t index ) + { + KP::OnDereference( GetPointer() ); + DP::OnCheckRange( index ); + PointerType p = GetPointer(); + return p[ index ]; + } + + ConstReferenceType operator [] ( size_t index ) const + { + KP::OnDereference( GetPointer() ); + DP::OnCheckRange( index ); + ConstPointerType p = GetPointer(); + return p[ index ]; + } + /// Helper function which can be called to avoid exposing GetPointer function. template < class T1 > bool Equals( const T1 * p ) const This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-17 02:25:49
|
Revision: 1103 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1103&view=rev Author: rich_sposato Date: 2011-09-17 02:25:43 +0000 (Sat, 17 Sep 2011) Log Message: ----------- Removed #if 0 lines because compiler choked on it. Modified Paths: -------------- trunk/test/SmartPtr/colvin_gibbons_trick.cpp Modified: trunk/test/SmartPtr/colvin_gibbons_trick.cpp =================================================================== --- trunk/test/SmartPtr/colvin_gibbons_trick.cpp 2011-09-17 02:20:19 UTC (rev 1102) +++ trunk/test/SmartPtr/colvin_gibbons_trick.cpp 2011-09-17 02:25:43 UTC (rev 1103) @@ -120,48 +120,3 @@ // ---------------------------------------------------------------------------- - -#if 0 - -https://sourceforge.net/tracker/index.php?func=detail&aid=2080889&group_id=29557&atid=396644 - -To fix the compile bug we have to disable the (const T&) ctor and use RefToValue, -the way how it is done in auto_prt. - -But I'm not sure about the consequences of such a change. - -Index: loki/SmartPtr.h -=================================================================== ---- loki/SmartPtr.h (revision 910) -+++ loki/SmartPtr.h (working copy) -@@ -1175,6 +1175,7 @@ - GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); - } - -+ /* - template - < - typename T1, -@@ -1187,6 +1188,7 @@ - SmartPtr(const SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) - : SP(rhs), OP(rhs), KP(rhs), CP(rhs) - { GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } -+ */ - - template - < -@@ -1205,7 +1207,10 @@ - - SmartPtr(RefToValue<SmartPtr> rhs) - : SP(rhs), OP(rhs), KP(rhs), CP(rhs) -- {} -+ { -+ SmartPtr& ref = rhs; -+ GetImplRef(*this) = OP::Clone(GetImplRef(ref)); -+ } - - operator RefToValue<SmartPtr>() - { return RefToValue<SmartPtr>(*this); } - -#endif - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-17 02:20:25
|
Revision: 1102 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1102&view=rev Author: rich_sposato Date: 2011-09-17 02:20:19 +0000 (Sat, 17 Sep 2011) Log Message: ----------- Uncommented test for const DestructiveCopy pointer after fixing bug. Modified Paths: -------------- trunk/test/SmartPtr/main.cpp Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-17 02:19:01 UTC (rev 1101) +++ trunk/test/SmartPtr/main.cpp 2011-09-17 02:20:19 UTC (rev 1102) @@ -40,6 +40,8 @@ extern void DoLockedPtrTest( void ); extern void DoLockedStorageTest( void ); +extern void TryColvinGibbonsTrick( void ); + unsigned int BaseClass::s_constructions = 0; unsigned int BaseClass::s_destructions = 0; @@ -1488,23 +1490,23 @@ /** @note The following code won't compile because p1 is declared const. You can test if Loki's SmartPtr DestructiveCopy policy was designed correctly by uncommenting these lines and seeing if any errors occur when compiling. If you see errors about converting - from const to non-const, or about assigning a ready-only reference, then DestructiveCopy + from const to non-const, or about assigning a read-only reference, then DestructiveCopy was designed correctly. */ -// DestructiveCopyPtr p2; -// assert( !p2 ); -// p2 = p1; -// assert( !p1 ); -// assert( p2 ); -// DestructiveCopyPtr p3( p2 ); -// assert( p3 ); -// assert( !p2 ); + DestructiveCopyPtr p2; + assert( !p2 ); + p2 = p1; + assert( !p1 ); + assert( p2 ); + DestructiveCopyPtr p3( p2 ); + assert( p3 ); + assert( !p2 ); } { /// @todo The following lines need to be uncommented when bug 3224572 gets fixed. -// DestructiveCopyPtr p1( MakePointer() ); -// assert( p1 ); + DestructiveCopyPtr p1( MakePointer() ); + assert( p1 ); } assert( BaseClass::AllDestroyed() ); @@ -1544,6 +1546,7 @@ DoRefLinkSwapTests(); DoComRefTest(); + TryColvinGibbonsTrick(); DoStrongConstTests(); DoConstConversionTests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-17 02:19:07
|
Revision: 1101 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1101&view=rev Author: rich_sposato Date: 2011-09-17 02:19:01 +0000 (Sat, 17 Sep 2011) Log Message: ----------- Fixed bug 2080889 by adding overload of const Clone function. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-13 00:50:05 UTC (rev 1100) +++ trunk/include/loki/SmartPtr.h 2011-09-17 02:19:01 UTC (rev 1101) @@ -729,6 +729,14 @@ {} template <class P1> + static P Clone( const P1 & val ) + { + P result(val); + const_cast< P1 & >( val ) = P1(); + return result; + } + + template <class P1> static P Clone(P1& val) { P result(val); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-13 00:50:11
|
Revision: 1100 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1100&view=rev Author: rich_sposato Date: 2011-09-13 00:50:05 +0000 (Tue, 13 Sep 2011) Log Message: ----------- Added call to OnDereference to constructor. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-09 00:30:44 UTC (rev 1099) +++ trunk/include/loki/SmartPtr.h 2011-09-13 00:50:05 UTC (rev 1100) @@ -1252,7 +1252,7 @@ template <class> class SP1, template <class> class CNP1 > - SmartPtr(const SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) + SmartPtr( const SmartPtr< T1, OP1, CP1, KP1, SP1, CNP1 >& rhs ) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { KP::OnDereference( GetImpl( rhs ) ); @@ -1268,7 +1268,7 @@ template <class> class SP1, template <class> class CNP1 > - SmartPtr(SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) + SmartPtr( SmartPtr< T1, OP1, CP1, KP1, SP1, CNP1 >& rhs ) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { KP::OnDereference( GetImpl( rhs ) ); @@ -1277,7 +1277,11 @@ SmartPtr(RefToValue<SmartPtr> rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) - {} + { + SmartPtr & ref = rhs; + KP::OnDereference( GetImpl( ref ) ); + GetImplRef( *this ) = OP::Clone( GetImplRef( ref ) ); + } operator RefToValue<SmartPtr>() { return RefToValue<SmartPtr>(*this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-09 00:30:51
|
Revision: 1099 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1099&view=rev Author: rich_sposato Date: 2011-09-09 00:30:44 +0000 (Fri, 09 Sep 2011) Log Message: ----------- Fixed bug 3023886 by changing static check to use unnamed enum. Modified Paths: -------------- trunk/include/loki/static_check.h Modified: trunk/include/loki/static_check.h =================================================================== --- trunk/include/loki/static_check.h 2011-09-08 23:51:46 UTC (rev 1098) +++ trunk/include/loki/static_check.h 2011-09-09 00:30:44 UTC (rev 1099) @@ -2,14 +2,14 @@ // The Loki Library // Copyright (c) 2001 by Andrei Alexandrescu // This code accompanies the book: -// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The author or Addison-Wesley Longman make no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The author or Addison-Wesley Longman make no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// #ifndef LOKI_STATIC_CHECK_INC_ @@ -37,9 +37,11 @@ // If expr is zero, id will appear in a compile-time error message. //////////////////////////////////////////////////////////////////////////////// -#define LOKI_STATIC_CHECK(expr, msg) \ - { Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; } +#define LOKI_CONCAT( X, Y ) LOKI_CONCAT_SUB( X, Y ) +#define LOKI_CONCAT_SUB( X, Y ) X##Y +#define LOKI_STATIC_CHECK(expr, msg) enum { LOKI_CONCAT(ERROR_##msg, __LINE__) = sizeof(Loki::CompileTimeError<expr != 0 >) } + #endif // end file guardian This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-08 23:51:52
|
Revision: 1098 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1098&view=rev Author: rich_sposato Date: 2011-09-08 23:51:46 +0000 (Thu, 08 Sep 2011) Log Message: ----------- Added more tests for DestructiveCopy. Modified Paths: -------------- trunk/test/SmartPtr/main.cpp Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-08 23:37:26 UTC (rev 1097) +++ trunk/test/SmartPtr/main.cpp 2011-09-08 23:51:46 UTC (rev 1098) @@ -1480,9 +1480,31 @@ DestructiveCopyPtr p3( p2 ); assert( p3 ); assert( !p2 ); + } + + { + const DestructiveCopyPtr p1( new BaseClass ); + assert( p1 ); + /** @note The following code won't compile because p1 is declared const. You can test + if Loki's SmartPtr DestructiveCopy policy was designed correctly by uncommenting these + lines and seeing if any errors occur when compiling. If you see errors about converting + from const to non-const, or about assigning a ready-only reference, then DestructiveCopy + was designed correctly. + */ +// DestructiveCopyPtr p2; +// assert( !p2 ); +// p2 = p1; +// assert( !p1 ); +// assert( p2 ); +// DestructiveCopyPtr p3( p2 ); +// assert( p3 ); +// assert( !p2 ); + } + + { /// @todo The following lines need to be uncommented when bug 3224572 gets fixed. -// DestructiveCopyPtr p4( MakePointer() ); -// assert( p4 ); +// DestructiveCopyPtr p1( MakePointer() ); +// assert( p1 ); } assert( BaseClass::AllDestroyed() ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-08 23:37:33
|
Revision: 1097 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1097&view=rev Author: rich_sposato Date: 2011-09-08 23:37:26 +0000 (Thu, 08 Sep 2011) Log Message: ----------- Added tests for DestructiveCopy. Modified Paths: -------------- trunk/test/SmartPtr/main.cpp Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-07 22:51:17 UTC (rev 1096) +++ trunk/test/SmartPtr/main.cpp 2011-09-08 23:37:26 UTC (rev 1097) @@ -1455,6 +1455,44 @@ // ---------------------------------------------------------------------------- +typedef Loki::SmartPtr< BaseClass, DestructiveCopy > DestructiveCopyPtr; + +DestructiveCopyPtr MakePointer( void ) +{ + DestructiveCopyPtr p( new BaseClass ); + return p; +} + +// ---------------------------------------------------------------------------- + +void DoDestructiveCopyTest( void ) +{ + cout << "Starting DoDestructiveCopyTest." << endl; + + { + DestructiveCopyPtr p1( new BaseClass ); + assert( p1 ); + DestructiveCopyPtr p2; + assert( !p2 ); + p2 = p1; + assert( !p1 ); + assert( p2 ); + DestructiveCopyPtr p3( p2 ); + assert( p3 ); + assert( !p2 ); + /// @todo The following lines need to be uncommented when bug 3224572 gets fixed. +// DestructiveCopyPtr p4( MakePointer() ); +// assert( p4 ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoDestructiveCopyTest." << endl; +} + +// ---------------------------------------------------------------------------- + int main( int argc, const char * argv[] ) { bool doThreadTest = false; @@ -1465,6 +1503,7 @@ } DoDeepCopyTests(); + DoDestructiveCopyTest(); DoRefLinkTests(); DoWeakLeakTest(); DoStrongRefCountTests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-07 22:51:23
|
Revision: 1096 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1096&view=rev Author: rich_sposato Date: 2011-09-07 22:51:17 +0000 (Wed, 07 Sep 2011) Log Message: ----------- Added code to support test of bug 3224518. Modified Paths: -------------- trunk/test/SmartPtr/base.h Modified: trunk/test/SmartPtr/base.h =================================================================== --- trunk/test/SmartPtr/base.h 2011-09-07 22:50:38 UTC (rev 1095) +++ trunk/test/SmartPtr/base.h 2011-09-07 22:51:17 UTC (rev 1096) @@ -1,12 +1,12 @@ //////////////////////////////////////////////////////////////////////////////// // Test program for The Loki Library // Copyright (c) 2006 Richard Sposato -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The authors make no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The authors make no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// @@ -20,7 +20,7 @@ class BaseClass { public: - BaseClass( void ) + BaseClass( void ) : m_refCount( 1 ) { s_constructions++; } @@ -31,8 +31,14 @@ } // These 2 functions are so we can pretend we have a COM object. - void AddRef( void ) {} - void Release( void ) {} + void AddRef( void ) { ++m_refCount; } + void Release( void ) + { + assert( 0 < m_refCount ); + --m_refCount; + if ( 0 == m_refCount ) + delete this; + } // This function is used only for the DeepCopy policy. virtual BaseClass * Clone( void ) const @@ -75,6 +81,8 @@ static unsigned int s_constructions; static unsigned int s_destructions; + + unsigned int m_refCount; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-07 22:50:46
|
Revision: 1095 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1095&view=rev Author: rich_sposato Date: 2011-09-07 22:50:38 +0000 (Wed, 07 Sep 2011) Log Message: ----------- Added tests for bug 3224518. Modified Paths: -------------- trunk/test/SmartPtr/main.cpp Modified: trunk/test/SmartPtr/main.cpp =================================================================== --- trunk/test/SmartPtr/main.cpp 2011-09-07 22:46:37 UTC (rev 1094) +++ trunk/test/SmartPtr/main.cpp 2011-09-07 22:50:38 UTC (rev 1095) @@ -54,7 +54,7 @@ class Thingy; typedef Loki::SmartPtr< Thingy, RefCounted, DisallowConversion, - AssertCheck, DefaultSPStorage, PropagateConst > + NoCheck, DefaultSPStorage, PropagateConst > Thingy_DefaultStorage_ptr; typedef Loki::SmartPtr< Thingy, RefCounted, DisallowConversion, @@ -69,18 +69,23 @@ AssertCheck, DefaultSPStorage, DontPropagateConst > NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr; -/// @note These 3 are used for testing const policies. +/// @note These 4 are used for testing const policies. + +typedef Loki::SmartPtr< BaseClass, RefCounted, DisallowConversion, + NoCheck, DefaultSPStorage, DontPropagateConst > + NonConstBase_RefCount_NoConvert_NoCheck_DontPropagate_ptr; + typedef Loki::SmartPtr< const BaseClass, RefCounted, DisallowConversion, - AssertCheck, DefaultSPStorage, DontPropagateConst > - ConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr; + NoCheck, DefaultSPStorage, DontPropagateConst > + ConstBase_RefCount_NoConvert_NoCheck_DontPropagate_ptr; typedef Loki::SmartPtr< const BaseClass, RefCounted, DisallowConversion, - AssertCheck, DefaultSPStorage, PropagateConst > - ConstBase_RefCount_NoConvert_Assert_Propagate_ptr; + NoCheck, DefaultSPStorage, PropagateConst > + ConstBase_RefCount_NoConvert_NoCheck_Propagate_ptr; typedef Loki::SmartPtr< BaseClass, RefCounted, DisallowConversion, - AssertCheck, DefaultSPStorage, PropagateConst > - NonConstBase_RefCount_NoConvert_Assert_Propagate_ptr; + NoCheck, DefaultSPStorage, PropagateConst > + NonConstBase_RefCount_NoConvert_NoCheck_Propagate_ptr; // ---------------------------------------------------------------------------- @@ -135,11 +140,12 @@ void DoConstConversionTests( void ) { + cout << "Starting DoConstConversionTests." << endl; - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1; - ConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p2( p1 ); - ConstBase_RefCount_NoConvert_Assert_Propagate_ptr p3( p1 ); - NonConstBase_RefCount_NoConvert_Assert_Propagate_ptr p4( p1 ); + NonConstBase_RefCount_NoConvert_NoCheck_DontPropagate_ptr p1; + ConstBase_RefCount_NoConvert_NoCheck_DontPropagate_ptr p2( p1 ); + ConstBase_RefCount_NoConvert_NoCheck_Propagate_ptr p3( p1 ); + NonConstBase_RefCount_NoConvert_NoCheck_Propagate_ptr p4( p1 ); // p1 = p2; // illegal! converts const to non-const. // p1 = p3; // illegal! converts const to non-const. @@ -153,775 +159,824 @@ p4 = p1; // legal, but dubious. Changes const-propagation policy. // p4 = p2; // illegal! converts const to non-const. // p4 = p3; // illegal! converts const to non-const. + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoConstConversionTests." << endl; } // ---------------------------------------------------------------------------- void DoOwnershipConversionTests( void ) { - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1; - NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p2; - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p3; - NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p4( new BaseClass ); - NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p5; - NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p6; + cout << "Starting DoOwnershipConversionTests." << endl; - // legal constructions. Each should allow copy with same policies. - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p7( p1 ); - NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p8( p2 ); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p9( p3 ); - NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p10( p4 ); - NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p11( p5 ); + { + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1( new BaseClass ); + NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p2( new BaseClass ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p3( new BaseClass ); + NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p4( new BaseClass ); + NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p5( new BaseClass ); + NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p6( new BaseClass ); - // illegal construction! Can't copy anything with NoCopy policy. - // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p12( p6 ); + // legal constructions. Each should allow copy with same policies. + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p7( p1 ); + NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p8( p2 ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p9( p3 ); + NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p10( p4 ); + NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p11( p5 ); - // illegal constructions! Can't convert from one ownership policy to another. -// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p13( p2 ); -// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p14( p3 ); -// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p15( p4 ); -// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p16( p5 ); -// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p17( p6 ); + // illegal construction! Can't copy anything with NoCopy policy. + // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p12( p6 ); - // illegal constructions! Can't convert from one ownership policy to another. -// NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p18( p1 ); -// NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p19( p3 ); -// NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p20( p4 ); -// NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p21( p5 ); -// NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p22( p6 ); + // illegal constructions! Can't convert from one ownership policy to another. + // NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p13( p2 ); + // NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p14( p3 ); + // NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p15( p4 ); + // NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p16( p5 ); + // NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p17( p6 ); - // illegal constructions! Can't convert from one ownership policy to another. -// NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p23( p1 ); -// NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p24( p2 ); -// NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p25( p4 ); -// NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p26( p5 ); -// NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p27( p6 ); + // illegal constructions! Can't convert from one ownership policy to another. + // NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p18( p1 ); + // NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p19( p3 ); + // NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p20( p4 ); + // NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p21( p5 ); + // NonConstBase_ComRef_NoConvert_Assert_DontPropagate_ptr p22( p6 ); - // illegal constructions! Can't convert from one ownership policy to another. -// NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p28( p1 ); -// NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p29( p2 ); -// NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p30( p3 ); -// NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p31( p5 ); -// NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p32( p6 ); + // illegal constructions! Can't convert from one ownership policy to another. + // NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p23( p1 ); + // NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p24( p2 ); + // NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p25( p4 ); + // NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p26( p5 ); + // NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p27( p6 ); - // illegal constructions! Can't convert from one ownership policy to another. -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p33( p1 ); -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p34( p2 ); -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p35( p3 ); -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p36( p4 ); -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p37( p6 ); + // illegal constructions! Can't convert from one ownership policy to another. + // NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p28( p1 ); + // NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p29( p2 ); + // NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p30( p3 ); + // NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p31( p5 ); + // NonConstBase_DeepCopy_NoConvert_Assert_DontPropagate_ptr p32( p6 ); - // illegal constructions! Can't convert from one ownership policy to another. -// NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p38( p1 ); -// NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p39( p2 ); -// NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p40( p3 ); -// NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p41( p4 ); -// NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p42( p5 ); + // illegal constructions! Can't convert from one ownership policy to another. + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p33( p1 ); + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p34( p2 ); + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p35( p3 ); + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p36( p4 ); + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p37( p6 ); - // These constructions are legal because the preserve const-ness. - ConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p43( p5 ); - ConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p44( p43 ); - const BaseClass * rawP = new BaseClass; - // These constructions are illegal because the don't preserve constness. -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p45( rawP ); -// NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p46( p43 ); - ConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p47( rawP ); + // illegal constructions! Can't convert from one ownership policy to another. + // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p38( p1 ); + // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p39( p2 ); + // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p40( p3 ); + // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p41( p4 ); + // NonConstBase_NoCopy_NoConvert_Assert_DontPropagate_ptr p42( p5 ); + } - NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p48; - // This assignment is legal because it preserves constness. - p48 = p5; - // This assignment is illegal because it won't preserve constness. -// p48 = p43; + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); - // illegal assignements! Can't convert from one ownership policy to another. -// p1 = p2; -// p1 = p3; -// p1 = p4; -// p1 = p5; -// p1 = p6; -// p2 = p1; -// p2 = p3; -// p2 = p4; -// p2 = p5; -// p2 = p6; -// p3 = p1; -// p3 = p2; -// p3 = p4; -// p3 = p5; -// p3 = p6; -// p4 = p1; -// p4 = p2; -// p4 = p3; -// p4 = p5; -// p4 = p6; -// p5 = p1; -// p5 = p2; -// p5 = p3; -// p5 = p4; -// p5 = p6; -// p6 = p1; -// p6 = p2; -// p6 = p3; -// p6 = p4; -// p6 = p5; + { + // These constructions are legal because the preserve const-ness. + const BaseClass * rawP = new BaseClass; + ConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p43( rawP ); + ConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p44( p43 ); + rawP = new BaseClass; + // These constructions are illegal because the don't preserve constness. + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p45( rawP ); + // NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p46( p43 ); + ConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p47( rawP ); + + NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p48; + NonConstBase_KillCopy_NoConvert_Assert_DontPropagate_ptr p49( new BaseClass ); + // This assignment is legal because it preserves constness. + p48 = p49; + // This assignment is illegal because it won't preserve constness. + // p48 = p43; + + // illegal assignments! Can't convert from one ownership policy to another. + // p1 = p2; + // p1 = p3; + // p1 = p4; + // p1 = p5; + // p1 = p6; + // p2 = p1; + // p2 = p3; + // p2 = p4; + // p2 = p5; + // p2 = p6; + // p3 = p1; + // p3 = p2; + // p3 = p4; + // p3 = p5; + // p3 = p6; + // p4 = p1; + // p4 = p2; + // p4 = p3; + // p4 = p5; + // p4 = p6; + // p5 = p1; + // p5 = p2; + // p5 = p3; + // p5 = p4; + // p5 = p6; + // p6 = p1; + // p6 = p2; + // p6 = p3; + // p6 = p4; + // p6 = p5; + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoOwnershipConversionTests." << endl; } // ---------------------------------------------------------------------------- void DoInheritanceConversionTests( void ) { - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1; - PublicSub_RefCount_NoConvert_Assert_DontPropagate_ptr p2; - PrivateSub_RefCount_NoConvert_Assert_DontPropagate_ptr p3; + cout << "Starting DoInheritanceConversionTests." << endl; - p1 = p2; // legal. Cast to public base class allowed. - assert( p1 == p2 ); -// p1 = p3; // illegal! Can't assign pointer since base class is private. -// p2 = p1; // illegal! Can't do cast to derived class in pointer assignment. -// p2 = p3; // illegal! Can't assign when types are unrelated. -// p3 = p1; // illegal! Can't do cast to derived class in pointer assignment. -// p3 = p2; // illegal! Can't assign when types are unrelated. + { + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1; + PublicSub_RefCount_NoConvert_Assert_DontPropagate_ptr p2( new PublicSubClass ); + PrivateSub_RefCount_NoConvert_Assert_DontPropagate_ptr p3; - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p4( p2 ); - assert( p4 == p1 ); - assert( p4 == p2 ); - // These copy-constructions are illegal for reasons shown above. -// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p5( p3 ); -// PublicSub_RefCount_NoConvert_Assert_DontPropagate_ptr p6( p1 ); -// PublicSub_RefCount_NoConvert_Assert_DontPropagate_ptr p7( p3 ); -// PrivateSub_RefCount_NoConvert_Assert_DontPropagate_ptr p8( p1 ); -// PrivateSub_RefCount_NoConvert_Assert_DontPropagate_ptr p9( p2 ); + p1 = p2; // legal. Cast to public base class allowed. + assert( p1 == p2 ); +// p1 = p3; // illegal! Can't assign pointer since base class is private. +// p2 = p1; // illegal! Can't do cast to derived class in pointer assignment. +// p2 = p3; // illegal! Can't assign when types are unrelated. +// p3 = p1; // illegal! Can't do cast to derived class in pointer assignment. +// p3 = p2; // illegal! Can't assign when types are unrelated. + + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p4( p2 ); + assert( p4 == p1 ); + assert( p4 == p2 ); + // These copy-constructions are illegal for reasons shown above. +// NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p5( p3 ); +// PublicSub_RefCount_NoConvert_Assert_DontPropagate_ptr p6( p1 ); +// PublicSub_RefCount_NoConvert_Assert_DontPropagate_ptr p7( p3 ); +// PrivateSub_RefCount_NoConvert_Assert_DontPropagate_ptr p8( p1 ); +// PrivateSub_RefCount_NoConvert_Assert_DontPropagate_ptr p9( p2 ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoInheritanceConversionTests." << endl; } // ---------------------------------------------------------------------------- void DoRefCountSwapTests( void ) { - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1( new BaseClass ); - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p2( new BaseClass ); + cout << "Starting DoRefCountSwapTests." << endl; - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p3( p1 ); - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p4( p2 ); + { + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1( new BaseClass ); + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p2( new BaseClass ); - // p1 == p3 and p2 == p4 - assert( p1 == p3 ); - assert( p1 != p2 ); - assert( p1 != p4 ); - assert( p2 == p4 ); - assert( p2 != p3 ); - assert( p2 != p1 ); + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p3( p1 ); + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p4( p2 ); - // p1 == p4 and p2 == p3 - p3.Swap( p4 ); - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); + // p1 == p3 and p2 == p4 + assert( p1 == p3 ); + assert( p1 != p2 ); + assert( p1 != p4 ); + assert( p2 == p4 ); + assert( p2 != p3 ); + assert( p2 != p1 ); - // p1 == p3 and p2 == p4 - p3.Swap( p4 ); - assert( p1 == p3 ); - assert( p1 != p2 ); - assert( p1 != p4 ); - assert( p2 == p4 ); - assert( p2 != p3 ); - assert( p2 != p1 ); + // p1 == p4 and p2 == p3 + p3.Swap( p4 ); + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); - // p2 == p3 and p1 == p4 - p1.Swap( p2 ); - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); + // p1 == p3 and p2 == p4 + p3.Swap( p4 ); + assert( p1 == p3 ); + assert( p1 != p2 ); + assert( p1 != p4 ); + assert( p2 == p4 ); + assert( p2 != p3 ); + assert( p2 != p1 ); - // p2 == p3 and p1 == p4 - p1.Swap( p1 ); - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); + // p2 == p3 and p1 == p4 + p1.Swap( p2 ); + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); - // p2 == p3 and p4 == p1 - p1.Swap( p4 ); - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); + // p2 == p3 and p1 == p4 + p1.Swap( p1 ); + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + + // p2 == p3 and p4 == p1 + p1.Swap( p4 ); + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + } + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoRefCountSwapTests." << endl; } // ---------------------------------------------------------------------------- void DoRefLinkSwapTests( void ) { + cout << "Starting DoRefLinkSwapTests." << endl; - BaseClass * pBaseClass = new BaseClass; - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p1( pBaseClass ); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p2( new BaseClass ); - p1->DoThat(); - p2->DoThat(); + { + BaseClass * pBaseClass = new BaseClass; + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p1( pBaseClass ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p2( new BaseClass ); + p1->DoThat(); + p2->DoThat(); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p3( p1 ); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p4( p2 ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p3( p1 ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p4( p2 ); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p5; - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p6( new BaseClass ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p5; + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p6( new BaseClass ); - BaseClass * pBare1 = GetImpl( p1 ); - BaseClass * pBare2 = GetImpl( p2 ); - BaseClass * pBare6 = GetImpl( p6 ); - const bool is1LessThan2 = ( pBare1 < pBare2 ); - const bool is1LessThan6 = ( pBare1 < pBare6 ); - const bool is2LessThan6 = ( pBare2 < pBare6 ); - assert( pBare1 != pBare2 ); - assert( pBare1 != pBare6 ); - assert( pBare2 != pBare6 ); - assert( p1 == pBare1 ); - assert( p2 == pBare2 ); - assert( p6 == pBare6 ); - assert( pBare1 == p1 ); - assert( pBare2 == p2 ); - assert( pBare6 == p6 ); - assert( pBare2 != p1 ); - assert( p1 != pBare2 ); + BaseClass * pBare1 = GetImpl( p1 ); + BaseClass * pBare2 = GetImpl( p2 ); + BaseClass * pBare6 = GetImpl( p6 ); + const bool is1LessThan2 = ( pBare1 < pBare2 ); + const bool is1LessThan6 = ( pBare1 < pBare6 ); + const bool is2LessThan6 = ( pBare2 < pBare6 ); + assert( pBare1 != pBare2 ); + assert( pBare1 != pBare6 ); + assert( pBare2 != pBare6 ); + assert( p1 == pBare1 ); + assert( p2 == pBare2 ); + assert( p6 == pBare6 ); + assert( pBare1 == p1 ); + assert( pBare2 == p2 ); + assert( pBare6 == p6 ); + assert( pBare2 != p1 ); + assert( p1 != pBare2 ); - if ( is1LessThan2 ) - { - assert( p1 < p2 ); - assert( p1 <= p2 ); + if ( is1LessThan2 ) + { + assert( p1 < p2 ); + assert( p1 <= p2 ); + assert( p1 != p2 ); + assert( p2 > p1 ); + assert( p2 >= p1 ); + assert( p1 < pBare2 ); + assert( p1 <= pBare2 ); + assert( pBare2 > p1 ); + assert( pBare2 >= p1 ); + } + else + { + assert( p2 < p1 ); + assert( p2 <= p1 ); + assert( p2 != p1 ); + assert( p1 > p2 ); + assert( p1 >= p2 ); + assert( p2 < pBare1 ); + assert( p2 <= pBare1 ); + assert( p2 != pBare1 ); + assert( pBare1 > p2 ); + assert( pBare1 >= p2 ); + } + + if ( is1LessThan6 ) + { + assert( p1 < p6 ); + assert( p1 <= p6 ); + assert( p1 != p6 ); + assert( p6 > p1 ); + assert( p6 >= p1 ); + assert( p1 < pBare6 ); + assert( p1 <= pBare6 ); + assert( pBare6 > p1 ); + assert( pBare6 >= p1 ); + } + else + { + assert( p6 < p1 ); + assert( p6 <= p1 ); + assert( p6 != p1 ); + assert( p1 > p6 ); + assert( p1 >= p6 ); + assert( p6 < pBare1 ); + assert( p6 <= pBare1 ); + assert( p6 != pBare1 ); + assert( pBare1 > p6 ); + assert( pBare1 >= p6 ); + } + + if ( is2LessThan6 ) + { + assert( p2 < p6 ); + assert( p2 <= p6 ); + assert( p2 != p6 ); + assert( p6 > p2 ); + assert( p6 >= p2 ); + assert( p2 < pBare6 ); + assert( p2 <= pBare6 ); + assert( pBare6 > p2 ); + assert( pBare6 >= p2 ); + } + else + { + assert( p6 < p2 ); + assert( p6 <= p2 ); + assert( p6 != p2 ); + assert( p2 > p6 ); + assert( p2 >= p6 ); + assert( p6 < pBare2 ); + assert( p6 <= pBare2 ); + assert( p6 != pBare2 ); + assert( pBare2 > p6 ); + assert( pBare2 >= p6 ); + } + + // p1 <---> p3 and p2 <---> p4 and p5 and p6 + assert( p1 == p3 ); assert( p1 != p2 ); - assert( p2 > p1 ); - assert( p2 >= p1 ); - assert( p1 < pBare2 ); - assert( p1 <= pBare2 ); - assert( pBare2 > p1 ); - assert( pBare2 >= p1 ); - } - else - { - assert( p2 < p1 ); - assert( p2 <= p1 ); + assert( p1 != p4 ); + assert( p2 == p4 ); + assert( p2 != p3 ); assert( p2 != p1 ); - assert( p1 > p2 ); - assert( p1 >= p2 ); - assert( p2 < pBare1 ); - assert( p2 <= pBare1 ); - assert( p2 != pBare1 ); - assert( pBare1 > p2 ); - assert( pBare1 >= p2 ); - } + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - if ( is1LessThan6 ) - { - assert( p1 < p6 ); - assert( p1 <= p6 ); - assert( p1 != p6 ); - assert( p6 > p1 ); - assert( p6 >= p1 ); - assert( p1 < pBare6 ); - assert( p1 <= pBare6 ); - assert( pBare6 > p1 ); - assert( pBare6 >= p1 ); - } - else - { - assert( p6 < p1 ); - assert( p6 <= p1 ); - assert( p6 != p1 ); - assert( p1 > p6 ); - assert( p1 >= p6 ); - assert( p6 < pBare1 ); - assert( p6 <= pBare1 ); - assert( p6 != pBare1 ); - assert( pBare1 > p6 ); - assert( pBare1 >= p6 ); - } + p3.Swap( p4 ); // p1 <---> p4 and p2 <---> p3 and p5 and p6 + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - if ( is2LessThan6 ) - { - assert( p2 < p6 ); - assert( p2 <= p6 ); - assert( p2 != p6 ); - assert( p6 > p2 ); - assert( p6 >= p2 ); - assert( p2 < pBare6 ); - assert( p2 <= pBare6 ); - assert( pBare6 > p2 ); - assert( pBare6 >= p2 ); - } - else - { - assert( p6 < p2 ); - assert( p6 <= p2 ); - assert( p6 != p2 ); - assert( p2 > p6 ); - assert( p2 >= p6 ); - assert( p6 < pBare2 ); - assert( p6 <= pBare2 ); - assert( p6 != pBare2 ); - assert( pBare2 > p6 ); - assert( pBare2 >= p6 ); - } + p3.Swap( p4 ); // p1 <---> p3 and p2 <---> p4 and p5 and p6 + assert( p1 == p3 ); + assert( p1 != p2 ); + assert( p1 != p4 ); + assert( p2 == p4 ); + assert( p2 != p3 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - // p1 <---> p3 and p2 <---> p4 and p5 and p6 - assert( p1 == p3 ); - assert( p1 != p2 ); - assert( p1 != p4 ); - assert( p2 == p4 ); - assert( p2 != p3 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p1.Swap( p2 ); // p2 <---> p3 and p1 <---> p4 and p5 and p6 + assert( p1 != pBaseClass ); + assert( p2 == pBaseClass ); + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - p3.Swap( p4 ); // p1 <---> p4 and p2 <---> p3 and p5 and p6 - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p1.Swap( p1 ); // p2 <---> p3 and p1 <---> p4 and p5 and p6 + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - p3.Swap( p4 ); // p1 <---> p3 and p2 <---> p4 and p5 and p6 - assert( p1 == p3 ); - assert( p1 != p2 ); - assert( p1 != p4 ); - assert( p2 == p4 ); - assert( p2 != p3 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p1.Swap( p4 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - p1.Swap( p2 ); // p2 <---> p3 and p1 <---> p4 and p5 and p6 - assert( p1 != pBaseClass ); - assert( p2 == pBaseClass ); - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p4.Swap( p1 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - p1.Swap( p1 ); // p2 <---> p3 and p1 <---> p4 and p5 and p6 - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p5.Swap( p5 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); - p1.Swap( p4 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p5.Swap( p1 ); // p2 <---> p3 and p4 <---> p5 and p1 and p6 + assert( p5 == p4 ); + assert( p5 != p2 ); + assert( p5 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p5 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p4 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - p4.Swap( p1 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p6.Swap( p1 ); // p2 <---> p3 and p4 <---> p5 and p1 and p6 + assert( p5 == p4 ); + assert( p5 != p2 ); + assert( p5 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p5 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p4 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); - p5.Swap( p5 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); + p5.Swap( p1 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 + assert( p1 == p4 ); + assert( p1 != p2 ); + assert( p1 != p3 ); + assert( p2 == p3 ); + assert( p2 != p4 ); + assert( p2 != p1 ); + assert( p1 != p5 ); + assert( p2 != p5 ); + assert( p3 != p5 ); + assert( p4 != p5 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); - p5.Swap( p1 ); // p2 <---> p3 and p4 <---> p5 and p1 and p6 - assert( p5 == p4 ); - assert( p5 != p2 ); - assert( p5 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p5 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p4 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p6 = p2; // p6 <---> p2 <---> p3 and p4 <---> p1 and p5 + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p5 != p3 ); + assert( p2 != p4 ); + assert( p2 != p5 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); - p6.Swap( p1 ); // p2 <---> p3 and p4 <---> p5 and p1 and p6 - assert( p5 == p4 ); - assert( p5 != p2 ); - assert( p5 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p5 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p4 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); + p5 = p3; // p6 <---> p2 <---> p3 <---> p5 and p4 <---> p1 + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); - p5.Swap( p1 ); // p2 <---> p3 and p4 <---> p1 and p5 and p6 - assert( p1 == p4 ); - assert( p1 != p2 ); - assert( p1 != p3 ); - assert( p2 == p3 ); - assert( p2 != p4 ); - assert( p2 != p1 ); - assert( p1 != p5 ); - assert( p2 != p5 ); - assert( p3 != p5 ); - assert( p4 != p5 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); + p5.Swap( p3 ); // p6 <---> p2 <---> p5 <---> p3 and p4 <---> p1 + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); - p6 = p2; // p6 <---> p2 <---> p3 and p4 <---> p1 and p5 - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p5 != p3 ); - assert( p2 != p4 ); - assert( p2 != p5 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); + p2.Swap( p3 ); // p6 <---> p3 <---> p5 <---> p2 and p4 <---> p1 + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); - p5 = p3; // p6 <---> p2 <---> p3 <---> p5 and p4 <---> p1 - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); + bool merged = false; + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p7( pBaseClass ); + assert( p7 == p7 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + merged = p7.Merge( p6 ); + // p7 <---> p6 <---> p3 <---> p5 <---> p2 and p4 <---> p1 + assert( merged ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); - p5.Swap( p3 ); // p6 <---> p2 <---> p5 <---> p3 and p4 <---> p1 - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p8( pBaseClass ); + assert( p6 == p8 ); + assert( p1 != p8 ); + merged = p6.Merge( p8 ); + // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 + assert( merged ); + assert( p6 == p8 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); + assert( p8 == p8 ); - p2.Swap( p3 ); // p6 <---> p3 <---> p5 <---> p2 and p4 <---> p1 - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); + merged = p6.Merge( p6 ); + // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 + assert( merged ); + assert( p6 == p8 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); + assert( p8 == p8 ); - bool merged = false; - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p7( pBaseClass ); - assert( p7 == p7 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - merged = p7.Merge( p6 ); - // p7 <---> p6 <---> p3 <---> p5 <---> p2 and p4 <---> p1 - assert( merged ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); + merged = p6.Merge( p3 ); + // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 + assert( merged ); + assert( p6 == p8 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); + assert( p8 == p8 ); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p8( pBaseClass ); - assert( p6 == p8 ); - assert( p1 != p8 ); - merged = p6.Merge( p8 ); - // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 - assert( merged ); - assert( p6 == p8 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); - assert( p8 == p8 ); + merged = p5.Merge( p1 ); + // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 + assert( !merged ); + assert( p6 == p8 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); + assert( p8 == p8 ); - merged = p6.Merge( p6 ); - // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 - assert( merged ); - assert( p6 == p8 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); - assert( p8 == p8 ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p9( pBaseClass ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr pA( p9 ); + assert( p9 == pA ); + assert( p9 == p8 ); + assert( p1 != p8 ); + merged = p9.Merge( p1 ); + // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 + // and p4 <---> p1 and p9 <---> pA + assert( !merged ); + assert( p6 == p8 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); + assert( p8 == p8 ); + assert( p9 == p9 ); + assert( pA == pA ); - merged = p6.Merge( p3 ); - // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 - assert( merged ); - assert( p6 == p8 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); - assert( p8 == p8 ); + merged = p9.Merge( p2 ); + // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 <---> p9 <---> pA + // and p4 <---> p1 + assert( merged ); + assert( p6 == p8 ); + assert( p6 == p7 ); + assert( p1 != p7 ); + assert( p6 == p5 ); + assert( p6 == p2 ); + assert( p6 == p3 ); + assert( p5 == p3 ); + assert( p2 == p3 ); + assert( p1 == p4 ); + assert( p2 != p4 ); + assert( p1 != p5 ); + assert( p2 != p1 ); + assert( p3 != p1 ); + assert( p1 == p1 ); + assert( p2 == p2 ); + assert( p3 == p3 ); + assert( p4 == p4 ); + assert( p5 == p5 ); + assert( p6 == p6 ); + assert( p7 == p7 ); + assert( p8 == p8 ); + assert( p9 == p9 ); + assert( pA == pA ); + } - merged = p5.Merge( p1 ); - // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 and p4 <---> p1 - assert( !merged ); - assert( p6 == p8 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); - assert( p8 == p8 ); - - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p9( pBaseClass ); - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr pA( p9 ); - assert( p9 == pA ); - assert( p9 == p8 ); - assert( p1 != p8 ); - merged = p9.Merge( p1 ); - // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 - // and p4 <---> p1 and p9 <---> pA - assert( !merged ); - assert( p6 == p8 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); - assert( p8 == p8 ); - assert( p9 == p9 ); - assert( pA == pA ); - - merged = p9.Merge( p2 ); - // p7 <---> p6 <---> p8 <---> p3 <---> p5 <---> p2 <---> p9 <---> pA - // and p4 <---> p1 - assert( merged ); - assert( p6 == p8 ); - assert( p6 == p7 ); - assert( p1 != p7 ); - assert( p6 == p5 ); - assert( p6 == p2 ); - assert( p6 == p3 ); - assert( p5 == p3 ); - assert( p2 == p3 ); - assert( p1 == p4 ); - assert( p2 != p4 ); - assert( p1 != p5 ); - assert( p2 != p1 ); - assert( p3 != p1 ); - assert( p1 == p1 ); - assert( p2 == p2 ); - assert( p3 == p3 ); - assert( p4 == p4 ); - assert( p5 == p5 ); - assert( p6 == p6 ); - assert( p7 == p7 ); - assert( p8 == p8 ); - assert( p9 == p9 ); - assert( pA == pA ); + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoRefLinkSwapTests." << endl; } // ---------------------------------------------------------------------------- void DoRefLinkTests( void ) { + cout << "Starting DoRefLinkTests." << endl; const unsigned int ctorCount = BaseClass::GetCtorCount(); (void) ctorCount; const unsigned int dtorCount = BaseClass::GetDtorCount(); (void) dtorCount; @@ -951,12 +1006,18 @@ assert( dtorCount + 2 == BaseClass::GetDtorCount() ); assert( BaseClass::GetCtorCount() == BaseClass::GetDtorCount() ); + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoRefLinkTests." << endl; } // ---------------------------------------------------------------------------- void DoRefCountNullPointerTests( void ) { + cout << "Starting DoRefCountNullPointerTests." << endl; + BaseClass * pNull = NULL; (void) pNull; const unsigned int ctorCount = BaseClass::GetCtorCount(); (void) ctorCount; const unsigned int dtorCount = BaseClass::GetDtorCount(); (void) dtorCount; @@ -965,7 +1026,7 @@ { NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p0; NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p1; - NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p2( p0 ); + NonConstBase_RefCount_NoConvert_Assert_DontPropagate_ptr p2; assert( !p0 ); assert( !p1 ); @@ -1005,12 +1066,19 @@ } assert( ctorCount == BaseClass::GetCtorCount() ); assert( dtorCount == BaseClass::GetDtorCount() ); + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoRefCountNullPointerTests." << endl; } // ---------------------------------------------------------------------------- void DoRefLinkNullPointerTests( void ) { + cout << "Starting DoRefLinkNullPointerTests." << endl; + BaseClass * pNull = NULL; (void) pNull; const unsigned int ctorCount = BaseClass::GetCtorCount(); (void) ctorCount; const unsigned int dtorCount = BaseClass::GetDtorCount(); (void) dtorCount; @@ -1019,7 +1087,7 @@ { NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p0; NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p1; - NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p2( p0 ); + NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p2; assert( !p0 ); assert( !p1 ); @@ -1059,12 +1127,18 @@ } assert( ctorCount == BaseClass::GetCtorCount() ); assert( dtorCount == BaseClass::GetDtorCount() ); + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoRefLinkNullPointerTests." << endl; } // ---------------------------------------------------------------------------- void DoComRefTest( void ) { + cout << "Starting DoComRefTest." << endl; const unsigned int ctorCount = MimicCOM::GetCtorCount(); (void) ctorCount; const unsigned int dtorCount = MimicCOM::GetDtorCount(); (void) dtorCount; @@ -1090,12 +1164,19 @@ } assert( ctorCount+2 == MimicCOM::GetCtorCount() ); assert( dtorCount+2 == MimicCOM::GetDtorCount() ); + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoComRefTest." << endl; } // ---------------------------------------------------------------------------- void DoForwardReferenceTest( void ) { + cout << "Starting DoForwardReferenceTest." << endl; + /** @note These lines should cause the compiler to make a warning message about attempting to delete an undefined type. But it should not produce any error messages. @@ -1112,6 +1193,11 @@ //Thingy_HeapStorage_ptr p5( p4 ); //Thingy_HeapStorage_ptr p6; //p6 = p5; + + assert( BaseClass::AllDestroyed() ); + assert( !BaseClass::ExtraConstructions() ); + assert( !BaseClass::ExtraDestructions() ); + cout << "Finished DoForwardReferenceTest." << endl; } // ---------------------------------------------------------------------------- @@ -1122,25 +1208,63 @@ class Feline { public: - virtual ~Feline() {} + + static inline bool AllDestroyed( void ) + { + return ( s_constructions == s_destructions ); + } + + static inline bool ExtraConstructions( void ) + { + return ( s_constructions > s_destructions ); + } + + static inline bool ExtraDestructions( void ) + { + return ( s_constructions < s_destructions ); + } + + static inline unsigned int GetCtorCount( void ) + { + return s_constructions; + } + + static inline unsigned int GetDtorCount( void ) + { + return s_destructions; + } + + Feline( void ) { s_constructions++; } + virtual ~Feline() { s_destructions++; } + virtual Feline * Clone( void ) const = 0; + + private: + static unsigned int s_constructions; + static unsigned int s_destructions; }; - class Lion : public Feline + unsigned int Feline::s_constructions = 0; + unsigned int Feline::s_destructions = 0; + + class Tiger : public Feline { public: - virtual ~Lion() {} + virtual ~Tiger() {} + virtual Tiger * Clone( void ) const { return new Tiger( *this ); } }; - class Tiger : public Feline + class Lion : public Feline { public: - virtual ~Tiger() {} + virtual ~Lion() {} + virtual Lion * Clone( void ) const { return new Lion( *this ); } }; class Dog { public: virtual ~Dog() {} + virtual Dog * Clone( void ) const { return new Dog( *this ); } }; } @@ -1149,88 +1273,188 @@ void DoSmartPtrDynamicCastTests( void ) { - typedef ::Loki::SmartPtr< Feline > FelinePtr; - typedef ::Loki::SmartPtr< Lion > LionPtr; - typedef ::Loki::SmartPtr< Tiger > TigerPtr; - typedef ::Loki::SmartPtr< Dog > DogPtr; + cout << "Starting DoSmartPtrDynamicCastTests." << endl; - Feline * feline = new Lion; - Lion * lion = new Lion; - Tiger * tiger = new Tiger; - Dog * dog = new Dog; + typedef ::Loki::SmartPtr< Feline, RefCounted, DisallowConversion, NoCheck > FelinePtr; + typedef ::Loki::SmartPtr< Tiger, RefCounted, DisallowConversion, NoCheck > TigerPtr; + typedef ::Loki::SmartPtr< Lion, RefCounted, DisallowConversion, NoCheck > LionPtr; + typedef ::Loki::SmartPtr< Dog, RefCounted, DisallowConversion, No... [truncated message content] |
From: <ric...@us...> - 2011-09-07 22:46:43
|
Revision: 1094 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1094&view=rev Author: rich_sposato Date: 2011-09-07 22:46:37 +0000 (Wed, 07 Sep 2011) Log Message: ----------- Fixed bug 3224518 by adding calls to OnDereference. Modified Paths: -------------- trunk/include/loki/SmartPtr.h Modified: trunk/include/loki/SmartPtr.h =================================================================== --- trunk/include/loki/SmartPtr.h 2011-09-07 20:04:38 UTC (rev 1093) +++ trunk/include/loki/SmartPtr.h 2011-09-07 22:46:37 UTC (rev 1094) @@ -983,7 +983,7 @@ static void OnDefault(const P&) { // Make it depended on template parameter - static const bool DependedFalse = sizeof(P*) == 0; + static const bool DependedFalse = ( sizeof(P*) == 0 ); LOKI_STATIC_CHECK(DependedFalse, ERROR_This_Policy_Does_Not_Allow_Default_Initialization); } @@ -1196,6 +1196,7 @@ (void)helper; // do void cast to remove compiler warning. // Dynamic casting from T1 to T and saving result in `this''s pointer PointerType p = dynamic_cast< PointerType >( GetImplRef( rhs ) ); + KP::OnDereference( p ); GetImplRef( *this ) = OP::Clone( p ); } @@ -1214,6 +1215,7 @@ (void)helper; // do void cast to remove compiler warning. // Dynamic casting from T1 to T and saving result in `this''s pointer PointerType p = dynamic_cast< PointerType >( GetImplRef( rhs ) ); + KP::OnDereference( p ); GetImplRef( *this ) = OP::Clone( p ); } @@ -1237,6 +1239,7 @@ SmartPtr(CopyArg& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { + KP::OnDereference( GetImpl( rhs ) ); GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } @@ -1252,6 +1255,7 @@ SmartPtr(const SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { + KP::OnDereference( GetImpl( rhs ) ); GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } @@ -1267,6 +1271,7 @@ SmartPtr(SmartPtr<T1, OP1, CP1, KP1, SP1, CNP1 >& rhs) : SP(rhs), OP(rhs), KP(rhs), CP(rhs) { + KP::OnDereference( GetImpl( rhs ) ); GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-07 20:04:44
|
Revision: 1093 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1093&view=rev Author: rich_sposato Date: 2011-09-07 20:04:38 +0000 (Wed, 07 Sep 2011) Log Message: ----------- Changed return type for assignment functions. Modified Paths: -------------- trunk/include/loki/SafeBits.h Modified: trunk/include/loki/SafeBits.h =================================================================== --- trunk/include/loki/SafeBits.h 2011-09-07 00:06:19 UTC (rev 1092) +++ trunk/include/loki/SafeBits.h 2011-09-07 20:04:38 UTC (rev 1093) @@ -250,12 +250,12 @@ // These operators are private, and will not instantiate in any // event because of the incomplete Forbidden_conversion struct. - template < typename T > SafeBitConst operator|( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitConst operator&( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitConst operator^( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitConst operator|=( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitConst operator&=( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitConst operator^=( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitConst & operator|( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitConst & operator&( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitConst & operator^( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitConst & operator|=( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitConst & operator&=( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitConst & operator^=( T ) const { Forbidden_conversion< T > wrong; return *this; } // And the same thing for comparisons: private and unusable. // if ( label1 == label2 ) { ... } @@ -333,17 +333,17 @@ SafeBitField operator & ( const SafeBitField & rhs ) const { return SafeBitField( word & rhs.word ); } SafeBitField operator ^ ( const SafeBitField & rhs ) const { return SafeBitField( word ^ rhs.word ); } SafeBitField operator ~ ( void ) const { return SafeBitField( ~word ); } - SafeBitField operator |= ( const SafeBitField & rhs ) { word |= rhs.word; return *this; } - SafeBitField operator &= ( const SafeBitField & rhs ) { word &= rhs.word; return *this; } - SafeBitField operator ^= ( const SafeBitField & rhs ) { word ^= rhs.word; return *this; } + SafeBitField & operator |= ( const SafeBitField & rhs ) { word |= rhs.word; return *this; } + SafeBitField & operator &= ( const SafeBitField & rhs ) { word &= rhs.word; return *this; } + SafeBitField & operator ^= ( const SafeBitField & rhs ) { word ^= rhs.word; return *this; } /// Bitwise operators that use bit-constants. SafeBitField operator | ( const_t rhs ) const { return SafeBitField( word | rhs.word ); } SafeBitField operator & ( const_t rhs ) const { return SafeBitField( word & rhs.word ); } SafeBitField operator ^ ( const_t rhs ) const { return SafeBitField( word ^ rhs.word ); } - SafeBitField operator |= ( const_t rhs ) { word |= rhs.word; return *this; } - SafeBitField operator &= ( const_t rhs ) { word &= rhs.word; return *this; } - SafeBitField operator ^= ( const_t rhs ) { word ^= rhs.word; return *this; } + SafeBitField & operator |= ( const_t rhs ) { word |= rhs.word; return *this; } + SafeBitField & operator &= ( const_t rhs ) { word &= rhs.word; return *this; } + SafeBitField & operator ^= ( const_t rhs ) { word ^= rhs.word; return *this; } // Conversion to bool. // This is a major source of headaches, but it's required to support code like this: @@ -361,15 +361,15 @@ // It is somewhat safer to convert to a pointer, at least pointers to different types cannot be readilly compared, and there are no // bitwise operations on pointers, but the conversion from word_t to a pointer can have run-time cost if they are of different size. // - operator const bool() const { return ( 0 != word ); } + operator bool() const { return ( 0 != word ); } // Shift operators shift bits inside the bit field. Does not make // sense, most of the time, except perhaps to loop over labels and // increment them. SafeBitField operator << ( unsigned int s ) { return SafeBitField( word << s ); } SafeBitField operator >> ( unsigned int s ) { return SafeBitField( word >> s ); } - SafeBitField operator <<= ( unsigned int s ) { word <<= s; return *this; } - SafeBitField operator >>= ( unsigned int s ) { word >>= s; return *this; } + SafeBitField & operator <<= ( unsigned int s ) { word <<= s; return *this; } + SafeBitField & operator >>= ( unsigned int s ) { word >>= s; return *this; } // Word size is also the maximum number of different bit fields for // a given word type. @@ -394,12 +394,12 @@ // These operators are private, and will not instantiate in any // event because of the incomplete Forbidden_conversion struct. - template < typename T > SafeBitField operator | ( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitField operator & ( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitField operator ^ ( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitField operator |= ( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitField operator &= ( T ) const { Forbidden_conversion< T > wrong; return *this; } - template < typename T > SafeBitField operator ^= ( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitField & operator | ( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitField & operator & ( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitField & operator ^ ( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitField & operator |= ( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitField & operator &= ( T ) const { Forbidden_conversion< T > wrong; return *this; } + template < typename T > SafeBitField & operator ^= ( T ) const { Forbidden_conversion< T > wrong; return *this; } // And the same thing for comparisons: // if ( label1 == label2 ) { ... } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ric...@us...> - 2011-09-07 00:06:25
|
Revision: 1092 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1092&view=rev Author: rich_sposato Date: 2011-09-07 00:06:19 +0000 (Wed, 07 Sep 2011) Log Message: ----------- Changed test program when working on bug 3106378. Modified Paths: -------------- trunk/test/SafeBits/SafeBitTest.cpp Modified: trunk/test/SafeBits/SafeBitTest.cpp =================================================================== --- trunk/test/SafeBits/SafeBitTest.cpp 2011-09-06 23:56:29 UTC (rev 1091) +++ trunk/test/SafeBits/SafeBitTest.cpp 2011-09-07 00:06:19 UTC (rev 1092) @@ -73,6 +73,7 @@ Cat_state cat_state = CAT_SLEEPING; assert( cat_state ); + Dog_state dog_now; Dog_state dog_state = DOG_DROOLING; assert( dog_state ); bool happy = cat_state & ( CAT_SLEEPING | CAT_PURRING ); // OK @@ -116,7 +117,8 @@ assert( state.size() == ( 8 * sizeof(unsigned int) ) ); assert( sizeof(Cat_state) == sizeof(unsigned int) ); - dog_state = DOG_BARKING; + dog_now = dog_state = DOG_BARKING; + assert( dog_now == dog_state ); #ifdef ERROR6 if ( dog_state == cat_state ) {} // Don't allow comparison of different types. #endif @@ -307,10 +309,12 @@ #endif - dog_state |= DOG_CHEWING; + dog_now = dog_state |= DOG_CHEWING; assert( dog_state & ( DOG_CHEWING | DOG_BARKING ) ); - dog_state &= DOG_CHEWING; + assert( dog_now == dog_state ); + dog_now = dog_state &= DOG_CHEWING; assert( dog_state == DOG_CHEWING ); + assert( dog_now == dog_state ); dog_state = ~dog_state; assert( dog_state != DOG_CHEWING ); dog_state = ~dog_state; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |