From 26d771c3a142e9863a40178ff97d66e74d4535b5 Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Mon, 2 Feb 2009 06:23:28 +0000 Subject: [PATCH] Changed pass-by-value to pass-by-reference. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@984 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/MultiMethods.h | 96 ++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/include/loki/MultiMethods.h b/include/loki/MultiMethods.h index 303f817..f41b2e0 100644 --- a/include/loki/MultiMethods.h +++ b/include/loki/MultiMethods.h @@ -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_MULTIMETHODS_INC_ @@ -38,18 +38,18 @@ namespace Loki namespace Private { - template struct InvocationTraits { - static ResultType - DoDispatch(SomeLhs& lhs, SomeRhs& rhs, + static ResultType + DoDispatch(SomeLhs& lhs, SomeRhs& rhs, Executor& exec, Int2Type) { return exec.Fire(lhs, rhs); } - static ResultType - DoDispatch(SomeLhs& lhs, SomeRhs& rhs, + static ResultType + DoDispatch(SomeLhs& lhs, SomeRhs& rhs, Executor& exec, Int2Type) { return exec.Fire(rhs, lhs); @@ -65,7 +65,7 @@ namespace Loki template < class Executor, - class BaseLhs, + class BaseLhs, class TypesLhs, bool symmetric = true, class BaseRhs = BaseLhs, @@ -76,35 +76,35 @@ namespace Loki { template static ResultType DispatchRhs(SomeLhs& lhs, BaseRhs& rhs, - Executor exec, NullType) + Executor & exec, NullType) { return exec.OnError(lhs, rhs); } - + template static ResultType DispatchRhs(SomeLhs& lhs, BaseRhs& rhs, - Executor exec, Typelist) - { + Executor & exec, Typelist) + { if (Head* p2 = dynamic_cast(&rhs)) { Int2Type<(symmetric && int(TL::IndexOf::value) < int(TL::IndexOf::value))> i2t; - typedef Private::InvocationTraits< + typedef Private::InvocationTraits< SomeLhs, Head, Executor, ResultType> CallTraits; - + return CallTraits::DoDispatch(lhs, *p2, exec, i2t); } return DispatchRhs(lhs, rhs, exec, Tail()); } - + static ResultType DispatchLhs(BaseLhs& lhs, BaseRhs& rhs, - Executor exec, NullType) + Executor & exec, NullType) { return exec.OnError(lhs, rhs); } - + template static ResultType DispatchLhs(BaseLhs& lhs, BaseRhs& rhs, - Executor exec, Typelist) - { + Executor & exec, Typelist) + { if (Head* p1 = dynamic_cast(&lhs)) { return DispatchRhs(*p1, rhs, exec, TypesRhs()); @@ -114,10 +114,10 @@ namespace Loki public: static ResultType Go(BaseLhs& lhs, BaseRhs& rhs, - Executor exec) + Executor & exec) { return DispatchLhs(lhs, rhs, exec, TypesLhs()); } }; - + //////////////////////////////////////////////////////////////////////////////// // class template BasicDispatcher // Implements a logarithmic double dispatcher for functors (or functions) @@ -137,36 +137,36 @@ namespace Loki typedef CallbackType MappedType; typedef AssocVector MapType; MapType callbackMap_; - + void DoAdd(TypeInfo lhs, TypeInfo rhs, CallbackType fun); bool DoRemove(TypeInfo lhs, TypeInfo rhs); - + public: template void Add(CallbackType fun) { DoAdd(typeid(SomeLhs), typeid(SomeRhs), fun); } - + template bool Remove() { return DoRemove(typeid(SomeLhs), typeid(SomeRhs)); } - + ResultType Go(BaseLhs& lhs, BaseRhs& rhs); }; // Non-inline to reduce compile time overhead... - template void BasicDispatcher ::DoAdd(TypeInfo lhs, TypeInfo rhs, CallbackType fun) { callbackMap_[KeyType(lhs, rhs)] = fun; } - - template bool BasicDispatcher ::DoRemove(TypeInfo lhs, TypeInfo rhs) @@ -174,7 +174,7 @@ namespace Loki return callbackMap_.erase(KeyType(lhs, rhs)) == 1; } - template ResultType BasicDispatcher ::Go(BaseLhs& lhs, BaseRhs& rhs) @@ -254,42 +254,42 @@ namespace Loki class DispatcherBackend = BasicDispatcher> class FnDispatcher { - DispatcherBackend backEnd_; - + public: template void Add(ResultType (*pFun)(BaseLhs&, BaseRhs&)) { return backEnd_.template Add(pFun); - } - + } + template void Add() { typedef Private::FnDispatcherHelper< - BaseLhs, BaseRhs, + BaseLhs, BaseRhs, SomeLhs, SomeRhs, ResultType, - CastingPolicy, - CastingPolicy, + CastingPolicy, + CastingPolicy, callback> Local; Add(&Local::Trampoline); } - + template void Add(bool = true) // [gcc] dummy bool { typedef Private::FnDispatcherHelper< - BaseLhs, BaseRhs, + BaseLhs, BaseRhs, SomeLhs, SomeRhs, ResultType, - CastingPolicy, - CastingPolicy, + CastingPolicy, + CastingPolicy, callback> Local; Add(&Local::Trampoline); @@ -298,7 +298,7 @@ namespace Loki Add(&Local::TrampolineR); } } - + template void Remove() { @@ -323,7 +323,7 @@ namespace Loki typename ResultType, class CastLhs, class CastRhs, class Fun, bool SwapArgs> - class FunctorDispatcherHelper + class FunctorDispatcherHelper { Fun fun_; ResultType Fire(BaseLhs& lhs, BaseRhs& rhs,Int2Type) @@ -352,7 +352,7 @@ namespace Loki template class CastingPolicy = DynamicCaster, + template class CastingPolicy = DynamicCaster, template class DispatcherBackend = BasicDispatcher> class FunctorDispatcher @@ -395,7 +395,7 @@ namespace Loki backEnd_.template Add(FunctorType(AdapterR(fun))); } } - + template void Remove() {