diff --git a/dlls/cstrike/cstrike/AMBuilder b/modules/cstrike/cstrike/AMBuilder similarity index 100% rename from dlls/cstrike/cstrike/AMBuilder rename to modules/cstrike/cstrike/AMBuilder diff --git a/dlls/cstrike/cstrike/CstrikeDatas.h b/modules/cstrike/cstrike/CstrikeDatas.h similarity index 100% rename from dlls/cstrike/cstrike/CstrikeDatas.h rename to modules/cstrike/cstrike/CstrikeDatas.h diff --git a/dlls/cstrike/cstrike/CstrikeHLTypeConversion.cpp b/modules/cstrike/cstrike/CstrikeHLTypeConversion.cpp similarity index 100% rename from dlls/cstrike/cstrike/CstrikeHLTypeConversion.cpp rename to modules/cstrike/cstrike/CstrikeHLTypeConversion.cpp diff --git a/dlls/cstrike/cstrike/CstrikeHLTypeConversion.h b/modules/cstrike/cstrike/CstrikeHLTypeConversion.h similarity index 100% rename from dlls/cstrike/cstrike/CstrikeHLTypeConversion.h rename to modules/cstrike/cstrike/CstrikeHLTypeConversion.h diff --git a/dlls/cstrike/cstrike/CstrikeHacks.cpp b/modules/cstrike/cstrike/CstrikeHacks.cpp similarity index 100% rename from dlls/cstrike/cstrike/CstrikeHacks.cpp rename to modules/cstrike/cstrike/CstrikeHacks.cpp diff --git a/dlls/cstrike/cstrike/CstrikeNatives.cpp b/modules/cstrike/cstrike/CstrikeNatives.cpp similarity index 100% rename from dlls/cstrike/cstrike/CstrikeNatives.cpp rename to modules/cstrike/cstrike/CstrikeNatives.cpp diff --git a/dlls/cstrike/cstrike/CstrikePlayer.cpp b/modules/cstrike/cstrike/CstrikePlayer.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/cstrike/CstrikePlayer.cpp rename to modules/cstrike/cstrike/CstrikePlayer.cpp diff --git a/dlls/cstrike/cstrike/CstrikePlayer.h b/modules/cstrike/cstrike/CstrikePlayer.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/cstrike/CstrikePlayer.h rename to modules/cstrike/cstrike/CstrikePlayer.h diff --git a/dlls/cstrike/cstrike/CstrikeUtils.cpp b/modules/cstrike/cstrike/CstrikeUtils.cpp similarity index 100% rename from dlls/cstrike/cstrike/CstrikeUtils.cpp rename to modules/cstrike/cstrike/CstrikeUtils.cpp diff --git a/dlls/cstrike/cstrike/CstrikeUtils.h b/modules/cstrike/cstrike/CstrikeUtils.h similarity index 100% rename from dlls/cstrike/cstrike/CstrikeUtils.h rename to modules/cstrike/cstrike/CstrikeUtils.h diff --git a/dlls/cstrike/cstrike/Makefile b/modules/cstrike/cstrike/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/cstrike/Makefile rename to modules/cstrike/cstrike/Makefile diff --git a/dlls/cstrike/cstrike/amxx_api.cpp b/modules/cstrike/cstrike/amxx_api.cpp similarity index 100% rename from dlls/cstrike/cstrike/amxx_api.cpp rename to modules/cstrike/cstrike/amxx_api.cpp diff --git a/dlls/cstrike/cstrike/moduleconfig.h b/modules/cstrike/cstrike/moduleconfig.h similarity index 100% rename from dlls/cstrike/cstrike/moduleconfig.h rename to modules/cstrike/cstrike/moduleconfig.h diff --git a/dlls/cstrike/cstrike/msvc12/cstrike.sln b/modules/cstrike/cstrike/msvc12/cstrike.sln similarity index 100% rename from dlls/cstrike/cstrike/msvc12/cstrike.sln rename to modules/cstrike/cstrike/msvc12/cstrike.sln diff --git a/dlls/cstrike/cstrike/msvc12/cstrike.vcxproj b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj similarity index 100% rename from dlls/cstrike/cstrike/msvc12/cstrike.vcxproj rename to modules/cstrike/cstrike/msvc12/cstrike.vcxproj diff --git a/dlls/cstrike/cstrike/msvc12/cstrike.vcxproj.filters b/modules/cstrike/cstrike/msvc12/cstrike.vcxproj.filters similarity index 100% rename from dlls/cstrike/cstrike/msvc12/cstrike.vcxproj.filters rename to modules/cstrike/cstrike/msvc12/cstrike.vcxproj.filters diff --git a/dlls/cstrike/cstrike/version.rc b/modules/cstrike/cstrike/version.rc similarity index 100% rename from dlls/cstrike/cstrike/version.rc rename to modules/cstrike/cstrike/version.rc diff --git a/dlls/cstrike/csx/AMBuilder b/modules/cstrike/csx/AMBuilder similarity index 100% rename from dlls/cstrike/csx/AMBuilder rename to modules/cstrike/csx/AMBuilder diff --git a/dlls/cstrike/csx/CMisc.cpp b/modules/cstrike/csx/CMisc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/CMisc.cpp rename to modules/cstrike/csx/CMisc.cpp diff --git a/dlls/cstrike/csx/CMisc.h b/modules/cstrike/csx/CMisc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/CMisc.h rename to modules/cstrike/csx/CMisc.h diff --git a/dlls/cstrike/csx/CRank.cpp b/modules/cstrike/csx/CRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/CRank.cpp rename to modules/cstrike/csx/CRank.cpp diff --git a/dlls/cstrike/csx/CRank.h b/modules/cstrike/csx/CRank.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/CRank.h rename to modules/cstrike/csx/CRank.h diff --git a/dlls/cstrike/csx/Makefile b/modules/cstrike/csx/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/Makefile rename to modules/cstrike/csx/Makefile diff --git a/dlls/cstrike/csx/WinCSX/AMBuilder b/modules/cstrike/csx/WinCSX/AMBuilder similarity index 100% rename from dlls/cstrike/csx/WinCSX/AMBuilder rename to modules/cstrike/csx/WinCSX/AMBuilder diff --git a/dlls/cstrike/csx/WinCSX/CRank.cpp b/modules/cstrike/csx/WinCSX/CRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/CRank.cpp rename to modules/cstrike/csx/WinCSX/CRank.cpp diff --git a/dlls/cstrike/csx/WinCSX/CRank.h b/modules/cstrike/csx/WinCSX/CRank.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/CRank.h rename to modules/cstrike/csx/WinCSX/CRank.h diff --git a/dlls/cstrike/csx/WinCSX/WinCSX.cpp b/modules/cstrike/csx/WinCSX/WinCSX.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/WinCSX.cpp rename to modules/cstrike/csx/WinCSX/WinCSX.cpp diff --git a/dlls/cstrike/csx/WinCSX/WinCSX.h b/modules/cstrike/csx/WinCSX/WinCSX.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/WinCSX.h rename to modules/cstrike/csx/WinCSX/WinCSX.h diff --git a/dlls/cstrike/csx/WinCSX/moduleconfig.h b/modules/cstrike/csx/WinCSX/moduleconfig.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/moduleconfig.h rename to modules/cstrike/csx/WinCSX/moduleconfig.h diff --git a/dlls/cstrike/csx/WinCSX/msvc12/WinCSX.sln b/modules/cstrike/csx/WinCSX/msvc12/WinCSX.sln similarity index 100% rename from dlls/cstrike/csx/WinCSX/msvc12/WinCSX.sln rename to modules/cstrike/csx/WinCSX/msvc12/WinCSX.sln diff --git a/dlls/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj b/modules/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj similarity index 100% rename from dlls/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj rename to modules/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj diff --git a/dlls/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj.filters b/modules/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj.filters similarity index 100% rename from dlls/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj.filters rename to modules/cstrike/csx/WinCSX/msvc12/WinCSX.vcxproj.filters diff --git a/dlls/cstrike/csx/WinCSX/resources/Resource.h b/modules/cstrike/csx/WinCSX/resources/Resource.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/resources/Resource.h rename to modules/cstrike/csx/WinCSX/resources/Resource.h diff --git a/dlls/cstrike/csx/WinCSX/resources/WinCSX.exe.manifest b/modules/cstrike/csx/WinCSX/resources/WinCSX.exe.manifest similarity index 100% rename from dlls/cstrike/csx/WinCSX/resources/WinCSX.exe.manifest rename to modules/cstrike/csx/WinCSX/resources/WinCSX.exe.manifest diff --git a/dlls/cstrike/csx/WinCSX/resources/WinCSX.ico b/modules/cstrike/csx/WinCSX/resources/WinCSX.ico old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/resources/WinCSX.ico rename to modules/cstrike/csx/WinCSX/resources/WinCSX.ico diff --git a/dlls/cstrike/csx/WinCSX/resources/WinCSX.rc b/modules/cstrike/csx/WinCSX/resources/WinCSX.rc old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/resources/WinCSX.rc rename to modules/cstrike/csx/WinCSX/resources/WinCSX.rc diff --git a/dlls/cstrike/csx/WinCSX/resources/small.ico b/modules/cstrike/csx/WinCSX/resources/small.ico old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/resources/small.ico rename to modules/cstrike/csx/WinCSX/resources/small.ico diff --git a/dlls/cstrike/csx/WinCSX/stdafx.cpp b/modules/cstrike/csx/WinCSX/stdafx.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/stdafx.cpp rename to modules/cstrike/csx/WinCSX/stdafx.cpp diff --git a/dlls/cstrike/csx/WinCSX/stdafx.h b/modules/cstrike/csx/WinCSX/stdafx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/WinCSX/stdafx.h rename to modules/cstrike/csx/WinCSX/stdafx.h diff --git a/dlls/cstrike/csx/meta_api.cpp b/modules/cstrike/csx/meta_api.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/meta_api.cpp rename to modules/cstrike/csx/meta_api.cpp diff --git a/dlls/cstrike/csx/moduleconfig.h b/modules/cstrike/csx/moduleconfig.h similarity index 100% rename from dlls/cstrike/csx/moduleconfig.h rename to modules/cstrike/csx/moduleconfig.h diff --git a/dlls/cstrike/csx/msvc12/csx.sln b/modules/cstrike/csx/msvc12/csx.sln similarity index 100% rename from dlls/cstrike/csx/msvc12/csx.sln rename to modules/cstrike/csx/msvc12/csx.sln diff --git a/dlls/cstrike/csx/msvc12/csx.vcxproj b/modules/cstrike/csx/msvc12/csx.vcxproj similarity index 100% rename from dlls/cstrike/csx/msvc12/csx.vcxproj rename to modules/cstrike/csx/msvc12/csx.vcxproj diff --git a/dlls/cstrike/csx/msvc12/csx.vcxproj.filters b/modules/cstrike/csx/msvc12/csx.vcxproj.filters similarity index 100% rename from dlls/cstrike/csx/msvc12/csx.vcxproj.filters rename to modules/cstrike/csx/msvc12/csx.vcxproj.filters diff --git a/dlls/cstrike/csx/rank.cpp b/modules/cstrike/csx/rank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/rank.cpp rename to modules/cstrike/csx/rank.cpp diff --git a/dlls/cstrike/csx/rank.h b/modules/cstrike/csx/rank.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/rank.h rename to modules/cstrike/csx/rank.h diff --git a/dlls/cstrike/csx/usermsg.cpp b/modules/cstrike/csx/usermsg.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/cstrike/csx/usermsg.cpp rename to modules/cstrike/csx/usermsg.cpp diff --git a/dlls/cstrike/csx/version.rc b/modules/cstrike/csx/version.rc similarity index 100% rename from dlls/cstrike/csx/version.rc rename to modules/cstrike/csx/version.rc diff --git a/dlls/dod/dodfun/AMBuilder b/modules/dod/dodfun/AMBuilder similarity index 100% rename from dlls/dod/dodfun/AMBuilder rename to modules/dod/dodfun/AMBuilder diff --git a/dlls/dod/dodfun/CMisc.cpp b/modules/dod/dodfun/CMisc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/CMisc.cpp rename to modules/dod/dodfun/CMisc.cpp diff --git a/dlls/dod/dodfun/CMisc.h b/modules/dod/dodfun/CMisc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/CMisc.h rename to modules/dod/dodfun/CMisc.h diff --git a/dlls/dod/dodfun/Makefile b/modules/dod/dodfun/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/Makefile rename to modules/dod/dodfun/Makefile diff --git a/dlls/dod/dodfun/NBase.cpp b/modules/dod/dodfun/NBase.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/NBase.cpp rename to modules/dod/dodfun/NBase.cpp diff --git a/dlls/dod/dodfun/NPD.cpp b/modules/dod/dodfun/NPD.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/NPD.cpp rename to modules/dod/dodfun/NPD.cpp diff --git a/dlls/dod/dodfun/Utils.cpp b/modules/dod/dodfun/Utils.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/Utils.cpp rename to modules/dod/dodfun/Utils.cpp diff --git a/dlls/dod/dodfun/dodfun.h b/modules/dod/dodfun/dodfun.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/dodfun.h rename to modules/dod/dodfun/dodfun.h diff --git a/dlls/dod/dodfun/moduleconfig.cpp b/modules/dod/dodfun/moduleconfig.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/moduleconfig.cpp rename to modules/dod/dodfun/moduleconfig.cpp diff --git a/dlls/dod/dodfun/moduleconfig.h b/modules/dod/dodfun/moduleconfig.h similarity index 100% rename from dlls/dod/dodfun/moduleconfig.h rename to modules/dod/dodfun/moduleconfig.h diff --git a/dlls/dod/dodfun/msvc12/dodfun.sln b/modules/dod/dodfun/msvc12/dodfun.sln similarity index 100% rename from dlls/dod/dodfun/msvc12/dodfun.sln rename to modules/dod/dodfun/msvc12/dodfun.sln diff --git a/dlls/dod/dodfun/msvc12/dodfun.vcxproj b/modules/dod/dodfun/msvc12/dodfun.vcxproj similarity index 100% rename from dlls/dod/dodfun/msvc12/dodfun.vcxproj rename to modules/dod/dodfun/msvc12/dodfun.vcxproj diff --git a/dlls/dod/dodfun/msvc12/dodfun.vcxproj.filters b/modules/dod/dodfun/msvc12/dodfun.vcxproj.filters similarity index 100% rename from dlls/dod/dodfun/msvc12/dodfun.vcxproj.filters rename to modules/dod/dodfun/msvc12/dodfun.vcxproj.filters diff --git a/dlls/dod/dodfun/usermsg.cpp b/modules/dod/dodfun/usermsg.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodfun/usermsg.cpp rename to modules/dod/dodfun/usermsg.cpp diff --git a/dlls/dod/dodfun/version.rc b/modules/dod/dodfun/version.rc similarity index 100% rename from dlls/dod/dodfun/version.rc rename to modules/dod/dodfun/version.rc diff --git a/dlls/dod/dodx/AMBuilder b/modules/dod/dodx/AMBuilder similarity index 100% rename from dlls/dod/dodx/AMBuilder rename to modules/dod/dodx/AMBuilder diff --git a/dlls/dod/dodx/CMisc.cpp b/modules/dod/dodx/CMisc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/CMisc.cpp rename to modules/dod/dodx/CMisc.cpp diff --git a/dlls/dod/dodx/CMisc.h b/modules/dod/dodx/CMisc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/CMisc.h rename to modules/dod/dodx/CMisc.h diff --git a/dlls/dod/dodx/CRank.cpp b/modules/dod/dodx/CRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/CRank.cpp rename to modules/dod/dodx/CRank.cpp diff --git a/dlls/dod/dodx/CRank.h b/modules/dod/dodx/CRank.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/CRank.h rename to modules/dod/dodx/CRank.h diff --git a/dlls/dod/dodx/Makefile b/modules/dod/dodx/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/Makefile rename to modules/dod/dodx/Makefile diff --git a/dlls/dod/dodx/NBase.cpp b/modules/dod/dodx/NBase.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/NBase.cpp rename to modules/dod/dodx/NBase.cpp diff --git a/dlls/dod/dodx/NRank.cpp b/modules/dod/dodx/NRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/NRank.cpp rename to modules/dod/dodx/NRank.cpp diff --git a/dlls/dod/dodx/Utils.cpp b/modules/dod/dodx/Utils.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/Utils.cpp rename to modules/dod/dodx/Utils.cpp diff --git a/dlls/dod/dodx/dodx.h b/modules/dod/dodx/dodx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/dodx.h rename to modules/dod/dodx/dodx.h diff --git a/dlls/dod/dodx/moduleconfig.cpp b/modules/dod/dodx/moduleconfig.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/moduleconfig.cpp rename to modules/dod/dodx/moduleconfig.cpp diff --git a/dlls/dod/dodx/moduleconfig.h b/modules/dod/dodx/moduleconfig.h similarity index 100% rename from dlls/dod/dodx/moduleconfig.h rename to modules/dod/dodx/moduleconfig.h diff --git a/dlls/dod/dodx/msvc12/dodx.sln b/modules/dod/dodx/msvc12/dodx.sln similarity index 100% rename from dlls/dod/dodx/msvc12/dodx.sln rename to modules/dod/dodx/msvc12/dodx.sln diff --git a/dlls/dod/dodx/msvc12/dodx.vcxproj b/modules/dod/dodx/msvc12/dodx.vcxproj similarity index 100% rename from dlls/dod/dodx/msvc12/dodx.vcxproj rename to modules/dod/dodx/msvc12/dodx.vcxproj diff --git a/dlls/dod/dodx/msvc12/dodx.vcxproj.filters b/modules/dod/dodx/msvc12/dodx.vcxproj.filters similarity index 100% rename from dlls/dod/dodx/msvc12/dodx.vcxproj.filters rename to modules/dod/dodx/msvc12/dodx.vcxproj.filters diff --git a/dlls/dod/dodx/usermsg.cpp b/modules/dod/dodx/usermsg.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/dod/dodx/usermsg.cpp rename to modules/dod/dodx/usermsg.cpp diff --git a/dlls/dod/dodx/version.rc b/modules/dod/dodx/version.rc similarity index 100% rename from dlls/dod/dodx/version.rc rename to modules/dod/dodx/version.rc diff --git a/dlls/engine/AMBuilder b/modules/engine/AMBuilder similarity index 100% rename from dlls/engine/AMBuilder rename to modules/engine/AMBuilder diff --git a/dlls/engine/Makefile b/modules/engine/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/Makefile rename to modules/engine/Makefile diff --git a/dlls/engine/amxxapi.cpp b/modules/engine/amxxapi.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/amxxapi.cpp rename to modules/engine/amxxapi.cpp diff --git a/dlls/engine/engine.cpp b/modules/engine/engine.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/engine.cpp rename to modules/engine/engine.cpp diff --git a/dlls/engine/engine.h b/modules/engine/engine.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/engine.h rename to modules/engine/engine.h diff --git a/dlls/engine/entity.cpp b/modules/engine/entity.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/entity.cpp rename to modules/engine/entity.cpp diff --git a/dlls/engine/entity.h b/modules/engine/entity.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/entity.h rename to modules/engine/entity.h diff --git a/dlls/engine/forwards.cpp b/modules/engine/forwards.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/forwards.cpp rename to modules/engine/forwards.cpp diff --git a/dlls/engine/globals.cpp b/modules/engine/globals.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/globals.cpp rename to modules/engine/globals.cpp diff --git a/dlls/engine/gpglobals.h b/modules/engine/gpglobals.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/engine/gpglobals.h rename to modules/engine/gpglobals.h diff --git a/dlls/engine/moduleconfig.h b/modules/engine/moduleconfig.h similarity index 100% rename from dlls/engine/moduleconfig.h rename to modules/engine/moduleconfig.h diff --git a/dlls/engine/msvc12/engine.sln b/modules/engine/msvc12/engine.sln similarity index 100% rename from dlls/engine/msvc12/engine.sln rename to modules/engine/msvc12/engine.sln diff --git a/dlls/engine/msvc12/engine.vcxproj b/modules/engine/msvc12/engine.vcxproj similarity index 100% rename from dlls/engine/msvc12/engine.vcxproj rename to modules/engine/msvc12/engine.vcxproj diff --git a/dlls/engine/msvc12/engine.vcxproj.filters b/modules/engine/msvc12/engine.vcxproj.filters similarity index 100% rename from dlls/engine/msvc12/engine.vcxproj.filters rename to modules/engine/msvc12/engine.vcxproj.filters diff --git a/dlls/engine/version.rc b/modules/engine/version.rc similarity index 100% rename from dlls/engine/version.rc rename to modules/engine/version.rc diff --git a/dlls/fakemeta/AMBuilder b/modules/fakemeta/AMBuilder similarity index 100% rename from dlls/fakemeta/AMBuilder rename to modules/fakemeta/AMBuilder diff --git a/dlls/fakemeta/Makefile b/modules/fakemeta/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/Makefile rename to modules/fakemeta/Makefile diff --git a/dlls/fakemeta/dllfunc.cpp b/modules/fakemeta/dllfunc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/dllfunc.cpp rename to modules/fakemeta/dllfunc.cpp diff --git a/dlls/fakemeta/dllfunc.h b/modules/fakemeta/dllfunc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/dllfunc.h rename to modules/fakemeta/dllfunc.h diff --git a/dlls/fakemeta/engfunc.cpp b/modules/fakemeta/engfunc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/engfunc.cpp rename to modules/fakemeta/engfunc.cpp diff --git a/dlls/fakemeta/engfunc.h b/modules/fakemeta/engfunc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/engfunc.h rename to modules/fakemeta/engfunc.h diff --git a/dlls/fakemeta/fakemeta_amxx.cpp b/modules/fakemeta/fakemeta_amxx.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/fakemeta_amxx.cpp rename to modules/fakemeta/fakemeta_amxx.cpp diff --git a/dlls/fakemeta/fakemeta_amxx.h b/modules/fakemeta/fakemeta_amxx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/fakemeta_amxx.h rename to modules/fakemeta/fakemeta_amxx.h diff --git a/dlls/fakemeta/fm_tr.cpp b/modules/fakemeta/fm_tr.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/fm_tr.cpp rename to modules/fakemeta/fm_tr.cpp diff --git a/dlls/fakemeta/fm_tr.h b/modules/fakemeta/fm_tr.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/fm_tr.h rename to modules/fakemeta/fm_tr.h diff --git a/dlls/fakemeta/fm_tr2.cpp b/modules/fakemeta/fm_tr2.cpp similarity index 100% rename from dlls/fakemeta/fm_tr2.cpp rename to modules/fakemeta/fm_tr2.cpp diff --git a/dlls/fakemeta/forward.cpp b/modules/fakemeta/forward.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/forward.cpp rename to modules/fakemeta/forward.cpp diff --git a/dlls/fakemeta/forward.h b/modules/fakemeta/forward.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/forward.h rename to modules/fakemeta/forward.h diff --git a/dlls/fakemeta/forwardmacros.h b/modules/fakemeta/forwardmacros.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/forwardmacros.h rename to modules/fakemeta/forwardmacros.h diff --git a/dlls/fakemeta/glb.cpp b/modules/fakemeta/glb.cpp similarity index 100% rename from dlls/fakemeta/glb.cpp rename to modules/fakemeta/glb.cpp diff --git a/dlls/fakemeta/glb.h b/modules/fakemeta/glb.h similarity index 100% rename from dlls/fakemeta/glb.h rename to modules/fakemeta/glb.h diff --git a/dlls/fakemeta/misc.cpp b/modules/fakemeta/misc.cpp similarity index 100% rename from dlls/fakemeta/misc.cpp rename to modules/fakemeta/misc.cpp diff --git a/dlls/fakemeta/moduleconfig.h b/modules/fakemeta/moduleconfig.h similarity index 100% rename from dlls/fakemeta/moduleconfig.h rename to modules/fakemeta/moduleconfig.h diff --git a/dlls/fakemeta/msvc12/fakemeta.sln b/modules/fakemeta/msvc12/fakemeta.sln similarity index 100% rename from dlls/fakemeta/msvc12/fakemeta.sln rename to modules/fakemeta/msvc12/fakemeta.sln diff --git a/dlls/fakemeta/msvc12/fakemeta.vcxproj b/modules/fakemeta/msvc12/fakemeta.vcxproj similarity index 100% rename from dlls/fakemeta/msvc12/fakemeta.vcxproj rename to modules/fakemeta/msvc12/fakemeta.vcxproj diff --git a/dlls/fakemeta/msvc12/fakemeta.vcxproj.filters b/modules/fakemeta/msvc12/fakemeta.vcxproj.filters similarity index 100% rename from dlls/fakemeta/msvc12/fakemeta.vcxproj.filters rename to modules/fakemeta/msvc12/fakemeta.vcxproj.filters diff --git a/dlls/fakemeta/pdata.cpp b/modules/fakemeta/pdata.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/pdata.cpp rename to modules/fakemeta/pdata.cpp diff --git a/dlls/fakemeta/pev.cpp b/modules/fakemeta/pev.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/pev.cpp rename to modules/fakemeta/pev.cpp diff --git a/dlls/fakemeta/pev.h b/modules/fakemeta/pev.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fakemeta/pev.h rename to modules/fakemeta/pev.h diff --git a/dlls/fakemeta/version.rc b/modules/fakemeta/version.rc similarity index 100% rename from dlls/fakemeta/version.rc rename to modules/fakemeta/version.rc diff --git a/dlls/fun/AMBuilder b/modules/fun/AMBuilder similarity index 100% rename from dlls/fun/AMBuilder rename to modules/fun/AMBuilder diff --git a/dlls/fun/Makefile b/modules/fun/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/fun/Makefile rename to modules/fun/Makefile diff --git a/dlls/fun/fun.cpp b/modules/fun/fun.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/fun/fun.cpp rename to modules/fun/fun.cpp diff --git a/dlls/fun/fun.h b/modules/fun/fun.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/fun/fun.h rename to modules/fun/fun.h diff --git a/dlls/fun/moduleconfig.h b/modules/fun/moduleconfig.h similarity index 100% rename from dlls/fun/moduleconfig.h rename to modules/fun/moduleconfig.h diff --git a/dlls/fun/msvc12/fun.sln b/modules/fun/msvc12/fun.sln similarity index 100% rename from dlls/fun/msvc12/fun.sln rename to modules/fun/msvc12/fun.sln diff --git a/dlls/fun/msvc12/fun.vcxproj b/modules/fun/msvc12/fun.vcxproj similarity index 100% rename from dlls/fun/msvc12/fun.vcxproj rename to modules/fun/msvc12/fun.vcxproj diff --git a/dlls/fun/msvc12/fun.vcxproj.filters b/modules/fun/msvc12/fun.vcxproj.filters similarity index 100% rename from dlls/fun/msvc12/fun.vcxproj.filters rename to modules/fun/msvc12/fun.vcxproj.filters diff --git a/dlls/fun/version.rc b/modules/fun/version.rc similarity index 100% rename from dlls/fun/version.rc rename to modules/fun/version.rc diff --git a/dlls/geoip/AMBuilder b/modules/geoip/AMBuilder similarity index 100% rename from dlls/geoip/AMBuilder rename to modules/geoip/AMBuilder diff --git a/dlls/geoip/GeoLite2-Country.mmdb b/modules/geoip/GeoLite2-Country.mmdb similarity index 100% rename from dlls/geoip/GeoLite2-Country.mmdb rename to modules/geoip/GeoLite2-Country.mmdb diff --git a/dlls/geoip/Makefile b/modules/geoip/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/geoip/Makefile rename to modules/geoip/Makefile diff --git a/dlls/geoip/geoip_amxx.h b/modules/geoip/geoip_amxx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/geoip/geoip_amxx.h rename to modules/geoip/geoip_amxx.h diff --git a/dlls/geoip/geoip_main.cpp b/modules/geoip/geoip_main.cpp similarity index 100% rename from dlls/geoip/geoip_main.cpp rename to modules/geoip/geoip_main.cpp diff --git a/dlls/geoip/geoip_main.h b/modules/geoip/geoip_main.h similarity index 100% rename from dlls/geoip/geoip_main.h rename to modules/geoip/geoip_main.h diff --git a/dlls/geoip/geoip_natives.cpp b/modules/geoip/geoip_natives.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/geoip/geoip_natives.cpp rename to modules/geoip/geoip_natives.cpp diff --git a/dlls/geoip/geoip_natives.h b/modules/geoip/geoip_natives.h similarity index 100% rename from dlls/geoip/geoip_natives.h rename to modules/geoip/geoip_natives.h diff --git a/dlls/geoip/geoip_util.cpp b/modules/geoip/geoip_util.cpp similarity index 100% rename from dlls/geoip/geoip_util.cpp rename to modules/geoip/geoip_util.cpp diff --git a/dlls/geoip/geoip_util.h b/modules/geoip/geoip_util.h similarity index 100% rename from dlls/geoip/geoip_util.h rename to modules/geoip/geoip_util.h diff --git a/dlls/geoip/moduleconfig.h b/modules/geoip/moduleconfig.h similarity index 100% rename from dlls/geoip/moduleconfig.h rename to modules/geoip/moduleconfig.h diff --git a/dlls/geoip/msvc12/geoip.sln b/modules/geoip/msvc12/geoip.sln similarity index 100% rename from dlls/geoip/msvc12/geoip.sln rename to modules/geoip/msvc12/geoip.sln diff --git a/dlls/geoip/msvc12/geoip.vcxproj b/modules/geoip/msvc12/geoip.vcxproj similarity index 100% rename from dlls/geoip/msvc12/geoip.vcxproj rename to modules/geoip/msvc12/geoip.vcxproj diff --git a/dlls/geoip/msvc12/geoip.vcxproj.filters b/modules/geoip/msvc12/geoip.vcxproj.filters similarity index 100% rename from dlls/geoip/msvc12/geoip.vcxproj.filters rename to modules/geoip/msvc12/geoip.vcxproj.filters diff --git a/dlls/geoip/version.rc b/modules/geoip/version.rc similarity index 100% rename from dlls/geoip/version.rc rename to modules/geoip/version.rc diff --git a/dlls/hamsandwich/AMBuilder b/modules/hamsandwich/AMBuilder similarity index 100% rename from dlls/hamsandwich/AMBuilder rename to modules/hamsandwich/AMBuilder diff --git a/dlls/hamsandwich/DataHandler.cpp b/modules/hamsandwich/DataHandler.cpp similarity index 100% rename from dlls/hamsandwich/DataHandler.cpp rename to modules/hamsandwich/DataHandler.cpp diff --git a/dlls/hamsandwich/DataHandler.h b/modules/hamsandwich/DataHandler.h similarity index 100% rename from dlls/hamsandwich/DataHandler.h rename to modules/hamsandwich/DataHandler.h diff --git a/dlls/hamsandwich/Makefile b/modules/hamsandwich/Makefile similarity index 96% rename from dlls/hamsandwich/Makefile rename to modules/hamsandwich/Makefile index e9006e2b..53135534 100644 --- a/dlls/hamsandwich/Makefile +++ b/modules/hamsandwich/Makefile @@ -1,125 +1,125 @@ -# (C)2004-2013 AMX Mod X Development Team -# Makefile written by David "BAILOPAN" Anderson - -########################################### -### EDIT THESE PATHS FOR YOUR OWN SETUP ### -########################################### - -HLSDK = ../../../hlsdk -MM_ROOT = ../../../metamod/metamod -PUBLIC_ROOT = ../../public - -##################################### -### EDIT BELOW FOR OTHER PROJECTS ### -##################################### - -PROJECT = hamsandwich - -OBJECTS = amxxmodule.cpp amxx_api.cpp config_parser.cpp hook_callbacks.cpp hook_native.cpp \ - srvcmd.cpp call_funcs.cpp hook_create.cpp DataHandler.cpp pdata.cpp hook_specialbot.cpp - -############################################## -### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### -############################################## - -C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -fomit-frame-pointer -pipe -C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 -C_GCC4_FLAGS = -fvisibility=hidden -CPP_GCC4_FLAGS = -fvisibility-inlines-hidden -CPP = gcc -CPP_OSX = clang - -LINK = - -INCLUDE = -I. -I$(PUBLIC_ROOT) -I$(PUBLIC_ROOT)/sdk -I$(PUBLIC_ROOT)/amtl \ - -I$(HLSDK) -I$(HLSDK)/public -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared\ - -I$(MM_ROOT) - -################################################ -### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ### -################################################ - -OS := $(shell uname -s) - -ifeq "$(OS)" "Darwin" - CPP = $(CPP_OSX) - LIB_EXT = dylib - LIB_SUFFIX = _amxx - CFLAGS += -DOSX - LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5 -else - LIB_EXT = so - LIB_SUFFIX = _amxx_i386 - CFLAGS += -DLINUX - LINK += -shared -endif - -LINK += -m32 -lm -ldl - -CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror -CPPFLAGS += -fno-exceptions -fno-rtti - -BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT) - -ifeq "$(DEBUG)" "true" - BIN_DIR = Debug - CFLAGS += $(C_DEBUG_FLAGS) -else - BIN_DIR = Release - CFLAGS += $(C_OPT_FLAGS) - LINK += -s -endif - -IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0") - -ifeq "$(IS_CLANG)" "1" - CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/") - CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/") -else - CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1) - CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3) -endif - -# Clang || GCC >= 4 -ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1" - CFLAGS += $(C_GCC4_FLAGS) - CPPFLAGS += $(CPP_GCC4_FLAGS) -endif - -# Clang >= 3 || GCC >= 4.7 -ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1" - CPPFLAGS += -Wno-delete-non-virtual-dtor -endif - -# OS is Linux and not using clang -ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1" - LINK += -static-libgcc -endif - -OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) - -# This will break if we include other Makefiles, but is fine for now. It allows -# us to make a copy of this file that uses altered paths (ie. Makefile.mine) -# or other changes without mucking up the original. -MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) - -$(BIN_DIR)/%.o: %.cpp - $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< - -all: - mkdir -p $(BIN_DIR) - ln -sf $(PUBLIC_ROOT)/sdk/amxxmodule.cpp - $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT) - -$(PROJECT): $(OBJ_BIN) - $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY) - -debug: - $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true - -default: all - -clean: - rm -rf $(BIN_DIR)/*.o - rm -f $(BIN_DIR)/$(BINARY) - +# (C)2004-2013 AMX Mod X Development Team +# Makefile written by David "BAILOPAN" Anderson + +########################################### +### EDIT THESE PATHS FOR YOUR OWN SETUP ### +########################################### + +HLSDK = ../../../hlsdk +MM_ROOT = ../../../metamod/metamod +PUBLIC_ROOT = ../../public + +##################################### +### EDIT BELOW FOR OTHER PROJECTS ### +##################################### + +PROJECT = hamsandwich + +OBJECTS = amxxmodule.cpp amxx_api.cpp config_parser.cpp hook_callbacks.cpp hook_native.cpp \ + srvcmd.cpp call_funcs.cpp hook_create.cpp DataHandler.cpp pdata.cpp hook_specialbot.cpp + +############################################## +### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### +############################################## + +C_OPT_FLAGS = -DNDEBUG -O3 -funroll-loops -fomit-frame-pointer -pipe +C_DEBUG_FLAGS = -D_DEBUG -DDEBUG -g -ggdb3 +C_GCC4_FLAGS = -fvisibility=hidden +CPP_GCC4_FLAGS = -fvisibility-inlines-hidden +CPP = gcc +CPP_OSX = clang + +LINK = + +INCLUDE = -I. -I$(PUBLIC_ROOT) -I$(PUBLIC_ROOT)/sdk -I$(PUBLIC_ROOT)/amtl \ + -I$(HLSDK) -I$(HLSDK)/public -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared\ + -I$(MM_ROOT) + +################################################ +### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ### +################################################ + +OS := $(shell uname -s) + +ifeq "$(OS)" "Darwin" + CPP = $(CPP_OSX) + LIB_EXT = dylib + LIB_SUFFIX = _amxx + CFLAGS += -DOSX + LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5 +else + LIB_EXT = so + LIB_SUFFIX = _amxx_i386 + CFLAGS += -DLINUX + LINK += -shared +endif + +LINK += -m32 -lm -ldl + +CFLAGS += -DPAWN_CELL_SIZE=32 -DJIT -DASM32 -DHAVE_STDINT_H -fno-strict-aliasing -m32 -Wall -Werror +CPPFLAGS += -fno-exceptions -fno-rtti + +BINARY = $(PROJECT)$(LIB_SUFFIX).$(LIB_EXT) + +ifeq "$(DEBUG)" "true" + BIN_DIR = Debug + CFLAGS += $(C_DEBUG_FLAGS) +else + BIN_DIR = Release + CFLAGS += $(C_OPT_FLAGS) + LINK += -s +endif + +IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0") + +ifeq "$(IS_CLANG)" "1" + CPP_MAJOR := $(shell $(CPP) --version | grep clang | sed "s/.*version \([0-9]\)*\.[0-9]*.*/\1/") + CPP_MINOR := $(shell $(CPP) --version | grep clang | sed "s/.*version [0-9]*\.\([0-9]\)*.*/\1/") +else + CPP_MAJOR := $(shell $(CPP) -dumpversion >&1 | cut -b1) + CPP_MINOR := $(shell $(CPP) -dumpversion >&1 | cut -b3) +endif + +# Clang || GCC >= 4 +ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1" + CFLAGS += $(C_GCC4_FLAGS) + CPPFLAGS += $(CPP_GCC4_FLAGS) +endif + +# Clang >= 3 || GCC >= 4.7 +ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1" + CPPFLAGS += -Wno-delete-non-virtual-dtor +endif + +# OS is Linux and not using clang +ifeq "$(shell expr $(OS) \= Linux \& $(IS_CLANG) \= 0)" "1" + LINK += -static-libgcc +endif + +OBJ_BIN := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) + +# This will break if we include other Makefiles, but is fine for now. It allows +# us to make a copy of this file that uses altered paths (ie. Makefile.mine) +# or other changes without mucking up the original. +MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) + +$(BIN_DIR)/%.o: %.cpp + $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< + +all: + mkdir -p $(BIN_DIR) + ln -sf $(PUBLIC_ROOT)/sdk/amxxmodule.cpp + $(MAKE) -f $(MAKEFILE_NAME) $(PROJECT) + +$(PROJECT): $(OBJ_BIN) + $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -o $(BIN_DIR)/$(BINARY) + +debug: + $(MAKE) -f $(MAKEFILE_NAME) all DEBUG=true + +default: all + +clean: + rm -rf $(BIN_DIR)/*.o + rm -f $(BIN_DIR)/$(BINARY) + diff --git a/dlls/hamsandwich/NEW_Util.h b/modules/hamsandwich/NEW_Util.h similarity index 100% rename from dlls/hamsandwich/NEW_Util.h rename to modules/hamsandwich/NEW_Util.h diff --git a/dlls/hamsandwich/Trampolines.h b/modules/hamsandwich/Trampolines.h similarity index 100% rename from dlls/hamsandwich/Trampolines.h rename to modules/hamsandwich/Trampolines.h diff --git a/dlls/hamsandwich/amxx_api.cpp b/modules/hamsandwich/amxx_api.cpp similarity index 100% rename from dlls/hamsandwich/amxx_api.cpp rename to modules/hamsandwich/amxx_api.cpp diff --git a/dlls/hamsandwich/call_funcs.cpp b/modules/hamsandwich/call_funcs.cpp similarity index 100% rename from dlls/hamsandwich/call_funcs.cpp rename to modules/hamsandwich/call_funcs.cpp diff --git a/dlls/hamsandwich/call_funcs.h b/modules/hamsandwich/call_funcs.h similarity index 100% rename from dlls/hamsandwich/call_funcs.h rename to modules/hamsandwich/call_funcs.h diff --git a/dlls/hamsandwich/celltotype.h b/modules/hamsandwich/celltotype.h similarity index 100% rename from dlls/hamsandwich/celltotype.h rename to modules/hamsandwich/celltotype.h diff --git a/dlls/hamsandwich/config_parser.cpp b/modules/hamsandwich/config_parser.cpp similarity index 100% rename from dlls/hamsandwich/config_parser.cpp rename to modules/hamsandwich/config_parser.cpp diff --git a/dlls/hamsandwich/forward.h b/modules/hamsandwich/forward.h similarity index 100% rename from dlls/hamsandwich/forward.h rename to modules/hamsandwich/forward.h diff --git a/dlls/hamsandwich/ham_const.h b/modules/hamsandwich/ham_const.h similarity index 100% rename from dlls/hamsandwich/ham_const.h rename to modules/hamsandwich/ham_const.h diff --git a/dlls/hamsandwich/ham_utils.h b/modules/hamsandwich/ham_utils.h similarity index 100% rename from dlls/hamsandwich/ham_utils.h rename to modules/hamsandwich/ham_utils.h diff --git a/dlls/hamsandwich/hook.h b/modules/hamsandwich/hook.h similarity index 100% rename from dlls/hamsandwich/hook.h rename to modules/hamsandwich/hook.h diff --git a/dlls/hamsandwich/hook_callbacks.cpp b/modules/hamsandwich/hook_callbacks.cpp similarity index 100% rename from dlls/hamsandwich/hook_callbacks.cpp rename to modules/hamsandwich/hook_callbacks.cpp diff --git a/dlls/hamsandwich/hook_callbacks.h b/modules/hamsandwich/hook_callbacks.h similarity index 100% rename from dlls/hamsandwich/hook_callbacks.h rename to modules/hamsandwich/hook_callbacks.h diff --git a/dlls/hamsandwich/hook_create.cpp b/modules/hamsandwich/hook_create.cpp similarity index 100% rename from dlls/hamsandwich/hook_create.cpp rename to modules/hamsandwich/hook_create.cpp diff --git a/dlls/hamsandwich/hook_create.h b/modules/hamsandwich/hook_create.h similarity index 100% rename from dlls/hamsandwich/hook_create.h rename to modules/hamsandwich/hook_create.h diff --git a/dlls/hamsandwich/hook_native.cpp b/modules/hamsandwich/hook_native.cpp similarity index 100% rename from dlls/hamsandwich/hook_native.cpp rename to modules/hamsandwich/hook_native.cpp diff --git a/dlls/hamsandwich/hook_specialbot.cpp b/modules/hamsandwich/hook_specialbot.cpp similarity index 100% rename from dlls/hamsandwich/hook_specialbot.cpp rename to modules/hamsandwich/hook_specialbot.cpp diff --git a/dlls/hamsandwich/hook_specialbot.h b/modules/hamsandwich/hook_specialbot.h similarity index 100% rename from dlls/hamsandwich/hook_specialbot.h rename to modules/hamsandwich/hook_specialbot.h diff --git a/dlls/hamsandwich/hooklist.h b/modules/hamsandwich/hooklist.h similarity index 100% rename from dlls/hamsandwich/hooklist.h rename to modules/hamsandwich/hooklist.h diff --git a/dlls/hamsandwich/moduleconfig.h b/modules/hamsandwich/moduleconfig.h similarity index 100% rename from dlls/hamsandwich/moduleconfig.h rename to modules/hamsandwich/moduleconfig.h diff --git a/dlls/hamsandwich/msvc12/hamsandwich.sln b/modules/hamsandwich/msvc12/hamsandwich.sln similarity index 100% rename from dlls/hamsandwich/msvc12/hamsandwich.sln rename to modules/hamsandwich/msvc12/hamsandwich.sln diff --git a/dlls/hamsandwich/msvc12/hamsandwich.vcxproj b/modules/hamsandwich/msvc12/hamsandwich.vcxproj similarity index 100% rename from dlls/hamsandwich/msvc12/hamsandwich.vcxproj rename to modules/hamsandwich/msvc12/hamsandwich.vcxproj diff --git a/dlls/hamsandwich/msvc12/hamsandwich.vcxproj.filters b/modules/hamsandwich/msvc12/hamsandwich.vcxproj.filters similarity index 100% rename from dlls/hamsandwich/msvc12/hamsandwich.vcxproj.filters rename to modules/hamsandwich/msvc12/hamsandwich.vcxproj.filters diff --git a/dlls/hamsandwich/offsets.h b/modules/hamsandwich/offsets.h similarity index 100% rename from dlls/hamsandwich/offsets.h rename to modules/hamsandwich/offsets.h diff --git a/dlls/hamsandwich/pdata.cpp b/modules/hamsandwich/pdata.cpp similarity index 100% rename from dlls/hamsandwich/pdata.cpp rename to modules/hamsandwich/pdata.cpp diff --git a/dlls/hamsandwich/srvcmd.cpp b/modules/hamsandwich/srvcmd.cpp similarity index 100% rename from dlls/hamsandwich/srvcmd.cpp rename to modules/hamsandwich/srvcmd.cpp diff --git a/dlls/hamsandwich/typetocell.h b/modules/hamsandwich/typetocell.h similarity index 100% rename from dlls/hamsandwich/typetocell.h rename to modules/hamsandwich/typetocell.h diff --git a/dlls/hamsandwich/version.rc b/modules/hamsandwich/version.rc similarity index 100% rename from dlls/hamsandwich/version.rc rename to modules/hamsandwich/version.rc diff --git a/dlls/mysqlx/AMBuilder b/modules/mysqlx/AMBuilder similarity index 100% rename from dlls/mysqlx/AMBuilder rename to modules/mysqlx/AMBuilder diff --git a/dlls/mysqlx/Makefile b/modules/mysqlx/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/mysqlx/Makefile rename to modules/mysqlx/Makefile diff --git a/dlls/mysqlx/basic_sql.cpp b/modules/mysqlx/basic_sql.cpp similarity index 100% rename from dlls/mysqlx/basic_sql.cpp rename to modules/mysqlx/basic_sql.cpp diff --git a/dlls/mysqlx/handles.cpp b/modules/mysqlx/handles.cpp similarity index 100% rename from dlls/mysqlx/handles.cpp rename to modules/mysqlx/handles.cpp diff --git a/dlls/mysqlx/module.cpp b/modules/mysqlx/module.cpp similarity index 100% rename from dlls/mysqlx/module.cpp rename to modules/mysqlx/module.cpp diff --git a/dlls/mysqlx/moduleconfig.h b/modules/mysqlx/moduleconfig.h similarity index 100% rename from dlls/mysqlx/moduleconfig.h rename to modules/mysqlx/moduleconfig.h diff --git a/dlls/mysqlx/msvc12/mysqlx.sln b/modules/mysqlx/msvc12/mysqlx.sln similarity index 100% rename from dlls/mysqlx/msvc12/mysqlx.sln rename to modules/mysqlx/msvc12/mysqlx.sln diff --git a/dlls/mysqlx/msvc12/mysqlx.vcxproj b/modules/mysqlx/msvc12/mysqlx.vcxproj similarity index 100% rename from dlls/mysqlx/msvc12/mysqlx.vcxproj rename to modules/mysqlx/msvc12/mysqlx.vcxproj diff --git a/dlls/mysqlx/msvc12/mysqlx.vcxproj.filters b/modules/mysqlx/msvc12/mysqlx.vcxproj.filters similarity index 100% rename from dlls/mysqlx/msvc12/mysqlx.vcxproj.filters rename to modules/mysqlx/msvc12/mysqlx.vcxproj.filters diff --git a/dlls/mysqlx/mysql/ISQLDriver.h b/modules/mysqlx/mysql/ISQLDriver.h similarity index 100% rename from dlls/mysqlx/mysql/ISQLDriver.h rename to modules/mysqlx/mysql/ISQLDriver.h diff --git a/dlls/mysqlx/mysql/MysqlDatabase.cpp b/modules/mysqlx/mysql/MysqlDatabase.cpp similarity index 100% rename from dlls/mysqlx/mysql/MysqlDatabase.cpp rename to modules/mysqlx/mysql/MysqlDatabase.cpp diff --git a/dlls/mysqlx/mysql/MysqlDatabase.h b/modules/mysqlx/mysql/MysqlDatabase.h similarity index 100% rename from dlls/mysqlx/mysql/MysqlDatabase.h rename to modules/mysqlx/mysql/MysqlDatabase.h diff --git a/dlls/mysqlx/mysql/MysqlDriver.cpp b/modules/mysqlx/mysql/MysqlDriver.cpp similarity index 100% rename from dlls/mysqlx/mysql/MysqlDriver.cpp rename to modules/mysqlx/mysql/MysqlDriver.cpp diff --git a/dlls/mysqlx/mysql/MysqlDriver.h b/modules/mysqlx/mysql/MysqlDriver.h similarity index 100% rename from dlls/mysqlx/mysql/MysqlDriver.h rename to modules/mysqlx/mysql/MysqlDriver.h diff --git a/dlls/mysqlx/mysql/MysqlHeaders.h b/modules/mysqlx/mysql/MysqlHeaders.h similarity index 100% rename from dlls/mysqlx/mysql/MysqlHeaders.h rename to modules/mysqlx/mysql/MysqlHeaders.h diff --git a/dlls/mysqlx/mysql/MysqlQuery.cpp b/modules/mysqlx/mysql/MysqlQuery.cpp similarity index 100% rename from dlls/mysqlx/mysql/MysqlQuery.cpp rename to modules/mysqlx/mysql/MysqlQuery.cpp diff --git a/dlls/mysqlx/mysql/MysqlQuery.h b/modules/mysqlx/mysql/MysqlQuery.h similarity index 100% rename from dlls/mysqlx/mysql/MysqlQuery.h rename to modules/mysqlx/mysql/MysqlQuery.h diff --git a/dlls/mysqlx/mysql/MysqlResultSet.cpp b/modules/mysqlx/mysql/MysqlResultSet.cpp similarity index 100% rename from dlls/mysqlx/mysql/MysqlResultSet.cpp rename to modules/mysqlx/mysql/MysqlResultSet.cpp diff --git a/dlls/mysqlx/mysql/MysqlResultSet.h b/modules/mysqlx/mysql/MysqlResultSet.h similarity index 100% rename from dlls/mysqlx/mysql/MysqlResultSet.h rename to modules/mysqlx/mysql/MysqlResultSet.h diff --git a/dlls/mysqlx/mysql2_header.h b/modules/mysqlx/mysql2_header.h similarity index 100% rename from dlls/mysqlx/mysql2_header.h rename to modules/mysqlx/mysql2_header.h diff --git a/dlls/mysqlx/oldcompat_sql.cpp b/modules/mysqlx/oldcompat_sql.cpp similarity index 100% rename from dlls/mysqlx/oldcompat_sql.cpp rename to modules/mysqlx/oldcompat_sql.cpp diff --git a/dlls/mysqlx/sqlheaders.h b/modules/mysqlx/sqlheaders.h similarity index 100% rename from dlls/mysqlx/sqlheaders.h rename to modules/mysqlx/sqlheaders.h diff --git a/dlls/mysqlx/thread/BaseWorker.cpp b/modules/mysqlx/thread/BaseWorker.cpp similarity index 100% rename from dlls/mysqlx/thread/BaseWorker.cpp rename to modules/mysqlx/thread/BaseWorker.cpp diff --git a/dlls/mysqlx/thread/BaseWorker.h b/modules/mysqlx/thread/BaseWorker.h similarity index 100% rename from dlls/mysqlx/thread/BaseWorker.h rename to modules/mysqlx/thread/BaseWorker.h diff --git a/dlls/mysqlx/thread/IThreader.h b/modules/mysqlx/thread/IThreader.h similarity index 100% rename from dlls/mysqlx/thread/IThreader.h rename to modules/mysqlx/thread/IThreader.h diff --git a/dlls/mysqlx/thread/PosixThreads.cpp b/modules/mysqlx/thread/PosixThreads.cpp similarity index 100% rename from dlls/mysqlx/thread/PosixThreads.cpp rename to modules/mysqlx/thread/PosixThreads.cpp diff --git a/dlls/mysqlx/thread/PosixThreads.h b/modules/mysqlx/thread/PosixThreads.h similarity index 100% rename from dlls/mysqlx/thread/PosixThreads.h rename to modules/mysqlx/thread/PosixThreads.h diff --git a/dlls/mysqlx/thread/ThreadSupport.h b/modules/mysqlx/thread/ThreadSupport.h similarity index 100% rename from dlls/mysqlx/thread/ThreadSupport.h rename to modules/mysqlx/thread/ThreadSupport.h diff --git a/dlls/mysqlx/thread/ThreadWorker.cpp b/modules/mysqlx/thread/ThreadWorker.cpp similarity index 100% rename from dlls/mysqlx/thread/ThreadWorker.cpp rename to modules/mysqlx/thread/ThreadWorker.cpp diff --git a/dlls/mysqlx/thread/ThreadWorker.h b/modules/mysqlx/thread/ThreadWorker.h similarity index 100% rename from dlls/mysqlx/thread/ThreadWorker.h rename to modules/mysqlx/thread/ThreadWorker.h diff --git a/dlls/mysqlx/thread/WinThreads.cpp b/modules/mysqlx/thread/WinThreads.cpp similarity index 100% rename from dlls/mysqlx/thread/WinThreads.cpp rename to modules/mysqlx/thread/WinThreads.cpp diff --git a/dlls/mysqlx/thread/WinThreads.h b/modules/mysqlx/thread/WinThreads.h similarity index 100% rename from dlls/mysqlx/thread/WinThreads.h rename to modules/mysqlx/thread/WinThreads.h diff --git a/dlls/mysqlx/threading.cpp b/modules/mysqlx/threading.cpp similarity index 100% rename from dlls/mysqlx/threading.cpp rename to modules/mysqlx/threading.cpp diff --git a/dlls/mysqlx/threading.h b/modules/mysqlx/threading.h similarity index 100% rename from dlls/mysqlx/threading.h rename to modules/mysqlx/threading.h diff --git a/dlls/mysqlx/version.rc b/modules/mysqlx/version.rc similarity index 100% rename from dlls/mysqlx/version.rc rename to modules/mysqlx/version.rc diff --git a/dlls/ns/AMBuilder b/modules/ns/AMBuilder similarity index 100% rename from dlls/ns/AMBuilder rename to modules/ns/AMBuilder diff --git a/dlls/ns/AllocString.h b/modules/ns/AllocString.h similarity index 100% rename from dlls/ns/AllocString.h rename to modules/ns/AllocString.h diff --git a/dlls/ns/CPlayer.h b/modules/ns/CPlayer.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ns/CPlayer.h rename to modules/ns/CPlayer.h diff --git a/dlls/ns/FastDelegate.h b/modules/ns/FastDelegate.h similarity index 97% rename from dlls/ns/FastDelegate.h rename to modules/ns/FastDelegate.h index b40cef11..f9001761 100644 --- a/dlls/ns/FastDelegate.h +++ b/modules/ns/FastDelegate.h @@ -1,2108 +1,2108 @@ -// FastDelegate.h -// Efficient delegates in C++ that generate only two lines of asm code! -// Documentation is found at http://www.codeproject.com/cpp/FastDelegate.asp -// -// - Don Clugston, Mar 2004. -// Major contributions were made by Jody Hagins. -// History: -// 24-Apr-04 1.0 * Submitted to CodeProject. -// 28-Apr-04 1.1 * Prevent most unsafe uses of evil static function hack. -// * Improved syntax for horrible_cast (thanks Paul Bludov). -// * Tested on Metrowerks MWCC and Intel ICL (IA32) -// * Compiled, but not run, on Comeau C++ and Intel Itanium ICL. -// 27-Jun-04 1.2 * Now works on Borland C++ Builder 5.5 -// * Now works on /clr "managed C++" code on VC7, VC7.1 -// * Comeau C++ now compiles without warnings. -// * Prevent the virtual inheritance case from being used on -// VC6 and earlier, which generate incorrect code. -// * Improved warning and error messages. Non-standard hacks -// now have compile-time checks to make them safer. -// * implicit_cast used instead of static_cast in many cases. -// * If calling a const member function, a const class pointer can be used. -// * MakeDelegate() global helper function added to simplify pass-by-value. -// * Added fastdelegate.clear() -// 16-Jul-04 1.2.1* Workaround for gcc bug (const member function pointers in templates) -// 30-Oct-04 1.3 * Support for (non-void) return values. -// * No more workarounds in client code! -// MSVC and Intel now use a clever hack invented by John Dlugosz: -// - The FASTDELEGATEDECLARE workaround is no longer necessary. -// - No more warning messages for VC6 -// * Less use of macros. Error messages should be more comprehensible. -// * Added include guards -// * Added FastDelegate::empty() to test if invocation is safe (Thanks Neville Franks). -// * Now tested on VS 2005 Express Beta, PGI C++ -// 24-Dec-04 1.4 * Added DelegateMemento, to allow collections of disparate delegates. -// * <,>,<=,>= comparison operators to allow storage in ordered containers. -// * Substantial reduction of code size, especially the 'Closure' class. -// * Standardised all the compiler-specific workarounds. -// * MFP conversion now works for CodePlay (but not yet supported in the full code). -// * Now compiles without warnings on _any_ supported compiler, including BCC 5.5.1 -// * New syntax: FastDelegate< int (char *, double) >. -// 14-Feb-05 1.4.1* Now treats =0 as equivalent to .clear(), ==0 as equivalent to .empty(). (Thanks elfric). -// * Now tested on Intel ICL for AMD64, VS2005 Beta for AMD64 and Itanium. -// 30-Mar-05 1.5 * Safebool idiom: "if (dg)" is now equivalent to "if (!dg.empty())" -// * Fully supported by CodePlay VectorC -// * Bugfix for Metrowerks: empty() was buggy because a valid MFP can be 0 on MWCC! -// * More optimal assignment,== and != operators for static function pointers. - -#ifndef FASTDELEGATE_H -#define FASTDELEGATE_H -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#include // to allow <,> comparisons - -//////////////////////////////////////////////////////////////////////////////// -// Configuration options -// -//////////////////////////////////////////////////////////////////////////////// - -// Uncomment the following #define for optimally-sized delegates. -// In this case, the generated asm code is almost identical to the code you'd get -// if the compiler had native support for delegates. -// It will not work on systems where sizeof(dataptr) < sizeof(codeptr). -// Thus, it will not work for DOS compilers using the medium model. -// It will also probably fail on some DSP systems. -#define FASTDELEGATE_USESTATICFUNCTIONHACK - -// Uncomment the next line to allow function declarator syntax. -// It is automatically enabled for those compilers where it is known to work. -//#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX - -//////////////////////////////////////////////////////////////////////////////// -// Compiler identification for workarounds -// -//////////////////////////////////////////////////////////////////////////////// - -// Compiler identification. It's not easy to identify Visual C++ because -// many vendors fraudulently define Microsoft's identifiers. -#if defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__VECTOR_C) && !defined(__ICL) && !defined(__BORLANDC__) -#define FASTDLGT_ISMSVC - -#if (_MSC_VER <1300) // Many workarounds are required for VC6. -#define FASTDLGT_VC6 -#pragma warning(disable:4786) // disable this ridiculous warning -#endif - -#endif - -// Does the compiler uses Microsoft's member function pointer structure? -// If so, it needs special treatment. -// Metrowerks CodeWarrior, Intel, and CodePlay fraudulently define Microsoft's -// identifier, _MSC_VER. We need to filter Metrowerks out. -#if defined(_MSC_VER) && !defined(__MWERKS__) -#define FASTDLGT_MICROSOFT_MFP - -#if !defined(__VECTOR_C) -// CodePlay doesn't have the __single/multi/virtual_inheritance keywords -#define FASTDLGT_HASINHERITANCE_KEYWORDS -#endif -#endif - -// Does it allow function declarator syntax? The following compilers are known to work: -#if defined(FASTDLGT_ISMSVC) && (_MSC_VER >=1310) // VC 7.1 -#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX -#endif - -// Gcc(2.95+), and versions of Digital Mars, Intel and Comeau in common use. -#if defined (__DMC__) || defined(__GNUC__) || defined(__ICL) || defined(__COMO__) -#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX -#endif - -// It works on Metrowerks MWCC 3.2.2. From boost.Config it should work on earlier ones too. -#if defined (__MWERKS__) -#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX -#endif - -#ifdef __GNUC__ // Workaround GCC bug #8271 - // At present, GCC doesn't recognize constness of MFPs in templates -#define FASTDELEGATE_GCC_BUG_8271 -#endif - - - -//////////////////////////////////////////////////////////////////////////////// -// General tricks used in this code -// -// (a) Error messages are generated by typdefing an array of negative size to -// generate compile-time errors. -// (b) Warning messages on MSVC are generated by declaring unused variables, and -// enabling the "variable XXX is never used" warning. -// (c) Unions are used in a few compiler-specific cases to perform illegal casts. -// (d) For Microsoft and Intel, when adjusting the 'this' pointer, it's cast to -// (char *) first to ensure that the correct number of *bytes* are added. -// -//////////////////////////////////////////////////////////////////////////////// -// Helper templates -// -//////////////////////////////////////////////////////////////////////////////// - - -namespace fastdelegate { -namespace detail { // we'll hide the implementation details in a nested namespace. - -// implicit_cast< > -// I believe this was originally going to be in the C++ standard but -// was left out by accident. It's even milder than static_cast. -// I use it instead of static_cast<> to emphasize that I'm not doing -// anything nasty. -// Usage is identical to static_cast<> -template -inline OutputClass implicit_cast(InputClass input){ - return input; -} - -// horrible_cast< > -// This is truly evil. It completely subverts C++'s type system, allowing you -// to cast from any class to any other class. Technically, using a union -// to perform the cast is undefined behaviour (even in C). But we can see if -// it is OK by checking that the union is the same size as each of its members. -// horrible_cast<> should only be used for compiler-specific workarounds. -// Usage is identical to reinterpret_cast<>. - -// This union is declared outside the horrible_cast because BCC 5.5.1 -// can't inline a function with a nested class, and gives a warning. -template -union horrible_union{ - OutputClass out; - InputClass in; -}; - -template -inline OutputClass horrible_cast(const InputClass input){ - horrible_union u; - // Cause a compile-time error if in, out and u are not the same size. - // If the compile fails here, it means the compiler has peculiar - // unions which would prevent the cast from working. - typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u) - && sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1]; - u.in = input; - return u.out; -} - -//////////////////////////////////////////////////////////////////////////////// -// Workarounds -// -//////////////////////////////////////////////////////////////////////////////// - -// Backwards compatibility: This macro used to be necessary in the virtual inheritance -// case for Intel and Microsoft. Now it just forward-declares the class. -#define FASTDELEGATEDECLARE(CLASSNAME) class CLASSNAME; - -// Prevent use of the static function hack with the DOS medium model. -#ifdef __MEDIUM__ -#undef FASTDELEGATE_USESTATICFUNCTIONHACK -#endif - -// DefaultVoid - a workaround for 'void' templates in VC6. -// -// (1) VC6 and earlier do not allow 'void' as a default template argument. -// (2) They also doesn't allow you to return 'void' from a function. -// -// Workaround for (1): Declare a dummy type 'DefaultVoid' which we use -// when we'd like to use 'void'. We convert it into 'void' and back -// using the templates DefaultVoidToVoid<> and VoidToDefaultVoid<>. -// Workaround for (2): On VC6, the code for calling a void function is -// identical to the code for calling a non-void function in which the -// return value is never used, provided the return value is returned -// in the EAX register, rather than on the stack. -// This is true for most fundamental types such as int, enum, void *. -// Const void * is the safest option since it doesn't participate -// in any automatic conversions. But on a 16-bit compiler it might -// cause extra code to be generated, so we disable it for all compilers -// except for VC6 (and VC5). -#ifdef FASTDLGT_VC6 -// VC6 workaround -typedef const void * DefaultVoid; -#else -// On any other compiler, just use a normal void. -typedef void DefaultVoid; -#endif - -// Translate from 'DefaultVoid' to 'void'. -// Everything else is unchanged -template -struct DefaultVoidToVoid { typedef T type; }; - -template <> -struct DefaultVoidToVoid { typedef void type; }; - -// Translate from 'void' into 'DefaultVoid' -// Everything else is unchanged -template -struct VoidToDefaultVoid { typedef T type; }; - -template <> -struct VoidToDefaultVoid { typedef DefaultVoid type; }; - - - -//////////////////////////////////////////////////////////////////////////////// -// Fast Delegates, part 1: -// -// Conversion of member function pointer to a standard form -// -//////////////////////////////////////////////////////////////////////////////// - -// GenericClass is a fake class, ONLY used to provide a type. -// It is vitally important that it is never defined, so that the compiler doesn't -// think it can optimize the invocation. For example, Borland generates simpler -// code if it knows the class only uses single inheritance. - -// Compilers using Microsoft's structure need to be treated as a special case. -#ifdef FASTDLGT_MICROSOFT_MFP - -#ifdef FASTDLGT_HASINHERITANCE_KEYWORDS - // For Microsoft and Intel, we want to ensure that it's the most efficient type of MFP - // (4 bytes), even when the /vmg option is used. Declaring an empty class - // would give 16 byte pointers in this case.... - class __single_inheritance GenericClass; -#endif - // ...but for Codeplay, an empty class *always* gives 4 byte pointers. - // If compiled with the /clr option ("managed C++"), the JIT compiler thinks - // it needs to load GenericClass before it can call any of its functions, - // (compiles OK but crashes at runtime!), so we need to declare an - // empty class to make it happy. - // Codeplay and VC4 can't cope with the unknown_inheritance case either. - class GenericClass {}; -#else - class GenericClass; -#endif - -// The size of a single inheritance member function pointer. -const int SINGLE_MEMFUNCPTR_SIZE = sizeof(void (GenericClass::*)()); - -// SimplifyMemFunc< >::Convert() -// -// A template function that converts an arbitrary member function pointer into the -// simplest possible form of member function pointer, using a supplied 'this' pointer. -// According to the standard, this can be done legally with reinterpret_cast<>. -// For (non-standard) compilers which use member function pointers which vary in size -// depending on the class, we need to use knowledge of the internal structure of a -// member function pointer, as used by the compiler. Template specialization is used -// to distinguish between the sizes. Because some compilers don't support partial -// template specialisation, I use full specialisation of a wrapper struct. - -// general case -- don't know how to convert it. Force a compile failure -template -struct SimplifyMemFunc { - template - inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, - GenericMemFuncType &bound_func) { - // Unsupported member function type -- force a compile failure. - // (it's illegal to have a array with negative size). - typedef char ERROR_Unsupported_member_function_pointer_on_this_compiler[N-100]; - return 0; - } -}; - -// For compilers where all member func ptrs are the same size, everything goes here. -// For non-standard compilers, only single_inheritance classes go here. -template <> -struct SimplifyMemFunc { - template - inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, - GenericMemFuncType &bound_func) { -#if defined __DMC__ - // Digital Mars doesn't allow you to cast between abitrary PMF's, - // even though the standard says you can. The 32-bit compiler lets you - // static_cast through an int, but the DOS compiler doesn't. - bound_func = horrible_cast(function_to_bind); -#else - bound_func = reinterpret_cast(function_to_bind); -#endif - return reinterpret_cast(pthis); - } -}; - -//////////////////////////////////////////////////////////////////////////////// -// Fast Delegates, part 1b: -// -// Workarounds for Microsoft and Intel -// -//////////////////////////////////////////////////////////////////////////////// - - -// Compilers with member function pointers which violate the standard (MSVC, Intel, Codeplay), -// need to be treated as a special case. -#ifdef FASTDLGT_MICROSOFT_MFP - -// We use unions to perform horrible_casts. I would like to use #pragma pack(push, 1) -// at the start of each function for extra safety, but VC6 seems to ICE -// intermittently if you do this inside a template. - -// __multiple_inheritance classes go here -// Nasty hack for Microsoft and Intel (IA32 and Itanium) -template<> -struct SimplifyMemFunc< SINGLE_MEMFUNCPTR_SIZE + sizeof(int) > { - template - inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, - GenericMemFuncType &bound_func) { - // We need to use a horrible_cast to do this conversion. - // In MSVC, a multiple inheritance member pointer is internally defined as: - union { - XFuncType func; - struct { - GenericMemFuncType funcaddress; // points to the actual member function - int delta; // #BYTES to be added to the 'this' pointer - }s; - } u; - // Check that the horrible_cast will work - typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)? 1 : -1]; - u.func = function_to_bind; - bound_func = u.s.funcaddress; - return reinterpret_cast(reinterpret_cast(pthis) + u.s.delta); - } -}; - -// virtual inheritance is a real nuisance. It's inefficient and complicated. -// On MSVC and Intel, there isn't enough information in the pointer itself to -// enable conversion to a closure pointer. Earlier versions of this code didn't -// work for all cases, and generated a compile-time error instead. -// But a very clever hack invented by John M. Dlugosz solves this problem. -// My code is somewhat different to his: I have no asm code, and I make no -// assumptions about the calling convention that is used. - -// In VC++ and ICL, a virtual_inheritance member pointer -// is internally defined as: -struct MicrosoftVirtualMFP { - void (GenericClass::*codeptr)(); // points to the actual member function - int delta; // #bytes to be added to the 'this' pointer - int vtable_index; // or 0 if no virtual inheritance -}; -// The CRUCIAL feature of Microsoft/Intel MFPs which we exploit is that the -// m_codeptr member is *always* called, regardless of the values of the other -// members. (This is *not* true for other compilers, eg GCC, which obtain the -// function address from the vtable if a virtual function is being called). -// Dlugosz's trick is to make the codeptr point to a probe function which -// returns the 'this' pointer that was used. - -// Define a generic class that uses virtual inheritance. -// It has a trival member function that returns the value of the 'this' pointer. -struct GenericVirtualClass : virtual public GenericClass -{ - typedef GenericVirtualClass * (GenericVirtualClass::*ProbePtrType)(); - GenericVirtualClass * GetThis() { return this; } -}; - -// __virtual_inheritance classes go here -template <> -struct SimplifyMemFunc -{ - - template - inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, - GenericMemFuncType &bound_func) { - union { - XFuncType func; - GenericClass* (X::*ProbeFunc)(); - MicrosoftVirtualMFP s; - } u; - u.func = function_to_bind; - bound_func = reinterpret_cast(u.s.codeptr); - union { - GenericVirtualClass::ProbePtrType virtfunc; - MicrosoftVirtualMFP s; - } u2; - // Check that the horrible_cast<>s will work - typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s) - && sizeof(function_to_bind)==sizeof(u.ProbeFunc) - && sizeof(u2.virtfunc)==sizeof(u2.s) ? 1 : -1]; - // Unfortunately, taking the address of a MF prevents it from being inlined, so - // this next line can't be completely optimised away by the compiler. - u2.virtfunc = &GenericVirtualClass::GetThis; - u.s.codeptr = u2.s.codeptr; - return (pthis->*u.ProbeFunc)(); - } -}; - -#if (_MSC_VER <1300) - -// Nasty hack for Microsoft Visual C++ 6.0 -// unknown_inheritance classes go here -// There is a compiler bug in MSVC6 which generates incorrect code in this case!! -template <> -struct SimplifyMemFunc -{ - template - inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, - GenericMemFuncType &bound_func) { - // There is an apalling but obscure compiler bug in MSVC6 and earlier: - // vtable_index and 'vtordisp' are always set to 0 in the - // unknown_inheritance case! - // This means that an incorrect function could be called!!! - // Compiling with the /vmg option leads to potentially incorrect code. - // This is probably the reason that the IDE has a user interface for specifying - // the /vmg option, but it is disabled - you can only specify /vmg on - // the command line. In VC1.5 and earlier, the compiler would ICE if it ever - // encountered this situation. - // It is OK to use the /vmg option if /vmm or /vms is specified. - - // Fortunately, the wrong function is only called in very obscure cases. - // It only occurs when a derived class overrides a virtual function declared - // in a virtual base class, and the member function - // points to the *Derived* version of that function. The problem can be - // completely averted in 100% of cases by using the *Base class* for the - // member fpointer. Ie, if you use the base class as an interface, you'll - // stay out of trouble. - // Occasionally, you might want to point directly to a derived class function - // that isn't an override of a base class. In this case, both vtable_index - // and 'vtordisp' are zero, but a virtual_inheritance pointer will be generated. - // We can generate correct code in this case. To prevent an incorrect call from - // ever being made, on MSVC6 we generate a warning, and call a function to - // make the program crash instantly. - typedef char ERROR_VC6CompilerBug[-100]; - return 0; - } -}; - - -#else - -// Nasty hack for Microsoft and Intel (IA32 and Itanium) -// unknown_inheritance classes go here -// This is probably the ugliest bit of code I've ever written. Look at the casts! -// There is a compiler bug in MSVC6 which prevents it from using this code. -template <> -struct SimplifyMemFunc -{ - template - inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, - GenericMemFuncType &bound_func) { - // The member function pointer is 16 bytes long. We can't use a normal cast, but - // we can use a union to do the conversion. - union { - XFuncType func; - // In VC++ and ICL, an unknown_inheritance member pointer - // is internally defined as: - struct { - GenericMemFuncType m_funcaddress; // points to the actual member function - int delta; // #bytes to be added to the 'this' pointer - int vtordisp; // #bytes to add to 'this' to find the vtable - int vtable_index; // or 0 if no virtual inheritance - } s; - } u; - // Check that the horrible_cast will work - typedef int ERROR_CantUsehorrible_cast[sizeof(XFuncType)==sizeof(u.s)? 1 : -1]; - u.func = function_to_bind; - bound_func = u.s.funcaddress; - int virtual_delta = 0; - if (u.s.vtable_index) { // Virtual inheritance is used - // First, get to the vtable. - // It is 'vtordisp' bytes from the start of the class. - const int * vtable = *reinterpret_cast( - reinterpret_cast(pthis) + u.s.vtordisp ); - - // 'vtable_index' tells us where in the table we should be looking. - virtual_delta = u.s.vtordisp + *reinterpret_cast( - reinterpret_cast(vtable) + u.s.vtable_index); - } - // The int at 'virtual_delta' gives us the amount to add to 'this'. - // Finally we can add the three components together. Phew! - return reinterpret_cast( - reinterpret_cast(pthis) + u.s.delta + virtual_delta); - }; -}; -#endif // MSVC 7 and greater - -#endif // MS/Intel hacks - -} // namespace detail - -//////////////////////////////////////////////////////////////////////////////// -// Fast Delegates, part 2: -// -// Define the delegate storage, and cope with static functions -// -//////////////////////////////////////////////////////////////////////////////// - -// DelegateMemento -- an opaque structure which can hold an arbitary delegate. -// It knows nothing about the calling convention or number of arguments used by -// the function pointed to. -// It supplies comparison operators so that it can be stored in STL collections. -// It cannot be set to anything other than null, nor invoked directly: -// it must be converted to a specific delegate. - -// Implementation: -// There are two possible implementations: the Safe method and the Evil method. -// DelegateMemento - Safe version -// -// This implementation is standard-compliant, but a bit tricky. -// A static function pointer is stored inside the class. -// Here are the valid values: -// +-- Static pointer --+--pThis --+-- pMemFunc-+-- Meaning------+ -// | 0 | 0 | 0 | Empty | -// | !=0 |(dontcare)| Invoker | Static function| -// | 0 | !=0 | !=0* | Method call | -// +--------------------+----------+------------+----------------+ -// * For Metrowerks, this can be 0. (first virtual function in a -// single_inheritance class). -// When stored stored inside a specific delegate, the 'dontcare' entries are replaced -// with a reference to the delegate itself. This complicates the = and == operators -// for the delegate class. - -// DelegateMemento - Evil version -// -// For compilers where data pointers are at least as big as code pointers, it is -// possible to store the function pointer in the this pointer, using another -// horrible_cast. In this case the DelegateMemento implementation is simple: -// +--pThis --+-- pMemFunc-+-- Meaning---------------------+ -// | 0 | 0 | Empty | -// | !=0 | !=0* | Static function or method call| -// +----------+------------+-------------------------------+ -// * For Metrowerks, this can be 0. (first virtual function in a -// single_inheritance class). -// Note that the Sun C++ and MSVC documentation explicitly state that they -// support static_cast between void * and function pointers. - -class DelegateMemento { -protected: - // the data is protected, not private, because many - // compilers have problems with template friends. - typedef void (detail::GenericClass::*GenericMemFuncType)(); // arbitrary MFP. - detail::GenericClass *m_pthis; - GenericMemFuncType m_pFunction; - -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - typedef void (*GenericFuncPtr)(); // arbitrary code pointer - GenericFuncPtr m_pStaticFunction; -#endif - -public: -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - DelegateMemento() : m_pthis(0), m_pFunction(0), m_pStaticFunction(0) {}; - void clear() { - m_pthis=0; m_pFunction=0; m_pStaticFunction=0; - } -#else - DelegateMemento() : m_pthis(0), m_pFunction(0) {}; - void clear() { m_pthis=0; m_pFunction=0; } -#endif -public: -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - inline bool IsEqual (const DelegateMemento &x) const{ - // We have to cope with the static function pointers as a special case - if (m_pFunction!=x.m_pFunction) return false; - // the static function ptrs must either both be equal, or both be 0. - if (m_pStaticFunction!=x.m_pStaticFunction) return false; - if (m_pStaticFunction!=0) return m_pthis==x.m_pthis; - else return true; - } -#else // Evil Method - inline bool IsEqual (const DelegateMemento &x) const{ - return m_pthis==x.m_pthis && m_pFunction==x.m_pFunction; - } -#endif - // Provide a strict weak ordering for DelegateMementos. - inline bool IsLess(const DelegateMemento &right) const { - // deal with static function pointers first -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - if (m_pStaticFunction !=0 || right.m_pStaticFunction!=0) - return m_pStaticFunction < right.m_pStaticFunction; -#endif - if (m_pthis !=right.m_pthis) return m_pthis < right.m_pthis; - // There are no ordering operators for member function pointers, - // but we can fake one by comparing each byte. The resulting ordering is - // arbitrary (and compiler-dependent), but it permits storage in ordered STL containers. - return memcmp(&m_pFunction, &right.m_pFunction, sizeof(m_pFunction)) < 0; - - } - // BUGFIX (Mar 2005): - // We can't just compare m_pFunction because on Metrowerks, - // m_pFunction can be zero even if the delegate is not empty! - inline bool operator ! () const // Is it bound to anything? - { return m_pthis==0 && m_pFunction==0; } - inline bool empty() const // Is it bound to anything? - { return m_pthis==0 && m_pFunction==0; } -public: - DelegateMemento & operator = (const DelegateMemento &right) { - SetMementoFrom(right); - return *this; - } - inline bool operator <(const DelegateMemento &right) { - return IsLess(right); - } - inline bool operator >(const DelegateMemento &right) { - return right.IsLess(*this); - } - DelegateMemento (const DelegateMemento &right) : - m_pthis(right.m_pthis), m_pFunction(right.m_pFunction) -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - , m_pStaticFunction (right.m_pStaticFunction) -#endif - {} -protected: - void SetMementoFrom(const DelegateMemento &right) { - m_pFunction = right.m_pFunction; - m_pthis = right.m_pthis; -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - m_pStaticFunction = right.m_pStaticFunction; -#endif - } -}; - - -// ClosurePtr<> -// -// A private wrapper class that adds function signatures to DelegateMemento. -// It's the class that does most of the actual work. -// The signatures are specified by: -// GenericMemFunc: must be a type of GenericClass member function pointer. -// StaticFuncPtr: must be a type of function pointer with the same signature -// as GenericMemFunc. -// UnvoidStaticFuncPtr: is the same as StaticFuncPtr, except on VC6 -// where it never returns void (returns DefaultVoid instead). - -// An outer class, FastDelegateN<>, handles the invoking and creates the -// necessary typedefs. -// This class does everything else. - -namespace detail { - -template < class GenericMemFunc, class StaticFuncPtr, class UnvoidStaticFuncPtr> -class ClosurePtr : public DelegateMemento { -public: - // These functions are for setting the delegate to a member function. - - // Here's the clever bit: we convert an arbitrary member function into a - // standard form. XMemFunc should be a member function of class X, but I can't - // enforce that here. It needs to be enforced by the wrapper class. - template < class X, class XMemFunc > - inline void bindmemfunc(X *pthis, XMemFunc function_to_bind ) { - m_pthis = SimplifyMemFunc< sizeof(function_to_bind) > - ::Convert(pthis, function_to_bind, m_pFunction); -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - m_pStaticFunction = 0; -#endif - } - // For const member functions, we only need a const class pointer. - // Since we know that the member function is const, it's safe to - // remove the const qualifier from the 'this' pointer with a const_cast. - // VC6 has problems if we just overload 'bindmemfunc', so we give it a different name. - template < class X, class XMemFunc> - inline void bindconstmemfunc(const X *pthis, XMemFunc function_to_bind) { - m_pthis= SimplifyMemFunc< sizeof(function_to_bind) > - ::Convert(const_cast(pthis), function_to_bind, m_pFunction); -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - m_pStaticFunction = 0; -#endif - } -#ifdef FASTDELEGATE_GCC_BUG_8271 // At present, GCC doesn't recognize constness of MFPs in templates - template < class X, class XMemFunc> - inline void bindmemfunc(const X *pthis, XMemFunc function_to_bind) { - bindconstmemfunc(pthis, function_to_bind); -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - m_pStaticFunction = 0; -#endif - } -#endif - // These functions are required for invoking the stored function - inline GenericClass *GetClosureThis() const { return m_pthis; } - inline GenericMemFunc GetClosureMemPtr() const { return reinterpret_cast(m_pFunction); } - -// There are a few ways of dealing with static function pointers. -// There's a standard-compliant, but tricky method. -// There's also a straightforward hack, that won't work on DOS compilers using the -// medium memory model. It's so evil that I can't recommend it, but I've -// implemented it anyway because it produces very nice asm code. - -#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - -// ClosurePtr<> - Safe version -// -// This implementation is standard-compliant, but a bit tricky. -// I store the function pointer inside the class, and the delegate then -// points to itself. Whenever the delegate is copied, these self-references -// must be transformed, and this complicates the = and == operators. -public: - // The next two functions are for operator ==, =, and the copy constructor. - // We may need to convert the m_pthis pointers, so that - // they remain as self-references. - template< class DerivedClass > - inline void CopyFrom (DerivedClass *pParent, const DelegateMemento &x) { - SetMementoFrom(x); - if (m_pStaticFunction!=0) { - // transform self references... - m_pthis=reinterpret_cast(pParent); - } - } - // For static functions, the 'static_function_invoker' class in the parent - // will be called. The parent then needs to call GetStaticFunction() to find out - // the actual function to invoke. - template < class DerivedClass, class ParentInvokerSig > - inline void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, - StaticFuncPtr function_to_bind ) { - if (function_to_bind==0) { // cope with assignment to 0 - m_pFunction=0; - } else { - bindmemfunc(pParent, static_function_invoker); - } - m_pStaticFunction=reinterpret_cast(function_to_bind); - } - inline UnvoidStaticFuncPtr GetStaticFunction() const { - return reinterpret_cast(m_pStaticFunction); - } -#else - -// ClosurePtr<> - Evil version -// -// For compilers where data pointers are at least as big as code pointers, it is -// possible to store the function pointer in the this pointer, using another -// horrible_cast. Invocation isn't any faster, but it saves 4 bytes, and -// speeds up comparison and assignment. If C++ provided direct language support -// for delegates, they would produce asm code that was almost identical to this. -// Note that the Sun C++ and MSVC documentation explicitly state that they -// support static_cast between void * and function pointers. - - template< class DerivedClass > - inline void CopyFrom (DerivedClass *pParent, const DelegateMemento &right) { - SetMementoFrom(right); - } - // For static functions, the 'static_function_invoker' class in the parent - // will be called. The parent then needs to call GetStaticFunction() to find out - // the actual function to invoke. - // ******** EVIL, EVIL CODE! ******* - template < class DerivedClass, class ParentInvokerSig> - inline void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, - StaticFuncPtr function_to_bind) { - if (function_to_bind==0) { // cope with assignment to 0 - m_pFunction=0; - } else { - // We'll be ignoring the 'this' pointer, but we need to make sure we pass - // a valid value to bindmemfunc(). - bindmemfunc(pParent, static_function_invoker); - } - - // WARNING! Evil hack. We store the function in the 'this' pointer! - // Ensure that there's a compilation failure if function pointers - // and data pointers have different sizes. - // If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK. - typedef int ERROR_CantUseEvilMethod[sizeof(GenericClass *)==sizeof(function_to_bind) ? 1 : -1]; - m_pthis = horrible_cast(function_to_bind); - // MSVC, SunC++ and DMC accept the following (non-standard) code: -// m_pthis = static_cast(static_cast(function_to_bind)); - // BCC32, Comeau and DMC accept this method. MSVC7.1 needs __int64 instead of long -// m_pthis = reinterpret_cast(reinterpret_cast(function_to_bind)); - } - // ******** EVIL, EVIL CODE! ******* - // This function will be called with an invalid 'this' pointer!! - // We're just returning the 'this' pointer, converted into - // a function pointer! - inline UnvoidStaticFuncPtr GetStaticFunction() const { - // Ensure that there's a compilation failure if function pointers - // and data pointers have different sizes. - // If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK. - typedef int ERROR_CantUseEvilMethod[sizeof(UnvoidStaticFuncPtr)==sizeof(this) ? 1 : -1]; - return horrible_cast(this); - } -#endif // !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) - - // Does the closure contain this static function? - inline bool IsEqualToStaticFuncPtr(StaticFuncPtr funcptr){ - if (funcptr==0) return empty(); - // For the Evil method, if it doesn't actually contain a static function, this will return an arbitrary - // value that is not equal to any valid function pointer. - else return funcptr==reinterpret_cast(GetStaticFunction()); - } -}; - - -} // namespace detail - -//////////////////////////////////////////////////////////////////////////////// -// Fast Delegates, part 3: -// -// Wrapper classes to ensure type safety -// -//////////////////////////////////////////////////////////////////////////////// - - -// Once we have the member function conversion templates, it's easy to make the -// wrapper classes. So that they will work with as many compilers as possible, -// the classes are of the form -// FastDelegate3 -// They can cope with any combination of parameters. The max number of parameters -// allowed is 8, but it is trivial to increase this limit. -// Note that we need to treat const member functions seperately. -// All this class does is to enforce type safety, and invoke the delegate with -// the correct list of parameters. - -// Because of the weird rule about the class of derived member function pointers, -// you sometimes need to apply a downcast to the 'this' pointer. -// This is the reason for the use of "implicit_cast(pthis)" in the code below. -// If CDerivedClass is derived from CBaseClass, but doesn't override SimpleVirtualFunction, -// without this trick you'd need to write: -// MyDelegate(static_cast(&d), &CDerivedClass::SimpleVirtualFunction); -// but with the trick you can write -// MyDelegate(&d, &CDerivedClass::SimpleVirtualFunction); - -// RetType is the type the compiler uses in compiling the template. For VC6, -// it cannot be void. DesiredRetType is the real type which is returned from -// all of the functions. It can be void. - -// Implicit conversion to "bool" is achieved using the safe_bool idiom, -// using member data pointers (MDP). This allows "if (dg)..." syntax -// Because some compilers (eg codeplay) don't have a unique value for a zero -// MDP, an extra padding member is added to the SafeBool struct. -// Some compilers (eg VC6) won't implicitly convert from 0 to an MDP, so -// in that case the static function constructor is not made explicit; this -// allows "if (dg==0) ..." to compile. - -//N=0 -template -class FastDelegate0 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(); - typedef RetType (*UnvoidStaticFunctionPtr)(); - typedef RetType (detail::GenericClass::*GenericMemFn)(); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate0 type; - - // Construction and comparison functions - FastDelegate0() { clear(); } - FastDelegate0(const FastDelegate0 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate0 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate0 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate0 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate0 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate0 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate0(Y *pthis, DesiredRetType (X::* function_to_bind)() ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)()) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate0(const Y *pthis, DesiredRetType (X::* function_to_bind)() const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)() const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate0(DesiredRetType (*function_to_bind)() ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)() ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)()) { - m_Closure.bindstaticfunc(this, &FastDelegate0::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() () const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction() const { - return (*(m_Closure.GetStaticFunction()))(); } -}; - -//N=1 -template -class FastDelegate1 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate1 type; - - // Construction and comparison functions - FastDelegate1() { clear(); } - FastDelegate1(const FastDelegate1 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate1 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate1 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate1 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate1 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate1 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate1(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate1(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate1(DesiredRetType (*function_to_bind)(Param1 p1) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1)) { - m_Closure.bindstaticfunc(this, &FastDelegate1::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1) const { - return (*(m_Closure.GetStaticFunction()))(p1); } -}; - -//N=2 -template -class FastDelegate2 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate2 type; - - // Construction and comparison functions - FastDelegate2() { clear(); } - FastDelegate2(const FastDelegate2 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate2 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate2 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate2 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate2 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate2 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate2(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate2(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate2(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2)) { - m_Closure.bindstaticfunc(this, &FastDelegate2::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2); } -}; - -//N=3 -template -class FastDelegate3 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate3 type; - - // Construction and comparison functions - FastDelegate3() { clear(); } - FastDelegate3(const FastDelegate3 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate3 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate3 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate3 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate3 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate3 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate3(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate3(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate3(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3)) { - m_Closure.bindstaticfunc(this, &FastDelegate3::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2, Param3 p3) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2, p3); } -}; - -//N=4 -template -class FastDelegate4 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate4 type; - - // Construction and comparison functions - FastDelegate4() { clear(); } - FastDelegate4(const FastDelegate4 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate4 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate4 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate4 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate4 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate4 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate4(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate4(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate4(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { - m_Closure.bindstaticfunc(this, &FastDelegate4::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4); } -}; - -//N=5 -template -class FastDelegate5 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate5 type; - - // Construction and comparison functions - FastDelegate5() { clear(); } - FastDelegate5(const FastDelegate5 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate5 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate5 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate5 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate5 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate5 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate5(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate5(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate5(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { - m_Closure.bindstaticfunc(this, &FastDelegate5::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5); } -}; - -//N=6 -template -class FastDelegate6 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate6 type; - - // Construction and comparison functions - FastDelegate6() { clear(); } - FastDelegate6(const FastDelegate6 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate6 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate6 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate6 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate6 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate6 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate6(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate6(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate6(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { - m_Closure.bindstaticfunc(this, &FastDelegate6::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6); } -}; - -//N=7 -template -class FastDelegate7 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate7 type; - - // Construction and comparison functions - FastDelegate7() { clear(); } - FastDelegate7(const FastDelegate7 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate7 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate7 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate7 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate7 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate7 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate7(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate7(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate7(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { - m_Closure.bindstaticfunc(this, &FastDelegate7::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7); } -}; - -//N=8 -template -class FastDelegate8 { -private: - typedef typename detail::DefaultVoidToVoid::type DesiredRetType; - typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); - typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); - typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); - typedef detail::ClosurePtr ClosureType; - ClosureType m_Closure; -public: - // Typedefs to aid generic programming - typedef FastDelegate8 type; - - // Construction and comparison functions - FastDelegate8() { clear(); } - FastDelegate8(const FastDelegate8 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - void operator = (const FastDelegate8 &x) { - m_Closure.CopyFrom(this, x.m_Closure); } - bool operator ==(const FastDelegate8 &x) const { - return m_Closure.IsEqual(x.m_Closure); } - bool operator !=(const FastDelegate8 &x) const { - return !m_Closure.IsEqual(x.m_Closure); } - bool operator <(const FastDelegate8 &x) const { - return m_Closure.IsLess(x.m_Closure); } - bool operator >(const FastDelegate8 &x) const { - return x.m_Closure.IsLess(m_Closure); } - // Binding to non-const member functions - template < class X, class Y > - FastDelegate8(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { - m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Binding to const member functions. - template < class X, class Y > - FastDelegate8(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - template < class X, class Y > - inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { - m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } - // Static functions. We convert them into a member function call. - // This constructor also provides implicit conversion - FastDelegate8(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { - bind(function_to_bind); } - // for efficiency, prevent creation of a temporary - void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { - bind(function_to_bind); } - inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { - m_Closure.bindstaticfunc(this, &FastDelegate8::InvokeStaticFunction, - function_to_bind); } - // Invoke the delegate - RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const { - return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7, p8); } - // Implicit conversion to "bool" using the safe_bool idiom -private: - typedef struct SafeBoolStruct { - int a_data_pointer_to_this_is_0_on_buggy_compilers; - StaticFunctionPtr m_nonzero; - } UselessTypedef; - typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; -public: - operator unspecified_bool_type() const { - return empty()? 0: &SafeBoolStruct::m_nonzero; - } - // necessary to allow ==0 to work despite the safe_bool idiom - inline bool operator==(StaticFunctionPtr funcptr) { - return m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator!=(StaticFunctionPtr funcptr) { - return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } - inline bool operator ! () const { // Is it bound to anything? - return !m_Closure; } - inline bool empty() const { - return !m_Closure; } - void clear() { m_Closure.clear();} - // Conversion to and from the DelegateMemento storage class - const DelegateMemento & GetMemento() { return m_Closure; } - void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } - -private: // Invoker for static functions - RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const { - return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8); } -}; - - -//////////////////////////////////////////////////////////////////////////////// -// Fast Delegates, part 4: -// -// FastDelegate<> class (Original author: Jody Hagins) -// Allows boost::function style syntax like: -// FastDelegate< double (int, long) > -// instead of: -// FastDelegate2< int, long, double > -// -//////////////////////////////////////////////////////////////////////////////// - -#ifdef FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX - -// Declare FastDelegate as a class template. It will be specialized -// later for all number of arguments. -template -class FastDelegate; - -//N=0 -// Specialization to allow use of -// FastDelegate< R ( ) > -// instead of -// FastDelegate0 < R > -template -class FastDelegate< R ( ) > - // Inherit from FastDelegate0 so that it can be treated just like a FastDelegate0 - : public FastDelegate0 < R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate0 < R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=1 -// Specialization to allow use of -// FastDelegate< R ( Param1 ) > -// instead of -// FastDelegate1 < Param1, R > -template -class FastDelegate< R ( Param1 ) > - // Inherit from FastDelegate1 so that it can be treated just like a FastDelegate1 - : public FastDelegate1 < Param1, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate1 < Param1, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=2 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2 ) > -// instead of -// FastDelegate2 < Param1, Param2, R > -template -class FastDelegate< R ( Param1, Param2 ) > - // Inherit from FastDelegate2 so that it can be treated just like a FastDelegate2 - : public FastDelegate2 < Param1, Param2, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate2 < Param1, Param2, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=3 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2, Param3 ) > -// instead of -// FastDelegate3 < Param1, Param2, Param3, R > -template -class FastDelegate< R ( Param1, Param2, Param3 ) > - // Inherit from FastDelegate3 so that it can be treated just like a FastDelegate3 - : public FastDelegate3 < Param1, Param2, Param3, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate3 < Param1, Param2, Param3, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=4 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2, Param3, Param4 ) > -// instead of -// FastDelegate4 < Param1, Param2, Param3, Param4, R > -template -class FastDelegate< R ( Param1, Param2, Param3, Param4 ) > - // Inherit from FastDelegate4 so that it can be treated just like a FastDelegate4 - : public FastDelegate4 < Param1, Param2, Param3, Param4, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate4 < Param1, Param2, Param3, Param4, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=5 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5 ) > -// instead of -// FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > -template -class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5 ) > - // Inherit from FastDelegate5 so that it can be treated just like a FastDelegate5 - : public FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=6 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6 ) > -// instead of -// FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > -template -class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6 ) > - // Inherit from FastDelegate6 so that it can be treated just like a FastDelegate6 - : public FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=7 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7 ) > -// instead of -// FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > -template -class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7 ) > - // Inherit from FastDelegate7 so that it can be treated just like a FastDelegate7 - : public FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - -//N=8 -// Specialization to allow use of -// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 ) > -// instead of -// FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > -template -class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 ) > - // Inherit from FastDelegate8 so that it can be treated just like a FastDelegate8 - : public FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > -{ -public: - // Make using the base type a bit easier via typedef. - typedef FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > BaseType; - - // Allow users access to the specific type of this delegate. - typedef FastDelegate SelfType; - - // Mimic the base class constructors. - FastDelegate() : BaseType() { } - - template < class X, class Y > - FastDelegate(Y * pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 )) - : BaseType(pthis, function_to_bind) { } - - template < class X, class Y > - FastDelegate(const Y *pthis, - R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const) - : BaseType(pthis, function_to_bind) - { } - - FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 )) - : BaseType(function_to_bind) { } - void operator = (const BaseType &x) { - *static_cast(this) = x; } -}; - - -#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX - -//////////////////////////////////////////////////////////////////////////////// -// Fast Delegates, part 5: -// -// MakeDelegate() helper function -// -// MakeDelegate(&x, &X::func) returns a fastdelegate of the type -// necessary for calling x.func() with the correct number of arguments. -// This makes it possible to eliminate many typedefs from user code. -// -//////////////////////////////////////////////////////////////////////////////// - -// Also declare overloads of a MakeDelegate() global function to -// reduce the need for typedefs. -// We need seperate overloads for const and non-const member functions. -// Also, because of the weird rule about the class of derived member function pointers, -// implicit downcasts may need to be applied later to the 'this' pointer. -// That's why two classes (X and Y) appear in the definitions. Y must be implicitly -// castable to X. - -// Workaround for VC6. VC6 needs void return types converted into DefaultVoid. -// GCC 3.2 and later won't compile this unless it's preceded by 'typename', -// but VC6 doesn't allow 'typename' in this context. -// So, I have to use a macro. - -#ifdef FASTDLGT_VC6 -#define FASTDLGT_RETTYPE detail::VoidToDefaultVoid::type -#else -#define FASTDLGT_RETTYPE RetType -#endif - -//N=0 -template -FastDelegate0 MakeDelegate(Y* x, RetType (X::*func)()) { - return FastDelegate0(x, func); -} - -template -FastDelegate0 MakeDelegate(Y* x, RetType (X::*func)() const) { - return FastDelegate0(x, func); -} - -//N=1 -template -FastDelegate1 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1)) { - return FastDelegate1(x, func); -} - -template -FastDelegate1 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1) const) { - return FastDelegate1(x, func); -} - -//N=2 -template -FastDelegate2 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2)) { - return FastDelegate2(x, func); -} - -template -FastDelegate2 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2) const) { - return FastDelegate2(x, func); -} - -//N=3 -template -FastDelegate3 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3)) { - return FastDelegate3(x, func); -} - -template -FastDelegate3 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3) const) { - return FastDelegate3(x, func); -} - -//N=4 -template -FastDelegate4 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { - return FastDelegate4(x, func); -} - -template -FastDelegate4 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { - return FastDelegate4(x, func); -} - -//N=5 -template -FastDelegate5 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { - return FastDelegate5(x, func); -} - -template -FastDelegate5 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { - return FastDelegate5(x, func); -} - -//N=6 -template -FastDelegate6 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { - return FastDelegate6(x, func); -} - -template -FastDelegate6 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { - return FastDelegate6(x, func); -} - -//N=7 -template -FastDelegate7 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { - return FastDelegate7(x, func); -} - -template -FastDelegate7 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { - return FastDelegate7(x, func); -} - -//N=8 -template -FastDelegate8 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { - return FastDelegate8(x, func); -} - -template -FastDelegate8 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { - return FastDelegate8(x, func); -} - - - // clean up after ourselves... -#undef FASTDLGT_RETTYPE - -} // namespace fastdelegate - -#endif // !defined(FASTDELEGATE_H) - +// FastDelegate.h +// Efficient delegates in C++ that generate only two lines of asm code! +// Documentation is found at http://www.codeproject.com/cpp/FastDelegate.asp +// +// - Don Clugston, Mar 2004. +// Major contributions were made by Jody Hagins. +// History: +// 24-Apr-04 1.0 * Submitted to CodeProject. +// 28-Apr-04 1.1 * Prevent most unsafe uses of evil static function hack. +// * Improved syntax for horrible_cast (thanks Paul Bludov). +// * Tested on Metrowerks MWCC and Intel ICL (IA32) +// * Compiled, but not run, on Comeau C++ and Intel Itanium ICL. +// 27-Jun-04 1.2 * Now works on Borland C++ Builder 5.5 +// * Now works on /clr "managed C++" code on VC7, VC7.1 +// * Comeau C++ now compiles without warnings. +// * Prevent the virtual inheritance case from being used on +// VC6 and earlier, which generate incorrect code. +// * Improved warning and error messages. Non-standard hacks +// now have compile-time checks to make them safer. +// * implicit_cast used instead of static_cast in many cases. +// * If calling a const member function, a const class pointer can be used. +// * MakeDelegate() global helper function added to simplify pass-by-value. +// * Added fastdelegate.clear() +// 16-Jul-04 1.2.1* Workaround for gcc bug (const member function pointers in templates) +// 30-Oct-04 1.3 * Support for (non-void) return values. +// * No more workarounds in client code! +// MSVC and Intel now use a clever hack invented by John Dlugosz: +// - The FASTDELEGATEDECLARE workaround is no longer necessary. +// - No more warning messages for VC6 +// * Less use of macros. Error messages should be more comprehensible. +// * Added include guards +// * Added FastDelegate::empty() to test if invocation is safe (Thanks Neville Franks). +// * Now tested on VS 2005 Express Beta, PGI C++ +// 24-Dec-04 1.4 * Added DelegateMemento, to allow collections of disparate delegates. +// * <,>,<=,>= comparison operators to allow storage in ordered containers. +// * Substantial reduction of code size, especially the 'Closure' class. +// * Standardised all the compiler-specific workarounds. +// * MFP conversion now works for CodePlay (but not yet supported in the full code). +// * Now compiles without warnings on _any_ supported compiler, including BCC 5.5.1 +// * New syntax: FastDelegate< int (char *, double) >. +// 14-Feb-05 1.4.1* Now treats =0 as equivalent to .clear(), ==0 as equivalent to .empty(). (Thanks elfric). +// * Now tested on Intel ICL for AMD64, VS2005 Beta for AMD64 and Itanium. +// 30-Mar-05 1.5 * Safebool idiom: "if (dg)" is now equivalent to "if (!dg.empty())" +// * Fully supported by CodePlay VectorC +// * Bugfix for Metrowerks: empty() was buggy because a valid MFP can be 0 on MWCC! +// * More optimal assignment,== and != operators for static function pointers. + +#ifndef FASTDELEGATE_H +#define FASTDELEGATE_H +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include // to allow <,> comparisons + +//////////////////////////////////////////////////////////////////////////////// +// Configuration options +// +//////////////////////////////////////////////////////////////////////////////// + +// Uncomment the following #define for optimally-sized delegates. +// In this case, the generated asm code is almost identical to the code you'd get +// if the compiler had native support for delegates. +// It will not work on systems where sizeof(dataptr) < sizeof(codeptr). +// Thus, it will not work for DOS compilers using the medium model. +// It will also probably fail on some DSP systems. +#define FASTDELEGATE_USESTATICFUNCTIONHACK + +// Uncomment the next line to allow function declarator syntax. +// It is automatically enabled for those compilers where it is known to work. +//#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +//////////////////////////////////////////////////////////////////////////////// +// Compiler identification for workarounds +// +//////////////////////////////////////////////////////////////////////////////// + +// Compiler identification. It's not easy to identify Visual C++ because +// many vendors fraudulently define Microsoft's identifiers. +#if defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__VECTOR_C) && !defined(__ICL) && !defined(__BORLANDC__) +#define FASTDLGT_ISMSVC + +#if (_MSC_VER <1300) // Many workarounds are required for VC6. +#define FASTDLGT_VC6 +#pragma warning(disable:4786) // disable this ridiculous warning +#endif + +#endif + +// Does the compiler uses Microsoft's member function pointer structure? +// If so, it needs special treatment. +// Metrowerks CodeWarrior, Intel, and CodePlay fraudulently define Microsoft's +// identifier, _MSC_VER. We need to filter Metrowerks out. +#if defined(_MSC_VER) && !defined(__MWERKS__) +#define FASTDLGT_MICROSOFT_MFP + +#if !defined(__VECTOR_C) +// CodePlay doesn't have the __single/multi/virtual_inheritance keywords +#define FASTDLGT_HASINHERITANCE_KEYWORDS +#endif +#endif + +// Does it allow function declarator syntax? The following compilers are known to work: +#if defined(FASTDLGT_ISMSVC) && (_MSC_VER >=1310) // VC 7.1 +#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX +#endif + +// Gcc(2.95+), and versions of Digital Mars, Intel and Comeau in common use. +#if defined (__DMC__) || defined(__GNUC__) || defined(__ICL) || defined(__COMO__) +#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX +#endif + +// It works on Metrowerks MWCC 3.2.2. From boost.Config it should work on earlier ones too. +#if defined (__MWERKS__) +#define FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX +#endif + +#ifdef __GNUC__ // Workaround GCC bug #8271 + // At present, GCC doesn't recognize constness of MFPs in templates +#define FASTDELEGATE_GCC_BUG_8271 +#endif + + + +//////////////////////////////////////////////////////////////////////////////// +// General tricks used in this code +// +// (a) Error messages are generated by typdefing an array of negative size to +// generate compile-time errors. +// (b) Warning messages on MSVC are generated by declaring unused variables, and +// enabling the "variable XXX is never used" warning. +// (c) Unions are used in a few compiler-specific cases to perform illegal casts. +// (d) For Microsoft and Intel, when adjusting the 'this' pointer, it's cast to +// (char *) first to ensure that the correct number of *bytes* are added. +// +//////////////////////////////////////////////////////////////////////////////// +// Helper templates +// +//////////////////////////////////////////////////////////////////////////////// + + +namespace fastdelegate { +namespace detail { // we'll hide the implementation details in a nested namespace. + +// implicit_cast< > +// I believe this was originally going to be in the C++ standard but +// was left out by accident. It's even milder than static_cast. +// I use it instead of static_cast<> to emphasize that I'm not doing +// anything nasty. +// Usage is identical to static_cast<> +template +inline OutputClass implicit_cast(InputClass input){ + return input; +} + +// horrible_cast< > +// This is truly evil. It completely subverts C++'s type system, allowing you +// to cast from any class to any other class. Technically, using a union +// to perform the cast is undefined behaviour (even in C). But we can see if +// it is OK by checking that the union is the same size as each of its members. +// horrible_cast<> should only be used for compiler-specific workarounds. +// Usage is identical to reinterpret_cast<>. + +// This union is declared outside the horrible_cast because BCC 5.5.1 +// can't inline a function with a nested class, and gives a warning. +template +union horrible_union{ + OutputClass out; + InputClass in; +}; + +template +inline OutputClass horrible_cast(const InputClass input){ + horrible_union u; + // Cause a compile-time error if in, out and u are not the same size. + // If the compile fails here, it means the compiler has peculiar + // unions which would prevent the cast from working. + typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u) + && sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1]; + u.in = input; + return u.out; +} + +//////////////////////////////////////////////////////////////////////////////// +// Workarounds +// +//////////////////////////////////////////////////////////////////////////////// + +// Backwards compatibility: This macro used to be necessary in the virtual inheritance +// case for Intel and Microsoft. Now it just forward-declares the class. +#define FASTDELEGATEDECLARE(CLASSNAME) class CLASSNAME; + +// Prevent use of the static function hack with the DOS medium model. +#ifdef __MEDIUM__ +#undef FASTDELEGATE_USESTATICFUNCTIONHACK +#endif + +// DefaultVoid - a workaround for 'void' templates in VC6. +// +// (1) VC6 and earlier do not allow 'void' as a default template argument. +// (2) They also doesn't allow you to return 'void' from a function. +// +// Workaround for (1): Declare a dummy type 'DefaultVoid' which we use +// when we'd like to use 'void'. We convert it into 'void' and back +// using the templates DefaultVoidToVoid<> and VoidToDefaultVoid<>. +// Workaround for (2): On VC6, the code for calling a void function is +// identical to the code for calling a non-void function in which the +// return value is never used, provided the return value is returned +// in the EAX register, rather than on the stack. +// This is true for most fundamental types such as int, enum, void *. +// Const void * is the safest option since it doesn't participate +// in any automatic conversions. But on a 16-bit compiler it might +// cause extra code to be generated, so we disable it for all compilers +// except for VC6 (and VC5). +#ifdef FASTDLGT_VC6 +// VC6 workaround +typedef const void * DefaultVoid; +#else +// On any other compiler, just use a normal void. +typedef void DefaultVoid; +#endif + +// Translate from 'DefaultVoid' to 'void'. +// Everything else is unchanged +template +struct DefaultVoidToVoid { typedef T type; }; + +template <> +struct DefaultVoidToVoid { typedef void type; }; + +// Translate from 'void' into 'DefaultVoid' +// Everything else is unchanged +template +struct VoidToDefaultVoid { typedef T type; }; + +template <> +struct VoidToDefaultVoid { typedef DefaultVoid type; }; + + + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 1: +// +// Conversion of member function pointer to a standard form +// +//////////////////////////////////////////////////////////////////////////////// + +// GenericClass is a fake class, ONLY used to provide a type. +// It is vitally important that it is never defined, so that the compiler doesn't +// think it can optimize the invocation. For example, Borland generates simpler +// code if it knows the class only uses single inheritance. + +// Compilers using Microsoft's structure need to be treated as a special case. +#ifdef FASTDLGT_MICROSOFT_MFP + +#ifdef FASTDLGT_HASINHERITANCE_KEYWORDS + // For Microsoft and Intel, we want to ensure that it's the most efficient type of MFP + // (4 bytes), even when the /vmg option is used. Declaring an empty class + // would give 16 byte pointers in this case.... + class __single_inheritance GenericClass; +#endif + // ...but for Codeplay, an empty class *always* gives 4 byte pointers. + // If compiled with the /clr option ("managed C++"), the JIT compiler thinks + // it needs to load GenericClass before it can call any of its functions, + // (compiles OK but crashes at runtime!), so we need to declare an + // empty class to make it happy. + // Codeplay and VC4 can't cope with the unknown_inheritance case either. + class GenericClass {}; +#else + class GenericClass; +#endif + +// The size of a single inheritance member function pointer. +const int SINGLE_MEMFUNCPTR_SIZE = sizeof(void (GenericClass::*)()); + +// SimplifyMemFunc< >::Convert() +// +// A template function that converts an arbitrary member function pointer into the +// simplest possible form of member function pointer, using a supplied 'this' pointer. +// According to the standard, this can be done legally with reinterpret_cast<>. +// For (non-standard) compilers which use member function pointers which vary in size +// depending on the class, we need to use knowledge of the internal structure of a +// member function pointer, as used by the compiler. Template specialization is used +// to distinguish between the sizes. Because some compilers don't support partial +// template specialisation, I use full specialisation of a wrapper struct. + +// general case -- don't know how to convert it. Force a compile failure +template +struct SimplifyMemFunc { + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // Unsupported member function type -- force a compile failure. + // (it's illegal to have a array with negative size). + typedef char ERROR_Unsupported_member_function_pointer_on_this_compiler[N-100]; + return 0; + } +}; + +// For compilers where all member func ptrs are the same size, everything goes here. +// For non-standard compilers, only single_inheritance classes go here. +template <> +struct SimplifyMemFunc { + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { +#if defined __DMC__ + // Digital Mars doesn't allow you to cast between abitrary PMF's, + // even though the standard says you can. The 32-bit compiler lets you + // static_cast through an int, but the DOS compiler doesn't. + bound_func = horrible_cast(function_to_bind); +#else + bound_func = reinterpret_cast(function_to_bind); +#endif + return reinterpret_cast(pthis); + } +}; + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 1b: +// +// Workarounds for Microsoft and Intel +// +//////////////////////////////////////////////////////////////////////////////// + + +// Compilers with member function pointers which violate the standard (MSVC, Intel, Codeplay), +// need to be treated as a special case. +#ifdef FASTDLGT_MICROSOFT_MFP + +// We use unions to perform horrible_casts. I would like to use #pragma pack(push, 1) +// at the start of each function for extra safety, but VC6 seems to ICE +// intermittently if you do this inside a template. + +// __multiple_inheritance classes go here +// Nasty hack for Microsoft and Intel (IA32 and Itanium) +template<> +struct SimplifyMemFunc< SINGLE_MEMFUNCPTR_SIZE + sizeof(int) > { + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // We need to use a horrible_cast to do this conversion. + // In MSVC, a multiple inheritance member pointer is internally defined as: + union { + XFuncType func; + struct { + GenericMemFuncType funcaddress; // points to the actual member function + int delta; // #BYTES to be added to the 'this' pointer + }s; + } u; + // Check that the horrible_cast will work + typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)? 1 : -1]; + u.func = function_to_bind; + bound_func = u.s.funcaddress; + return reinterpret_cast(reinterpret_cast(pthis) + u.s.delta); + } +}; + +// virtual inheritance is a real nuisance. It's inefficient and complicated. +// On MSVC and Intel, there isn't enough information in the pointer itself to +// enable conversion to a closure pointer. Earlier versions of this code didn't +// work for all cases, and generated a compile-time error instead. +// But a very clever hack invented by John M. Dlugosz solves this problem. +// My code is somewhat different to his: I have no asm code, and I make no +// assumptions about the calling convention that is used. + +// In VC++ and ICL, a virtual_inheritance member pointer +// is internally defined as: +struct MicrosoftVirtualMFP { + void (GenericClass::*codeptr)(); // points to the actual member function + int delta; // #bytes to be added to the 'this' pointer + int vtable_index; // or 0 if no virtual inheritance +}; +// The CRUCIAL feature of Microsoft/Intel MFPs which we exploit is that the +// m_codeptr member is *always* called, regardless of the values of the other +// members. (This is *not* true for other compilers, eg GCC, which obtain the +// function address from the vtable if a virtual function is being called). +// Dlugosz's trick is to make the codeptr point to a probe function which +// returns the 'this' pointer that was used. + +// Define a generic class that uses virtual inheritance. +// It has a trival member function that returns the value of the 'this' pointer. +struct GenericVirtualClass : virtual public GenericClass +{ + typedef GenericVirtualClass * (GenericVirtualClass::*ProbePtrType)(); + GenericVirtualClass * GetThis() { return this; } +}; + +// __virtual_inheritance classes go here +template <> +struct SimplifyMemFunc +{ + + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + union { + XFuncType func; + GenericClass* (X::*ProbeFunc)(); + MicrosoftVirtualMFP s; + } u; + u.func = function_to_bind; + bound_func = reinterpret_cast(u.s.codeptr); + union { + GenericVirtualClass::ProbePtrType virtfunc; + MicrosoftVirtualMFP s; + } u2; + // Check that the horrible_cast<>s will work + typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s) + && sizeof(function_to_bind)==sizeof(u.ProbeFunc) + && sizeof(u2.virtfunc)==sizeof(u2.s) ? 1 : -1]; + // Unfortunately, taking the address of a MF prevents it from being inlined, so + // this next line can't be completely optimised away by the compiler. + u2.virtfunc = &GenericVirtualClass::GetThis; + u.s.codeptr = u2.s.codeptr; + return (pthis->*u.ProbeFunc)(); + } +}; + +#if (_MSC_VER <1300) + +// Nasty hack for Microsoft Visual C++ 6.0 +// unknown_inheritance classes go here +// There is a compiler bug in MSVC6 which generates incorrect code in this case!! +template <> +struct SimplifyMemFunc +{ + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // There is an apalling but obscure compiler bug in MSVC6 and earlier: + // vtable_index and 'vtordisp' are always set to 0 in the + // unknown_inheritance case! + // This means that an incorrect function could be called!!! + // Compiling with the /vmg option leads to potentially incorrect code. + // This is probably the reason that the IDE has a user interface for specifying + // the /vmg option, but it is disabled - you can only specify /vmg on + // the command line. In VC1.5 and earlier, the compiler would ICE if it ever + // encountered this situation. + // It is OK to use the /vmg option if /vmm or /vms is specified. + + // Fortunately, the wrong function is only called in very obscure cases. + // It only occurs when a derived class overrides a virtual function declared + // in a virtual base class, and the member function + // points to the *Derived* version of that function. The problem can be + // completely averted in 100% of cases by using the *Base class* for the + // member fpointer. Ie, if you use the base class as an interface, you'll + // stay out of trouble. + // Occasionally, you might want to point directly to a derived class function + // that isn't an override of a base class. In this case, both vtable_index + // and 'vtordisp' are zero, but a virtual_inheritance pointer will be generated. + // We can generate correct code in this case. To prevent an incorrect call from + // ever being made, on MSVC6 we generate a warning, and call a function to + // make the program crash instantly. + typedef char ERROR_VC6CompilerBug[-100]; + return 0; + } +}; + + +#else + +// Nasty hack for Microsoft and Intel (IA32 and Itanium) +// unknown_inheritance classes go here +// This is probably the ugliest bit of code I've ever written. Look at the casts! +// There is a compiler bug in MSVC6 which prevents it from using this code. +template <> +struct SimplifyMemFunc +{ + template + inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind, + GenericMemFuncType &bound_func) { + // The member function pointer is 16 bytes long. We can't use a normal cast, but + // we can use a union to do the conversion. + union { + XFuncType func; + // In VC++ and ICL, an unknown_inheritance member pointer + // is internally defined as: + struct { + GenericMemFuncType m_funcaddress; // points to the actual member function + int delta; // #bytes to be added to the 'this' pointer + int vtordisp; // #bytes to add to 'this' to find the vtable + int vtable_index; // or 0 if no virtual inheritance + } s; + } u; + // Check that the horrible_cast will work + typedef int ERROR_CantUsehorrible_cast[sizeof(XFuncType)==sizeof(u.s)? 1 : -1]; + u.func = function_to_bind; + bound_func = u.s.funcaddress; + int virtual_delta = 0; + if (u.s.vtable_index) { // Virtual inheritance is used + // First, get to the vtable. + // It is 'vtordisp' bytes from the start of the class. + const int * vtable = *reinterpret_cast( + reinterpret_cast(pthis) + u.s.vtordisp ); + + // 'vtable_index' tells us where in the table we should be looking. + virtual_delta = u.s.vtordisp + *reinterpret_cast( + reinterpret_cast(vtable) + u.s.vtable_index); + } + // The int at 'virtual_delta' gives us the amount to add to 'this'. + // Finally we can add the three components together. Phew! + return reinterpret_cast( + reinterpret_cast(pthis) + u.s.delta + virtual_delta); + }; +}; +#endif // MSVC 7 and greater + +#endif // MS/Intel hacks + +} // namespace detail + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 2: +// +// Define the delegate storage, and cope with static functions +// +//////////////////////////////////////////////////////////////////////////////// + +// DelegateMemento -- an opaque structure which can hold an arbitary delegate. +// It knows nothing about the calling convention or number of arguments used by +// the function pointed to. +// It supplies comparison operators so that it can be stored in STL collections. +// It cannot be set to anything other than null, nor invoked directly: +// it must be converted to a specific delegate. + +// Implementation: +// There are two possible implementations: the Safe method and the Evil method. +// DelegateMemento - Safe version +// +// This implementation is standard-compliant, but a bit tricky. +// A static function pointer is stored inside the class. +// Here are the valid values: +// +-- Static pointer --+--pThis --+-- pMemFunc-+-- Meaning------+ +// | 0 | 0 | 0 | Empty | +// | !=0 |(dontcare)| Invoker | Static function| +// | 0 | !=0 | !=0* | Method call | +// +--------------------+----------+------------+----------------+ +// * For Metrowerks, this can be 0. (first virtual function in a +// single_inheritance class). +// When stored stored inside a specific delegate, the 'dontcare' entries are replaced +// with a reference to the delegate itself. This complicates the = and == operators +// for the delegate class. + +// DelegateMemento - Evil version +// +// For compilers where data pointers are at least as big as code pointers, it is +// possible to store the function pointer in the this pointer, using another +// horrible_cast. In this case the DelegateMemento implementation is simple: +// +--pThis --+-- pMemFunc-+-- Meaning---------------------+ +// | 0 | 0 | Empty | +// | !=0 | !=0* | Static function or method call| +// +----------+------------+-------------------------------+ +// * For Metrowerks, this can be 0. (first virtual function in a +// single_inheritance class). +// Note that the Sun C++ and MSVC documentation explicitly state that they +// support static_cast between void * and function pointers. + +class DelegateMemento { +protected: + // the data is protected, not private, because many + // compilers have problems with template friends. + typedef void (detail::GenericClass::*GenericMemFuncType)(); // arbitrary MFP. + detail::GenericClass *m_pthis; + GenericMemFuncType m_pFunction; + +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + typedef void (*GenericFuncPtr)(); // arbitrary code pointer + GenericFuncPtr m_pStaticFunction; +#endif + +public: +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + DelegateMemento() : m_pthis(0), m_pFunction(0), m_pStaticFunction(0) {}; + void clear() { + m_pthis=0; m_pFunction=0; m_pStaticFunction=0; + } +#else + DelegateMemento() : m_pthis(0), m_pFunction(0) {}; + void clear() { m_pthis=0; m_pFunction=0; } +#endif +public: +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + inline bool IsEqual (const DelegateMemento &x) const{ + // We have to cope with the static function pointers as a special case + if (m_pFunction!=x.m_pFunction) return false; + // the static function ptrs must either both be equal, or both be 0. + if (m_pStaticFunction!=x.m_pStaticFunction) return false; + if (m_pStaticFunction!=0) return m_pthis==x.m_pthis; + else return true; + } +#else // Evil Method + inline bool IsEqual (const DelegateMemento &x) const{ + return m_pthis==x.m_pthis && m_pFunction==x.m_pFunction; + } +#endif + // Provide a strict weak ordering for DelegateMementos. + inline bool IsLess(const DelegateMemento &right) const { + // deal with static function pointers first +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + if (m_pStaticFunction !=0 || right.m_pStaticFunction!=0) + return m_pStaticFunction < right.m_pStaticFunction; +#endif + if (m_pthis !=right.m_pthis) return m_pthis < right.m_pthis; + // There are no ordering operators for member function pointers, + // but we can fake one by comparing each byte. The resulting ordering is + // arbitrary (and compiler-dependent), but it permits storage in ordered STL containers. + return memcmp(&m_pFunction, &right.m_pFunction, sizeof(m_pFunction)) < 0; + + } + // BUGFIX (Mar 2005): + // We can't just compare m_pFunction because on Metrowerks, + // m_pFunction can be zero even if the delegate is not empty! + inline bool operator ! () const // Is it bound to anything? + { return m_pthis==0 && m_pFunction==0; } + inline bool empty() const // Is it bound to anything? + { return m_pthis==0 && m_pFunction==0; } +public: + DelegateMemento & operator = (const DelegateMemento &right) { + SetMementoFrom(right); + return *this; + } + inline bool operator <(const DelegateMemento &right) { + return IsLess(right); + } + inline bool operator >(const DelegateMemento &right) { + return right.IsLess(*this); + } + DelegateMemento (const DelegateMemento &right) : + m_pthis(right.m_pthis), m_pFunction(right.m_pFunction) +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + , m_pStaticFunction (right.m_pStaticFunction) +#endif + {} +protected: + void SetMementoFrom(const DelegateMemento &right) { + m_pFunction = right.m_pFunction; + m_pthis = right.m_pthis; +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = right.m_pStaticFunction; +#endif + } +}; + + +// ClosurePtr<> +// +// A private wrapper class that adds function signatures to DelegateMemento. +// It's the class that does most of the actual work. +// The signatures are specified by: +// GenericMemFunc: must be a type of GenericClass member function pointer. +// StaticFuncPtr: must be a type of function pointer with the same signature +// as GenericMemFunc. +// UnvoidStaticFuncPtr: is the same as StaticFuncPtr, except on VC6 +// where it never returns void (returns DefaultVoid instead). + +// An outer class, FastDelegateN<>, handles the invoking and creates the +// necessary typedefs. +// This class does everything else. + +namespace detail { + +template < class GenericMemFunc, class StaticFuncPtr, class UnvoidStaticFuncPtr> +class ClosurePtr : public DelegateMemento { +public: + // These functions are for setting the delegate to a member function. + + // Here's the clever bit: we convert an arbitrary member function into a + // standard form. XMemFunc should be a member function of class X, but I can't + // enforce that here. It needs to be enforced by the wrapper class. + template < class X, class XMemFunc > + inline void bindmemfunc(X *pthis, XMemFunc function_to_bind ) { + m_pthis = SimplifyMemFunc< sizeof(function_to_bind) > + ::Convert(pthis, function_to_bind, m_pFunction); +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = 0; +#endif + } + // For const member functions, we only need a const class pointer. + // Since we know that the member function is const, it's safe to + // remove the const qualifier from the 'this' pointer with a const_cast. + // VC6 has problems if we just overload 'bindmemfunc', so we give it a different name. + template < class X, class XMemFunc> + inline void bindconstmemfunc(const X *pthis, XMemFunc function_to_bind) { + m_pthis= SimplifyMemFunc< sizeof(function_to_bind) > + ::Convert(const_cast(pthis), function_to_bind, m_pFunction); +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = 0; +#endif + } +#ifdef FASTDELEGATE_GCC_BUG_8271 // At present, GCC doesn't recognize constness of MFPs in templates + template < class X, class XMemFunc> + inline void bindmemfunc(const X *pthis, XMemFunc function_to_bind) { + bindconstmemfunc(pthis, function_to_bind); +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + m_pStaticFunction = 0; +#endif + } +#endif + // These functions are required for invoking the stored function + inline GenericClass *GetClosureThis() const { return m_pthis; } + inline GenericMemFunc GetClosureMemPtr() const { return reinterpret_cast(m_pFunction); } + +// There are a few ways of dealing with static function pointers. +// There's a standard-compliant, but tricky method. +// There's also a straightforward hack, that won't work on DOS compilers using the +// medium memory model. It's so evil that I can't recommend it, but I've +// implemented it anyway because it produces very nice asm code. + +#if !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + +// ClosurePtr<> - Safe version +// +// This implementation is standard-compliant, but a bit tricky. +// I store the function pointer inside the class, and the delegate then +// points to itself. Whenever the delegate is copied, these self-references +// must be transformed, and this complicates the = and == operators. +public: + // The next two functions are for operator ==, =, and the copy constructor. + // We may need to convert the m_pthis pointers, so that + // they remain as self-references. + template< class DerivedClass > + inline void CopyFrom (DerivedClass *pParent, const DelegateMemento &x) { + SetMementoFrom(x); + if (m_pStaticFunction!=0) { + // transform self references... + m_pthis=reinterpret_cast(pParent); + } + } + // For static functions, the 'static_function_invoker' class in the parent + // will be called. The parent then needs to call GetStaticFunction() to find out + // the actual function to invoke. + template < class DerivedClass, class ParentInvokerSig > + inline void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, + StaticFuncPtr function_to_bind ) { + if (function_to_bind==0) { // cope with assignment to 0 + m_pFunction=0; + } else { + bindmemfunc(pParent, static_function_invoker); + } + m_pStaticFunction=reinterpret_cast(function_to_bind); + } + inline UnvoidStaticFuncPtr GetStaticFunction() const { + return reinterpret_cast(m_pStaticFunction); + } +#else + +// ClosurePtr<> - Evil version +// +// For compilers where data pointers are at least as big as code pointers, it is +// possible to store the function pointer in the this pointer, using another +// horrible_cast. Invocation isn't any faster, but it saves 4 bytes, and +// speeds up comparison and assignment. If C++ provided direct language support +// for delegates, they would produce asm code that was almost identical to this. +// Note that the Sun C++ and MSVC documentation explicitly state that they +// support static_cast between void * and function pointers. + + template< class DerivedClass > + inline void CopyFrom (DerivedClass *pParent, const DelegateMemento &right) { + SetMementoFrom(right); + } + // For static functions, the 'static_function_invoker' class in the parent + // will be called. The parent then needs to call GetStaticFunction() to find out + // the actual function to invoke. + // ******** EVIL, EVIL CODE! ******* + template < class DerivedClass, class ParentInvokerSig> + inline void bindstaticfunc(DerivedClass *pParent, ParentInvokerSig static_function_invoker, + StaticFuncPtr function_to_bind) { + if (function_to_bind==0) { // cope with assignment to 0 + m_pFunction=0; + } else { + // We'll be ignoring the 'this' pointer, but we need to make sure we pass + // a valid value to bindmemfunc(). + bindmemfunc(pParent, static_function_invoker); + } + + // WARNING! Evil hack. We store the function in the 'this' pointer! + // Ensure that there's a compilation failure if function pointers + // and data pointers have different sizes. + // If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK. + typedef int ERROR_CantUseEvilMethod[sizeof(GenericClass *)==sizeof(function_to_bind) ? 1 : -1]; + m_pthis = horrible_cast(function_to_bind); + // MSVC, SunC++ and DMC accept the following (non-standard) code: +// m_pthis = static_cast(static_cast(function_to_bind)); + // BCC32, Comeau and DMC accept this method. MSVC7.1 needs __int64 instead of long +// m_pthis = reinterpret_cast(reinterpret_cast(function_to_bind)); + } + // ******** EVIL, EVIL CODE! ******* + // This function will be called with an invalid 'this' pointer!! + // We're just returning the 'this' pointer, converted into + // a function pointer! + inline UnvoidStaticFuncPtr GetStaticFunction() const { + // Ensure that there's a compilation failure if function pointers + // and data pointers have different sizes. + // If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK. + typedef int ERROR_CantUseEvilMethod[sizeof(UnvoidStaticFuncPtr)==sizeof(this) ? 1 : -1]; + return horrible_cast(this); + } +#endif // !defined(FASTDELEGATE_USESTATICFUNCTIONHACK) + + // Does the closure contain this static function? + inline bool IsEqualToStaticFuncPtr(StaticFuncPtr funcptr){ + if (funcptr==0) return empty(); + // For the Evil method, if it doesn't actually contain a static function, this will return an arbitrary + // value that is not equal to any valid function pointer. + else return funcptr==reinterpret_cast(GetStaticFunction()); + } +}; + + +} // namespace detail + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 3: +// +// Wrapper classes to ensure type safety +// +//////////////////////////////////////////////////////////////////////////////// + + +// Once we have the member function conversion templates, it's easy to make the +// wrapper classes. So that they will work with as many compilers as possible, +// the classes are of the form +// FastDelegate3 +// They can cope with any combination of parameters. The max number of parameters +// allowed is 8, but it is trivial to increase this limit. +// Note that we need to treat const member functions seperately. +// All this class does is to enforce type safety, and invoke the delegate with +// the correct list of parameters. + +// Because of the weird rule about the class of derived member function pointers, +// you sometimes need to apply a downcast to the 'this' pointer. +// This is the reason for the use of "implicit_cast(pthis)" in the code below. +// If CDerivedClass is derived from CBaseClass, but doesn't override SimpleVirtualFunction, +// without this trick you'd need to write: +// MyDelegate(static_cast(&d), &CDerivedClass::SimpleVirtualFunction); +// but with the trick you can write +// MyDelegate(&d, &CDerivedClass::SimpleVirtualFunction); + +// RetType is the type the compiler uses in compiling the template. For VC6, +// it cannot be void. DesiredRetType is the real type which is returned from +// all of the functions. It can be void. + +// Implicit conversion to "bool" is achieved using the safe_bool idiom, +// using member data pointers (MDP). This allows "if (dg)..." syntax +// Because some compilers (eg codeplay) don't have a unique value for a zero +// MDP, an extra padding member is added to the SafeBool struct. +// Some compilers (eg VC6) won't implicitly convert from 0 to an MDP, so +// in that case the static function constructor is not made explicit; this +// allows "if (dg==0) ..." to compile. + +//N=0 +template +class FastDelegate0 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(); + typedef RetType (*UnvoidStaticFunctionPtr)(); + typedef RetType (detail::GenericClass::*GenericMemFn)(); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate0 type; + + // Construction and comparison functions + FastDelegate0() { clear(); } + FastDelegate0(const FastDelegate0 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate0 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate0 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate0 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate0 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate0 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate0(Y *pthis, DesiredRetType (X::* function_to_bind)() ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)()) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate0(const Y *pthis, DesiredRetType (X::* function_to_bind)() const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)() const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate0(DesiredRetType (*function_to_bind)() ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)() ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)()) { + m_Closure.bindstaticfunc(this, &FastDelegate0::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() () const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction() const { + return (*(m_Closure.GetStaticFunction()))(); } +}; + +//N=1 +template +class FastDelegate1 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate1 type; + + // Construction and comparison functions + FastDelegate1() { clear(); } + FastDelegate1(const FastDelegate1 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate1 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate1 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate1 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate1 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate1 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate1(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate1(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate1(DesiredRetType (*function_to_bind)(Param1 p1) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1)) { + m_Closure.bindstaticfunc(this, &FastDelegate1::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1) const { + return (*(m_Closure.GetStaticFunction()))(p1); } +}; + +//N=2 +template +class FastDelegate2 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate2 type; + + // Construction and comparison functions + FastDelegate2() { clear(); } + FastDelegate2(const FastDelegate2 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate2 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate2 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate2 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate2 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate2 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate2(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate2(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate2(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2)) { + m_Closure.bindstaticfunc(this, &FastDelegate2::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2); } +}; + +//N=3 +template +class FastDelegate3 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate3 type; + + // Construction and comparison functions + FastDelegate3() { clear(); } + FastDelegate3(const FastDelegate3 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate3 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate3 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate3 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate3 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate3 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate3(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate3(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate3(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3)) { + m_Closure.bindstaticfunc(this, &FastDelegate3::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3); } +}; + +//N=4 +template +class FastDelegate4 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate4 type; + + // Construction and comparison functions + FastDelegate4() { clear(); } + FastDelegate4(const FastDelegate4 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate4 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate4 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate4 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate4 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate4 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate4(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate4(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate4(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { + m_Closure.bindstaticfunc(this, &FastDelegate4::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4); } +}; + +//N=5 +template +class FastDelegate5 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate5 type; + + // Construction and comparison functions + FastDelegate5() { clear(); } + FastDelegate5(const FastDelegate5 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate5 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate5 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate5 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate5 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate5 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate5(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate5(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate5(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { + m_Closure.bindstaticfunc(this, &FastDelegate5::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5); } +}; + +//N=6 +template +class FastDelegate6 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate6 type; + + // Construction and comparison functions + FastDelegate6() { clear(); } + FastDelegate6(const FastDelegate6 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate6 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate6 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate6 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate6 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate6 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate6(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate6(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate6(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { + m_Closure.bindstaticfunc(this, &FastDelegate6::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6); } +}; + +//N=7 +template +class FastDelegate7 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate7 type; + + // Construction and comparison functions + FastDelegate7() { clear(); } + FastDelegate7(const FastDelegate7 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate7 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate7 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate7 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate7 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate7 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate7(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate7(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate7(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { + m_Closure.bindstaticfunc(this, &FastDelegate7::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7); } +}; + +//N=8 +template +class FastDelegate8 { +private: + typedef typename detail::DefaultVoidToVoid::type DesiredRetType; + typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); + typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); + typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8); + typedef detail::ClosurePtr ClosureType; + ClosureType m_Closure; +public: + // Typedefs to aid generic programming + typedef FastDelegate8 type; + + // Construction and comparison functions + FastDelegate8() { clear(); } + FastDelegate8(const FastDelegate8 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + void operator = (const FastDelegate8 &x) { + m_Closure.CopyFrom(this, x.m_Closure); } + bool operator ==(const FastDelegate8 &x) const { + return m_Closure.IsEqual(x.m_Closure); } + bool operator !=(const FastDelegate8 &x) const { + return !m_Closure.IsEqual(x.m_Closure); } + bool operator <(const FastDelegate8 &x) const { + return m_Closure.IsLess(x.m_Closure); } + bool operator >(const FastDelegate8 &x) const { + return x.m_Closure.IsLess(m_Closure); } + // Binding to non-const member functions + template < class X, class Y > + FastDelegate8(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { + m_Closure.bindmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Binding to const member functions. + template < class X, class Y > + FastDelegate8(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + template < class X, class Y > + inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { + m_Closure.bindconstmemfunc(detail::implicit_cast(pthis), function_to_bind); } + // Static functions. We convert them into a member function call. + // This constructor also provides implicit conversion + FastDelegate8(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { + bind(function_to_bind); } + // for efficiency, prevent creation of a temporary + void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) ) { + bind(function_to_bind); } + inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { + m_Closure.bindstaticfunc(this, &FastDelegate8::InvokeStaticFunction, + function_to_bind); } + // Invoke the delegate + RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const { + return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7, p8); } + // Implicit conversion to "bool" using the safe_bool idiom +private: + typedef struct SafeBoolStruct { + int a_data_pointer_to_this_is_0_on_buggy_compilers; + StaticFunctionPtr m_nonzero; + } UselessTypedef; + typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type; +public: + operator unspecified_bool_type() const { + return empty()? 0: &SafeBoolStruct::m_nonzero; + } + // necessary to allow ==0 to work despite the safe_bool idiom + inline bool operator==(StaticFunctionPtr funcptr) { + return m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator!=(StaticFunctionPtr funcptr) { + return !m_Closure.IsEqualToStaticFuncPtr(funcptr); } + inline bool operator ! () const { // Is it bound to anything? + return !m_Closure; } + inline bool empty() const { + return !m_Closure; } + void clear() { m_Closure.clear();} + // Conversion to and from the DelegateMemento storage class + const DelegateMemento & GetMemento() { return m_Closure; } + void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); } + +private: // Invoker for static functions + RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const { + return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8); } +}; + + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 4: +// +// FastDelegate<> class (Original author: Jody Hagins) +// Allows boost::function style syntax like: +// FastDelegate< double (int, long) > +// instead of: +// FastDelegate2< int, long, double > +// +//////////////////////////////////////////////////////////////////////////////// + +#ifdef FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +// Declare FastDelegate as a class template. It will be specialized +// later for all number of arguments. +template +class FastDelegate; + +//N=0 +// Specialization to allow use of +// FastDelegate< R ( ) > +// instead of +// FastDelegate0 < R > +template +class FastDelegate< R ( ) > + // Inherit from FastDelegate0 so that it can be treated just like a FastDelegate0 + : public FastDelegate0 < R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate0 < R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=1 +// Specialization to allow use of +// FastDelegate< R ( Param1 ) > +// instead of +// FastDelegate1 < Param1, R > +template +class FastDelegate< R ( Param1 ) > + // Inherit from FastDelegate1 so that it can be treated just like a FastDelegate1 + : public FastDelegate1 < Param1, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate1 < Param1, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=2 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2 ) > +// instead of +// FastDelegate2 < Param1, Param2, R > +template +class FastDelegate< R ( Param1, Param2 ) > + // Inherit from FastDelegate2 so that it can be treated just like a FastDelegate2 + : public FastDelegate2 < Param1, Param2, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate2 < Param1, Param2, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=3 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3 ) > +// instead of +// FastDelegate3 < Param1, Param2, Param3, R > +template +class FastDelegate< R ( Param1, Param2, Param3 ) > + // Inherit from FastDelegate3 so that it can be treated just like a FastDelegate3 + : public FastDelegate3 < Param1, Param2, Param3, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate3 < Param1, Param2, Param3, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=4 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4 ) > +// instead of +// FastDelegate4 < Param1, Param2, Param3, Param4, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4 ) > + // Inherit from FastDelegate4 so that it can be treated just like a FastDelegate4 + : public FastDelegate4 < Param1, Param2, Param3, Param4, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate4 < Param1, Param2, Param3, Param4, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=5 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5 ) > +// instead of +// FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5 ) > + // Inherit from FastDelegate5 so that it can be treated just like a FastDelegate5 + : public FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate5 < Param1, Param2, Param3, Param4, Param5, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=6 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6 ) > +// instead of +// FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6 ) > + // Inherit from FastDelegate6 so that it can be treated just like a FastDelegate6 + : public FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate6 < Param1, Param2, Param3, Param4, Param5, Param6, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=7 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7 ) > +// instead of +// FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7 ) > + // Inherit from FastDelegate7 so that it can be treated just like a FastDelegate7 + : public FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate7 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + +//N=8 +// Specialization to allow use of +// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 ) > +// instead of +// FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > +template +class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8 ) > + // Inherit from FastDelegate8 so that it can be treated just like a FastDelegate8 + : public FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > +{ +public: + // Make using the base type a bit easier via typedef. + typedef FastDelegate8 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, R > BaseType; + + // Allow users access to the specific type of this delegate. + typedef FastDelegate SelfType; + + // Mimic the base class constructors. + FastDelegate() : BaseType() { } + + template < class X, class Y > + FastDelegate(Y * pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 )) + : BaseType(pthis, function_to_bind) { } + + template < class X, class Y > + FastDelegate(const Y *pthis, + R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 ) const) + : BaseType(pthis, function_to_bind) + { } + + FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8 )) + : BaseType(function_to_bind) { } + void operator = (const BaseType &x) { + *static_cast(this) = x; } +}; + + +#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX + +//////////////////////////////////////////////////////////////////////////////// +// Fast Delegates, part 5: +// +// MakeDelegate() helper function +// +// MakeDelegate(&x, &X::func) returns a fastdelegate of the type +// necessary for calling x.func() with the correct number of arguments. +// This makes it possible to eliminate many typedefs from user code. +// +//////////////////////////////////////////////////////////////////////////////// + +// Also declare overloads of a MakeDelegate() global function to +// reduce the need for typedefs. +// We need seperate overloads for const and non-const member functions. +// Also, because of the weird rule about the class of derived member function pointers, +// implicit downcasts may need to be applied later to the 'this' pointer. +// That's why two classes (X and Y) appear in the definitions. Y must be implicitly +// castable to X. + +// Workaround for VC6. VC6 needs void return types converted into DefaultVoid. +// GCC 3.2 and later won't compile this unless it's preceded by 'typename', +// but VC6 doesn't allow 'typename' in this context. +// So, I have to use a macro. + +#ifdef FASTDLGT_VC6 +#define FASTDLGT_RETTYPE detail::VoidToDefaultVoid::type +#else +#define FASTDLGT_RETTYPE RetType +#endif + +//N=0 +template +FastDelegate0 MakeDelegate(Y* x, RetType (X::*func)()) { + return FastDelegate0(x, func); +} + +template +FastDelegate0 MakeDelegate(Y* x, RetType (X::*func)() const) { + return FastDelegate0(x, func); +} + +//N=1 +template +FastDelegate1 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1)) { + return FastDelegate1(x, func); +} + +template +FastDelegate1 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1) const) { + return FastDelegate1(x, func); +} + +//N=2 +template +FastDelegate2 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2)) { + return FastDelegate2(x, func); +} + +template +FastDelegate2 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2) const) { + return FastDelegate2(x, func); +} + +//N=3 +template +FastDelegate3 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3)) { + return FastDelegate3(x, func); +} + +template +FastDelegate3 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3) const) { + return FastDelegate3(x, func); +} + +//N=4 +template +FastDelegate4 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4)) { + return FastDelegate4(x, func); +} + +template +FastDelegate4 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4) const) { + return FastDelegate4(x, func); +} + +//N=5 +template +FastDelegate5 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5)) { + return FastDelegate5(x, func); +} + +template +FastDelegate5 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5) const) { + return FastDelegate5(x, func); +} + +//N=6 +template +FastDelegate6 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6)) { + return FastDelegate6(x, func); +} + +template +FastDelegate6 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6) const) { + return FastDelegate6(x, func); +} + +//N=7 +template +FastDelegate7 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7)) { + return FastDelegate7(x, func); +} + +template +FastDelegate7 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7) const) { + return FastDelegate7(x, func); +} + +//N=8 +template +FastDelegate8 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8)) { + return FastDelegate8(x, func); +} + +template +FastDelegate8 MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8) const) { + return FastDelegate8(x, func); +} + + + // clean up after ourselves... +#undef FASTDLGT_RETTYPE + +} // namespace fastdelegate + +#endif // !defined(FASTDELEGATE_H) + diff --git a/dlls/ns/GameManager.cpp b/modules/ns/GameManager.cpp similarity index 100% rename from dlls/ns/GameManager.cpp rename to modules/ns/GameManager.cpp diff --git a/dlls/ns/GameManager.h b/modules/ns/GameManager.h similarity index 100% rename from dlls/ns/GameManager.h rename to modules/ns/GameManager.h diff --git a/dlls/ns/Hash.h b/modules/ns/Hash.h similarity index 100% rename from dlls/ns/Hash.h rename to modules/ns/Hash.h diff --git a/dlls/ns/LocationManager.h b/modules/ns/LocationManager.h similarity index 100% rename from dlls/ns/LocationManager.h rename to modules/ns/LocationManager.h diff --git a/dlls/ns/Makefile b/modules/ns/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/ns/Makefile rename to modules/ns/Makefile diff --git a/dlls/ns/MessageHandler.cpp b/modules/ns/MessageHandler.cpp similarity index 100% rename from dlls/ns/MessageHandler.cpp rename to modules/ns/MessageHandler.cpp diff --git a/dlls/ns/MessageHandler.h b/modules/ns/MessageHandler.h similarity index 100% rename from dlls/ns/MessageHandler.h rename to modules/ns/MessageHandler.h diff --git a/dlls/ns/NEW_Util.h b/modules/ns/NEW_Util.h similarity index 100% rename from dlls/ns/NEW_Util.h rename to modules/ns/NEW_Util.h diff --git a/dlls/ns/ParticleManager.cpp b/modules/ns/ParticleManager.cpp similarity index 100% rename from dlls/ns/ParticleManager.cpp rename to modules/ns/ParticleManager.cpp diff --git a/dlls/ns/ParticleManager.h b/modules/ns/ParticleManager.h similarity index 100% rename from dlls/ns/ParticleManager.h rename to modules/ns/ParticleManager.h diff --git a/dlls/ns/SpawnManager.h b/modules/ns/SpawnManager.h similarity index 100% rename from dlls/ns/SpawnManager.h rename to modules/ns/SpawnManager.h diff --git a/dlls/ns/TitleManager.cpp b/modules/ns/TitleManager.cpp similarity index 100% rename from dlls/ns/TitleManager.cpp rename to modules/ns/TitleManager.cpp diff --git a/dlls/ns/TitleManager.h b/modules/ns/TitleManager.h similarity index 100% rename from dlls/ns/TitleManager.h rename to modules/ns/TitleManager.h diff --git a/dlls/ns/amxxapi.cpp b/modules/ns/amxxapi.cpp similarity index 100% rename from dlls/ns/amxxapi.cpp rename to modules/ns/amxxapi.cpp diff --git a/dlls/ns/dllapi.cpp b/modules/ns/dllapi.cpp similarity index 100% rename from dlls/ns/dllapi.cpp rename to modules/ns/dllapi.cpp diff --git a/dlls/ns/engineapi.cpp b/modules/ns/engineapi.cpp similarity index 100% rename from dlls/ns/engineapi.cpp rename to modules/ns/engineapi.cpp diff --git a/dlls/ns/moduleconfig.h b/modules/ns/moduleconfig.h similarity index 100% rename from dlls/ns/moduleconfig.h rename to modules/ns/moduleconfig.h diff --git a/dlls/ns/msvc12/ns.sln b/modules/ns/msvc12/ns.sln similarity index 100% rename from dlls/ns/msvc12/ns.sln rename to modules/ns/msvc12/ns.sln diff --git a/dlls/ns/msvc12/ns.vcxproj b/modules/ns/msvc12/ns.vcxproj similarity index 100% rename from dlls/ns/msvc12/ns.vcxproj rename to modules/ns/msvc12/ns.vcxproj diff --git a/dlls/ns/msvc12/ns.vcxproj.filters b/modules/ns/msvc12/ns.vcxproj.filters similarity index 100% rename from dlls/ns/msvc12/ns.vcxproj.filters rename to modules/ns/msvc12/ns.vcxproj.filters diff --git a/dlls/ns/natives/general.cpp b/modules/ns/natives/general.cpp similarity index 100% rename from dlls/ns/natives/general.cpp rename to modules/ns/natives/general.cpp diff --git a/dlls/ns/natives/memberfuncs.cpp b/modules/ns/natives/memberfuncs.cpp similarity index 100% rename from dlls/ns/natives/memberfuncs.cpp rename to modules/ns/natives/memberfuncs.cpp diff --git a/dlls/ns/natives/particles.cpp b/modules/ns/natives/particles.cpp similarity index 100% rename from dlls/ns/natives/particles.cpp rename to modules/ns/natives/particles.cpp diff --git a/dlls/ns/natives/player.cpp b/modules/ns/natives/player.cpp similarity index 100% rename from dlls/ns/natives/player.cpp rename to modules/ns/natives/player.cpp diff --git a/dlls/ns/natives/player_memory.cpp b/modules/ns/natives/player_memory.cpp similarity index 100% rename from dlls/ns/natives/player_memory.cpp rename to modules/ns/natives/player_memory.cpp diff --git a/dlls/ns/natives/structure.cpp b/modules/ns/natives/structure.cpp similarity index 100% rename from dlls/ns/natives/structure.cpp rename to modules/ns/natives/structure.cpp diff --git a/dlls/ns/natives/weapons.cpp b/modules/ns/natives/weapons.cpp similarity index 100% rename from dlls/ns/natives/weapons.cpp rename to modules/ns/natives/weapons.cpp diff --git a/dlls/ns/ns.h b/modules/ns/ns.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ns/ns.h rename to modules/ns/ns.h diff --git a/dlls/ns/ns_const.h b/modules/ns/ns_const.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ns/ns_const.h rename to modules/ns/ns_const.h diff --git a/dlls/ns/res_plugin.rc b/modules/ns/res_plugin.rc old mode 100755 new mode 100644 similarity index 100% rename from dlls/ns/res_plugin.rc rename to modules/ns/res_plugin.rc diff --git a/dlls/ns/utilfunctions.h b/modules/ns/utilfunctions.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ns/utilfunctions.h rename to modules/ns/utilfunctions.h diff --git a/dlls/ns/utils.cpp b/modules/ns/utils.cpp similarity index 100% rename from dlls/ns/utils.cpp rename to modules/ns/utils.cpp diff --git a/dlls/ns/version.rc b/modules/ns/version.rc similarity index 100% rename from dlls/ns/version.rc rename to modules/ns/version.rc diff --git a/dlls/nvault/AMBuilder b/modules/nvault/AMBuilder similarity index 100% rename from dlls/nvault/AMBuilder rename to modules/nvault/AMBuilder diff --git a/dlls/nvault/Binary.cpp b/modules/nvault/Binary.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/Binary.cpp rename to modules/nvault/Binary.cpp diff --git a/dlls/nvault/Binary.h b/modules/nvault/Binary.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/Binary.h rename to modules/nvault/Binary.h diff --git a/dlls/nvault/IVault.h b/modules/nvault/IVault.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/IVault.h rename to modules/nvault/IVault.h diff --git a/dlls/nvault/Journal.cpp b/modules/nvault/Journal.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/Journal.cpp rename to modules/nvault/Journal.cpp diff --git a/dlls/nvault/Journal.h b/modules/nvault/Journal.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/Journal.h rename to modules/nvault/Journal.h diff --git a/dlls/nvault/Makefile b/modules/nvault/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/Makefile rename to modules/nvault/Makefile diff --git a/dlls/nvault/NVault.cpp b/modules/nvault/NVault.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/NVault.cpp rename to modules/nvault/NVault.cpp diff --git a/dlls/nvault/NVault.h b/modules/nvault/NVault.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/NVault.h rename to modules/nvault/NVault.h diff --git a/dlls/nvault/amxxapi.cpp b/modules/nvault/amxxapi.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/amxxapi.cpp rename to modules/nvault/amxxapi.cpp diff --git a/dlls/nvault/amxxapi.h b/modules/nvault/amxxapi.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/amxxapi.h rename to modules/nvault/amxxapi.h diff --git a/dlls/nvault/compat.h b/modules/nvault/compat.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/nvault/compat.h rename to modules/nvault/compat.h diff --git a/dlls/nvault/moduleconfig.h b/modules/nvault/moduleconfig.h similarity index 100% rename from dlls/nvault/moduleconfig.h rename to modules/nvault/moduleconfig.h diff --git a/dlls/nvault/msvc12/nvault.sln b/modules/nvault/msvc12/nvault.sln similarity index 100% rename from dlls/nvault/msvc12/nvault.sln rename to modules/nvault/msvc12/nvault.sln diff --git a/dlls/nvault/msvc12/nvault.vcxproj b/modules/nvault/msvc12/nvault.vcxproj similarity index 100% rename from dlls/nvault/msvc12/nvault.vcxproj rename to modules/nvault/msvc12/nvault.vcxproj diff --git a/dlls/nvault/msvc12/nvault.vcxproj.filters b/modules/nvault/msvc12/nvault.vcxproj.filters similarity index 100% rename from dlls/nvault/msvc12/nvault.vcxproj.filters rename to modules/nvault/msvc12/nvault.vcxproj.filters diff --git a/dlls/nvault/version.rc b/modules/nvault/version.rc similarity index 100% rename from dlls/nvault/version.rc rename to modules/nvault/version.rc diff --git a/dlls/regex/AMBuilder b/modules/regex/AMBuilder similarity index 100% rename from dlls/regex/AMBuilder rename to modules/regex/AMBuilder diff --git a/dlls/regex/CRegEx.cpp b/modules/regex/CRegEx.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/CRegEx.cpp rename to modules/regex/CRegEx.cpp diff --git a/dlls/regex/CRegEx.h b/modules/regex/CRegEx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/CRegEx.h rename to modules/regex/CRegEx.h diff --git a/dlls/regex/Makefile b/modules/regex/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/Makefile rename to modules/regex/Makefile diff --git a/dlls/regex/lib_darwin/libpcre.a b/modules/regex/lib_darwin/libpcre.a similarity index 100% rename from dlls/regex/lib_darwin/libpcre.a rename to modules/regex/lib_darwin/libpcre.a diff --git a/dlls/regex/lib_linux/libpcre.a b/modules/regex/lib_linux/libpcre.a old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/lib_linux/libpcre.a rename to modules/regex/lib_linux/libpcre.a diff --git a/dlls/regex/lib_win/pcre.lib b/modules/regex/lib_win/pcre.lib old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/lib_win/pcre.lib rename to modules/regex/lib_win/pcre.lib diff --git a/dlls/regex/module.cpp b/modules/regex/module.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/module.cpp rename to modules/regex/module.cpp diff --git a/dlls/regex/moduleconfig.h b/modules/regex/moduleconfig.h similarity index 100% rename from dlls/regex/moduleconfig.h rename to modules/regex/moduleconfig.h diff --git a/dlls/regex/msvc12/regex.sln b/modules/regex/msvc12/regex.sln similarity index 100% rename from dlls/regex/msvc12/regex.sln rename to modules/regex/msvc12/regex.sln diff --git a/dlls/regex/msvc12/regex.vcxproj b/modules/regex/msvc12/regex.vcxproj similarity index 100% rename from dlls/regex/msvc12/regex.vcxproj rename to modules/regex/msvc12/regex.vcxproj diff --git a/dlls/regex/msvc12/regex.vcxproj.filters b/modules/regex/msvc12/regex.vcxproj.filters similarity index 100% rename from dlls/regex/msvc12/regex.vcxproj.filters rename to modules/regex/msvc12/regex.vcxproj.filters diff --git a/dlls/regex/pcre.h b/modules/regex/pcre.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/regex/pcre.h rename to modules/regex/pcre.h diff --git a/dlls/regex/utils.cpp b/modules/regex/utils.cpp similarity index 100% rename from dlls/regex/utils.cpp rename to modules/regex/utils.cpp diff --git a/dlls/regex/utils.h b/modules/regex/utils.h similarity index 100% rename from dlls/regex/utils.h rename to modules/regex/utils.h diff --git a/dlls/regex/version.rc b/modules/regex/version.rc similarity index 100% rename from dlls/regex/version.rc rename to modules/regex/version.rc diff --git a/dlls/sockets/AMBuilder b/modules/sockets/AMBuilder similarity index 100% rename from dlls/sockets/AMBuilder rename to modules/sockets/AMBuilder diff --git a/dlls/sockets/Makefile b/modules/sockets/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/sockets/Makefile rename to modules/sockets/Makefile diff --git a/dlls/sockets/moduleconfig.h b/modules/sockets/moduleconfig.h similarity index 100% rename from dlls/sockets/moduleconfig.h rename to modules/sockets/moduleconfig.h diff --git a/dlls/sockets/msvc12/sockets.sln b/modules/sockets/msvc12/sockets.sln similarity index 100% rename from dlls/sockets/msvc12/sockets.sln rename to modules/sockets/msvc12/sockets.sln diff --git a/dlls/sockets/msvc12/sockets.vcxproj b/modules/sockets/msvc12/sockets.vcxproj similarity index 100% rename from dlls/sockets/msvc12/sockets.vcxproj rename to modules/sockets/msvc12/sockets.vcxproj diff --git a/dlls/sockets/msvc12/sockets.vcxproj.filters b/modules/sockets/msvc12/sockets.vcxproj.filters similarity index 100% rename from dlls/sockets/msvc12/sockets.vcxproj.filters rename to modules/sockets/msvc12/sockets.vcxproj.filters diff --git a/dlls/sockets/sockets.cpp b/modules/sockets/sockets.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/sockets/sockets.cpp rename to modules/sockets/sockets.cpp diff --git a/dlls/sockets/version.rc b/modules/sockets/version.rc similarity index 100% rename from dlls/sockets/version.rc rename to modules/sockets/version.rc diff --git a/dlls/sqlite/AMBuilder b/modules/sqlite/AMBuilder similarity index 100% rename from dlls/sqlite/AMBuilder rename to modules/sqlite/AMBuilder diff --git a/dlls/sqlite/Makefile b/modules/sqlite/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/sqlite/Makefile rename to modules/sqlite/Makefile diff --git a/dlls/sqlite/basic_sql.cpp b/modules/sqlite/basic_sql.cpp similarity index 100% rename from dlls/sqlite/basic_sql.cpp rename to modules/sqlite/basic_sql.cpp diff --git a/dlls/sqlite/handles.cpp b/modules/sqlite/handles.cpp similarity index 100% rename from dlls/sqlite/handles.cpp rename to modules/sqlite/handles.cpp diff --git a/dlls/sqlite/module.cpp b/modules/sqlite/module.cpp similarity index 100% rename from dlls/sqlite/module.cpp rename to modules/sqlite/module.cpp diff --git a/dlls/sqlite/moduleconfig.h b/modules/sqlite/moduleconfig.h similarity index 100% rename from dlls/sqlite/moduleconfig.h rename to modules/sqlite/moduleconfig.h diff --git a/dlls/sqlite/msvc12/sqlite.sln b/modules/sqlite/msvc12/sqlite.sln similarity index 100% rename from dlls/sqlite/msvc12/sqlite.sln rename to modules/sqlite/msvc12/sqlite.sln diff --git a/dlls/sqlite/msvc12/sqlite.vcxproj b/modules/sqlite/msvc12/sqlite.vcxproj similarity index 100% rename from dlls/sqlite/msvc12/sqlite.vcxproj rename to modules/sqlite/msvc12/sqlite.vcxproj diff --git a/dlls/sqlite/msvc12/sqlite.vcxproj.filters b/modules/sqlite/msvc12/sqlite.vcxproj.filters similarity index 100% rename from dlls/sqlite/msvc12/sqlite.vcxproj.filters rename to modules/sqlite/msvc12/sqlite.vcxproj.filters diff --git a/dlls/sqlite/oldcompat_sql.cpp b/modules/sqlite/oldcompat_sql.cpp similarity index 100% rename from dlls/sqlite/oldcompat_sql.cpp rename to modules/sqlite/oldcompat_sql.cpp diff --git a/dlls/sqlite/sqlheaders.h b/modules/sqlite/sqlheaders.h similarity index 100% rename from dlls/sqlite/sqlheaders.h rename to modules/sqlite/sqlheaders.h diff --git a/dlls/sqlite/sqlite_header.h b/modules/sqlite/sqlite_header.h similarity index 100% rename from dlls/sqlite/sqlite_header.h rename to modules/sqlite/sqlite_header.h diff --git a/dlls/sqlite/sqlitepp/ISQLDriver.h b/modules/sqlite/sqlitepp/ISQLDriver.h similarity index 100% rename from dlls/sqlite/sqlitepp/ISQLDriver.h rename to modules/sqlite/sqlitepp/ISQLDriver.h diff --git a/dlls/sqlite/sqlitepp/SqliteDatabase.cpp b/modules/sqlite/sqlitepp/SqliteDatabase.cpp similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteDatabase.cpp rename to modules/sqlite/sqlitepp/SqliteDatabase.cpp diff --git a/dlls/sqlite/sqlitepp/SqliteDatabase.h b/modules/sqlite/sqlitepp/SqliteDatabase.h similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteDatabase.h rename to modules/sqlite/sqlitepp/SqliteDatabase.h diff --git a/dlls/sqlite/sqlitepp/SqliteDriver.cpp b/modules/sqlite/sqlitepp/SqliteDriver.cpp similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteDriver.cpp rename to modules/sqlite/sqlitepp/SqliteDriver.cpp diff --git a/dlls/sqlite/sqlitepp/SqliteDriver.h b/modules/sqlite/sqlitepp/SqliteDriver.h similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteDriver.h rename to modules/sqlite/sqlitepp/SqliteDriver.h diff --git a/dlls/sqlite/sqlitepp/SqliteHeaders.h b/modules/sqlite/sqlitepp/SqliteHeaders.h similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteHeaders.h rename to modules/sqlite/sqlitepp/SqliteHeaders.h diff --git a/dlls/sqlite/sqlitepp/SqliteQuery.cpp b/modules/sqlite/sqlitepp/SqliteQuery.cpp similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteQuery.cpp rename to modules/sqlite/sqlitepp/SqliteQuery.cpp diff --git a/dlls/sqlite/sqlitepp/SqliteQuery.h b/modules/sqlite/sqlitepp/SqliteQuery.h similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteQuery.h rename to modules/sqlite/sqlitepp/SqliteQuery.h diff --git a/dlls/sqlite/sqlitepp/SqliteResultSet.cpp b/modules/sqlite/sqlitepp/SqliteResultSet.cpp similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteResultSet.cpp rename to modules/sqlite/sqlitepp/SqliteResultSet.cpp diff --git a/dlls/sqlite/sqlitepp/SqliteResultSet.h b/modules/sqlite/sqlitepp/SqliteResultSet.h similarity index 100% rename from dlls/sqlite/sqlitepp/SqliteResultSet.h rename to modules/sqlite/sqlitepp/SqliteResultSet.h diff --git a/dlls/sqlite/thread/BaseWorker.cpp b/modules/sqlite/thread/BaseWorker.cpp similarity index 100% rename from dlls/sqlite/thread/BaseWorker.cpp rename to modules/sqlite/thread/BaseWorker.cpp diff --git a/dlls/sqlite/thread/BaseWorker.h b/modules/sqlite/thread/BaseWorker.h similarity index 100% rename from dlls/sqlite/thread/BaseWorker.h rename to modules/sqlite/thread/BaseWorker.h diff --git a/dlls/sqlite/thread/IThreader.h b/modules/sqlite/thread/IThreader.h similarity index 100% rename from dlls/sqlite/thread/IThreader.h rename to modules/sqlite/thread/IThreader.h diff --git a/dlls/sqlite/thread/PosixThreads.cpp b/modules/sqlite/thread/PosixThreads.cpp similarity index 100% rename from dlls/sqlite/thread/PosixThreads.cpp rename to modules/sqlite/thread/PosixThreads.cpp diff --git a/dlls/sqlite/thread/PosixThreads.h b/modules/sqlite/thread/PosixThreads.h similarity index 100% rename from dlls/sqlite/thread/PosixThreads.h rename to modules/sqlite/thread/PosixThreads.h diff --git a/dlls/sqlite/thread/ThreadSupport.h b/modules/sqlite/thread/ThreadSupport.h similarity index 100% rename from dlls/sqlite/thread/ThreadSupport.h rename to modules/sqlite/thread/ThreadSupport.h diff --git a/dlls/sqlite/thread/ThreadWorker.cpp b/modules/sqlite/thread/ThreadWorker.cpp similarity index 100% rename from dlls/sqlite/thread/ThreadWorker.cpp rename to modules/sqlite/thread/ThreadWorker.cpp diff --git a/dlls/sqlite/thread/ThreadWorker.h b/modules/sqlite/thread/ThreadWorker.h similarity index 100% rename from dlls/sqlite/thread/ThreadWorker.h rename to modules/sqlite/thread/ThreadWorker.h diff --git a/dlls/sqlite/thread/WinThreads.cpp b/modules/sqlite/thread/WinThreads.cpp similarity index 100% rename from dlls/sqlite/thread/WinThreads.cpp rename to modules/sqlite/thread/WinThreads.cpp diff --git a/dlls/sqlite/thread/WinThreads.h b/modules/sqlite/thread/WinThreads.h similarity index 100% rename from dlls/sqlite/thread/WinThreads.h rename to modules/sqlite/thread/WinThreads.h diff --git a/dlls/sqlite/threading.cpp b/modules/sqlite/threading.cpp similarity index 100% rename from dlls/sqlite/threading.cpp rename to modules/sqlite/threading.cpp diff --git a/dlls/sqlite/threading.h b/modules/sqlite/threading.h similarity index 100% rename from dlls/sqlite/threading.h rename to modules/sqlite/threading.h diff --git a/dlls/sqlite/version.rc b/modules/sqlite/version.rc similarity index 100% rename from dlls/sqlite/version.rc rename to modules/sqlite/version.rc diff --git a/dlls/tfcx/AMBuilder b/modules/tfcx/AMBuilder similarity index 100% rename from dlls/tfcx/AMBuilder rename to modules/tfcx/AMBuilder diff --git a/dlls/tfcx/CMisc.cpp b/modules/tfcx/CMisc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/CMisc.cpp rename to modules/tfcx/CMisc.cpp diff --git a/dlls/tfcx/CMisc.h b/modules/tfcx/CMisc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/CMisc.h rename to modules/tfcx/CMisc.h diff --git a/dlls/tfcx/CRank.cpp b/modules/tfcx/CRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/CRank.cpp rename to modules/tfcx/CRank.cpp diff --git a/dlls/tfcx/CRank.h b/modules/tfcx/CRank.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/CRank.h rename to modules/tfcx/CRank.h diff --git a/dlls/tfcx/Makefile b/modules/tfcx/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/Makefile rename to modules/tfcx/Makefile diff --git a/dlls/tfcx/NBase.cpp b/modules/tfcx/NBase.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/NBase.cpp rename to modules/tfcx/NBase.cpp diff --git a/dlls/tfcx/NRank.cpp b/modules/tfcx/NRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/NRank.cpp rename to modules/tfcx/NRank.cpp diff --git a/dlls/tfcx/Utils.cpp b/modules/tfcx/Utils.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/Utils.cpp rename to modules/tfcx/Utils.cpp diff --git a/dlls/tfcx/moduleconfig.cpp b/modules/tfcx/moduleconfig.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/moduleconfig.cpp rename to modules/tfcx/moduleconfig.cpp diff --git a/dlls/tfcx/moduleconfig.h b/modules/tfcx/moduleconfig.h similarity index 100% rename from dlls/tfcx/moduleconfig.h rename to modules/tfcx/moduleconfig.h diff --git a/dlls/tfcx/msvc12/tfcx.sln b/modules/tfcx/msvc12/tfcx.sln similarity index 100% rename from dlls/tfcx/msvc12/tfcx.sln rename to modules/tfcx/msvc12/tfcx.sln diff --git a/dlls/tfcx/msvc12/tfcx.vcxproj b/modules/tfcx/msvc12/tfcx.vcxproj similarity index 100% rename from dlls/tfcx/msvc12/tfcx.vcxproj rename to modules/tfcx/msvc12/tfcx.vcxproj diff --git a/dlls/tfcx/msvc12/tfcx.vcxproj.filters b/modules/tfcx/msvc12/tfcx.vcxproj.filters similarity index 100% rename from dlls/tfcx/msvc12/tfcx.vcxproj.filters rename to modules/tfcx/msvc12/tfcx.vcxproj.filters diff --git a/dlls/tfcx/tfcx.h b/modules/tfcx/tfcx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/tfcx.h rename to modules/tfcx/tfcx.h diff --git a/dlls/tfcx/usermsg.cpp b/modules/tfcx/usermsg.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/tfcx/usermsg.cpp rename to modules/tfcx/usermsg.cpp diff --git a/dlls/tfcx/version.rc b/modules/tfcx/version.rc similarity index 100% rename from dlls/tfcx/version.rc rename to modules/tfcx/version.rc diff --git a/dlls/ts/tsfun/AMBuilder b/modules/ts/tsfun/AMBuilder similarity index 100% rename from dlls/ts/tsfun/AMBuilder rename to modules/ts/tsfun/AMBuilder diff --git a/dlls/ts/tsfun/Makefile b/modules/ts/tsfun/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsfun/Makefile rename to modules/ts/tsfun/Makefile diff --git a/dlls/ts/tsfun/moduleconfig.h b/modules/ts/tsfun/moduleconfig.h similarity index 100% rename from dlls/ts/tsfun/moduleconfig.h rename to modules/ts/tsfun/moduleconfig.h diff --git a/dlls/ts/tsfun/msvc12/tsfun.sln b/modules/ts/tsfun/msvc12/tsfun.sln similarity index 100% rename from dlls/ts/tsfun/msvc12/tsfun.sln rename to modules/ts/tsfun/msvc12/tsfun.sln diff --git a/dlls/ts/tsfun/msvc12/tsfun.vcxproj b/modules/ts/tsfun/msvc12/tsfun.vcxproj similarity index 100% rename from dlls/ts/tsfun/msvc12/tsfun.vcxproj rename to modules/ts/tsfun/msvc12/tsfun.vcxproj diff --git a/dlls/ts/tsfun/msvc12/tsfun.vcxproj.filters b/modules/ts/tsfun/msvc12/tsfun.vcxproj.filters similarity index 100% rename from dlls/ts/tsfun/msvc12/tsfun.vcxproj.filters rename to modules/ts/tsfun/msvc12/tsfun.vcxproj.filters diff --git a/dlls/ts/tsfun/version.rc b/modules/ts/tsfun/version.rc similarity index 100% rename from dlls/ts/tsfun/version.rc rename to modules/ts/tsfun/version.rc diff --git a/dlls/ts/tsx/AMBuilder b/modules/ts/tsx/AMBuilder similarity index 100% rename from dlls/ts/tsx/AMBuilder rename to modules/ts/tsx/AMBuilder diff --git a/dlls/ts/tsx/CMisc.cpp b/modules/ts/tsx/CMisc.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/CMisc.cpp rename to modules/ts/tsx/CMisc.cpp diff --git a/dlls/ts/tsx/CMisc.h b/modules/ts/tsx/CMisc.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/CMisc.h rename to modules/ts/tsx/CMisc.h diff --git a/dlls/ts/tsx/CRank.cpp b/modules/ts/tsx/CRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/CRank.cpp rename to modules/ts/tsx/CRank.cpp diff --git a/dlls/ts/tsx/CRank.h b/modules/ts/tsx/CRank.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/CRank.h rename to modules/ts/tsx/CRank.h diff --git a/dlls/ts/tsx/Makefile b/modules/ts/tsx/Makefile old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/Makefile rename to modules/ts/tsx/Makefile diff --git a/dlls/ts/tsx/NBase.cpp b/modules/ts/tsx/NBase.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/NBase.cpp rename to modules/ts/tsx/NBase.cpp diff --git a/dlls/ts/tsx/NRank.cpp b/modules/ts/tsx/NRank.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/NRank.cpp rename to modules/ts/tsx/NRank.cpp diff --git a/dlls/ts/tsx/Utils.cpp b/modules/ts/tsx/Utils.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/Utils.cpp rename to modules/ts/tsx/Utils.cpp diff --git a/dlls/ts/tsx/moduleconfig.cpp b/modules/ts/tsx/moduleconfig.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/moduleconfig.cpp rename to modules/ts/tsx/moduleconfig.cpp diff --git a/dlls/ts/tsx/moduleconfig.h b/modules/ts/tsx/moduleconfig.h similarity index 100% rename from dlls/ts/tsx/moduleconfig.h rename to modules/ts/tsx/moduleconfig.h diff --git a/dlls/ts/tsx/msvc12/tsx.sln b/modules/ts/tsx/msvc12/tsx.sln similarity index 100% rename from dlls/ts/tsx/msvc12/tsx.sln rename to modules/ts/tsx/msvc12/tsx.sln diff --git a/dlls/ts/tsx/msvc12/tsx.vcxproj b/modules/ts/tsx/msvc12/tsx.vcxproj similarity index 100% rename from dlls/ts/tsx/msvc12/tsx.vcxproj rename to modules/ts/tsx/msvc12/tsx.vcxproj diff --git a/dlls/ts/tsx/msvc12/tsx.vcxproj.filters b/modules/ts/tsx/msvc12/tsx.vcxproj.filters similarity index 100% rename from dlls/ts/tsx/msvc12/tsx.vcxproj.filters rename to modules/ts/tsx/msvc12/tsx.vcxproj.filters diff --git a/dlls/ts/tsx/tsx.h b/modules/ts/tsx/tsx.h old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/tsx.h rename to modules/ts/tsx/tsx.h diff --git a/dlls/ts/tsx/usermsg.cpp b/modules/ts/tsx/usermsg.cpp old mode 100755 new mode 100644 similarity index 100% rename from dlls/ts/tsx/usermsg.cpp rename to modules/ts/tsx/usermsg.cpp diff --git a/dlls/ts/tsx/version.rc b/modules/ts/tsx/version.rc similarity index 100% rename from dlls/ts/tsx/version.rc rename to modules/ts/tsx/version.rc