commit 86ba8ffca6a6399bb19861e1cd826ec792a33651 Author: Vinnie Falco Date: Wed Sep 11 09:57:14 2013 -0700 Squashed 'src/beast/' content from commit 43e6d34 git-subtree-dir: src/beast git-subtree-split: 43e6d345e498da258dcca6d23795a3cc0fd55d2b diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..8d9c7343dc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,12 @@ +# Set default behaviour, in case users don't have core.autocrlf set. +* text=auto + +# Github +.md text eol=lf + +# Visual Studio +*.sln text eol=crlf +*.vcproj text eol=crlf +*.vcxproj text eol=crlf +*.props text eol=crlf +*.filters text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..d5acdb6154 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +Docs +._* +*.mode1v3 +*.pbxuser +*.perspectivev3 +*.user +*.ncb +*.suo +*.obj +*.ilk +*.pch +*.pdb +*.dep +*.idb +*.manifest +*.manifest.res +*.o +*.d +*.sdf +xcuserdata +contents.xcworkspacedata +.DS_Store +.svn +profile +Builds/VisualStudio2012/Debug +Builds/VisualStudio2012/Release diff --git a/Builds/VisualStudio2012/Beast.props b/Builds/VisualStudio2012/Beast.props new file mode 100644 index 0000000000..2428672bea --- /dev/null +++ b/Builds/VisualStudio2012/Beast.props @@ -0,0 +1,16 @@ + + + + + + + + Level4 + _CRTDBG_MAP_ALLOC;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) + true + false + %(AdditionalIncludeDirectories) + + + + \ No newline at end of file diff --git a/Builds/VisualStudio2012/BeastConfig.h b/Builds/VisualStudio2012/BeastConfig.h new file mode 100644 index 0000000000..600c4d35a2 --- /dev/null +++ b/Builds/VisualStudio2012/BeastConfig.h @@ -0,0 +1,161 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_BEASTCONFIG_H_INCLUDED +#define BEAST_BEASTCONFIG_H_INCLUDED + +/** Configuration file for Beast. + This sets various configurable options for Beast. In order to compile you + must place a copy of this file in a location where your build environment + can find it, and then customize its contents to suit your needs. + @file BeastConfig.h +*/ + +//------------------------------------------------------------------------------ +// +// Diagnostics +// +//------------------------------------------------------------------------------ + +/** Config: BEAST_FORCE_DEBUG + Normally, BEAST_DEBUG is set to 1 or 0 based on compiler and project + settings, but if you define this value, you can override this to force it + to be true or false. +*/ +#ifndef BEAST_FORCE_DEBUG +//#define BEAST_FORCE_DEBUG 1 +#endif + +/** Config: BEAST_LOG_ASSERTIONS + If this flag is enabled, the the bassert and bassertfalse macros will always + use Logger::writeToLog() to write a message when an assertion happens. + Enabling it will also leave this turned on in release builds. When it's + disabled, however, the bassert and bassertfalse macros will not be compiled + in a release build. + @see bassert, bassertfalse, Logger +*/ +#ifndef BEAST_LOG_ASSERTIONS +//#define BEAST_LOG_ASSERTIONS 1 +#endif + +/** Config: BEAST_CHECK_MEMORY_LEAKS + Enables a memory-leak check for certain objects when the app terminates. + See the LeakChecked class for more details about enabling leak checking for + specific classes. +*/ +#ifndef BEAST_CHECK_MEMORY_LEAKS +//#define BEAST_CHECK_MEMORY_LEAKS 0 +#endif + +/** Config: BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES + Setting this option makes Socket-derived classes generate compile errors + if they forget any of the virtual overrides As some Socket-derived classes + intentionally omit member functions that are not applicable, this macro + should only be enabled temporarily when writing your own Socket-derived + class, to make sure that the function signatures match as expected. +*/ +#ifndef BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES +//#define BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES 1 +#endif + +/** Config: BEAST_CATCH_UNHANDLED_EXCEPTIONS + This will wrap thread entry points with an exception catching block. + A customizable hook is provided to get called when unhandled exceptions + are thrown. + @see ProtectedCall +*/ +#ifndef BEAST_CATCH_UNHANDLED_EXCEPTIONS +//#define BEAST_CATCH_UNHANDLED_EXCEPTIONS 1 +#endif + +//------------------------------------------------------------------------------ +// +// Libraries +// +//------------------------------------------------------------------------------ + +/** Config: BEAST_DISABLE_BEAST_VERSION_PRINTING + Turns off the debugging display of the beast version number +*/ +#ifndef BEAST_DISABLE_BEAST_VERSION_PRINTING +//#define BEAST_DISABLE_BEAST_VERSION_PRINTING 1 +#endif + +/** Config: BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES + In a Visual C++ build, this can be used to stop the required system libs + being automatically added to the link stage. +*/ +#ifndef BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES +//#define BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES 1 +#endif + +/** Config: BEAST_INCLUDE_ZLIB_CODE + This can be used to disable Beast's embedded 3rd-party zlib code. + You might need to tweak this if you're linking to an external zlib library + in your app, but for normal apps, this option should be left alone. + + If you disable this, you might also want to set a value for + BEAST_ZLIB_INCLUDE_PATH, to specify the path where your zlib headers live. +*/ +#ifndef BEAST_INCLUDE_ZLIB_CODE +//#define BEAST_INCLUDE_ZLIB_CODE 1 +#endif + +/** Config: BEAST_ZLIB_INCLUDE_PATH + This is included when BEAST_INCLUDE_ZLIB_CODE is set to zero. +*/ +#ifndef BEAST_ZLIB_INCLUDE_PATH +#define BEAST_ZLIB_INCLUDE_PATH +#endif + +/** Config: BEAST_FUNCTIONAL_USES_### + source configuration. + Set one of these to manually force a particular implementation of bind(). + If nothing is chosen then beast will use whatever is appropriate for your + environment based on what is available. + If you override these, set ONE to 1 and the rest to 0 +*/ +#ifndef BEAST_FUNCTIONAL_USES_STD +//#define BEAST_FUNCTIONAL_USES_STD 0 +#endif +#ifndef BEAST_FUNCTIONAL_USES_TR1 +//#define BEAST_FUNCTIONAL_USES_TR1 0 +#endif +#ifndef BEAST_FUNCTIONAL_USES_BOOST +//#define BEAST_FUNCTIONAL_USES_BOOST 0 +#endif + +//------------------------------------------------------------------------------ +// +// Boost +// +//------------------------------------------------------------------------------ + +/** Config: BEAST_USE_BOOST_FEATURES + This activates boost specific features and improvements. If this is + turned on, the include paths for your build environment must be set + correctly to find the boost headers. +*/ +#ifndef BEAST_USE_BOOST_FEATURES +//#define BEAST_USE_BOOST_FEATURES 1 +#endif + +//------------------------------------------------------------------------------ + +#endif diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj new file mode 100644 index 0000000000..422e763b14 --- /dev/null +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -0,0 +1,1464 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + true + true + true + true + + + + true + true + true + true + + + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + true + true + true + true + + + + + + + {73C5A0F0-7629-4DE7-9194-BE7AC6C19535} + Win32Proj + beast + + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + false + v110 + true + Unicode + + + StaticLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir);%(AdditionalIncludeDirectories) + + + Windows + true + + + + + + + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir);%(AdditionalIncludeDirectories) + + + Windows + true + + + + + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir);%(AdditionalIncludeDirectories) + + + Windows + true + true + true + + + + + + + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir);%(AdditionalIncludeDirectories) + + + Windows + true + true + true + + + + + + \ No newline at end of file diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters new file mode 100644 index 0000000000..a10f8600c3 --- /dev/null +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -0,0 +1,1550 @@ + + + + + + + beast_core + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\zip\zlib + + + beast_core\native\java + + + + + + + + {6dafd8d5-2901-4b41-85b7-52f6e86baacc} + + + {7cc041c8-fdf4-4e98-a56a-df516c2a9aa2} + + + {3b7d8d7e-eabc-423c-a631-2ff37bf9b9eb} + + + {abe24d69-c1d1-49e2-98a1-1e7bf760b97a} + + + {e2339099-bb8e-4437-ae8b-d4f64ef1e3f3} + + + {a89aa17e-4e01-4c2d-ba7e-196e9e0b67bb} + + + {64a314e1-0361-428a-a294-0615d8140f58} + + + {1d018a70-71b3-4d70-9280-02efd4f348de} + + + {ad675f57-9303-4712-9ff2-c7f59f959e7b} + + + {016d839c-4860-4bc3-8f6c-e965f50c2bfa} + + + {7fb77af6-ce16-4f53-823e-906963b42985} + + + {4603580c-5668-4e70-bed8-77f00f03f0ff} + + + {3409dc7a-92b5-43aa-b678-fde9f82ced55} + + + {d3ea4af5-ae48-4144-a2ef-a212342d72ee} + + + {a1a38659-7779-41d6-8a3c-068433c4deaf} + + + {df5f5a69-5919-4a24-bbce-b3f87e4903cf} + + + {b0d206d9-c002-4be1-b503-4ad16aca838a} + + + {31038502-9139-4c19-bd67-8f90f08a70ca} + + + {69e28551-92ea-420b-a465-75ed248e3b59} + + + {62b1f8e3-79e4-46cc-b3fb-a12754aef249} + + + {1170f2bc-2456-410a-ab2b-c45f6ed37b9e} + + + {4834218f-f13f-41bc-a8a0-50314a3a99a3} + + + {15a98fee-1b52-45eb-9480-514b8750d755} + + + {cbf5f5a3-5d66-4b6d-996d-20ed14b41793} + + + {acd9ab9d-3ba8-4c60-bfb8-36799d9d7a06} + + + {67b47aab-8e6a-4acd-9291-d95a8795d6ad} + + + {e666952d-d490-40a2-aa05-2d63ea23284f} + + + {3f969218-0a32-41f1-8e05-9a47247cf494} + + + {10ef778f-6b81-437e-a6ef-558ff4163acc} + + + {0fa6b76b-305f-473c-9b94-c1028a3af3fc} + + + {54bbe439-76c3-4781-becc-9c70a2be6d82} + + + {af535ad5-a06c-462f-8ac0-8207a708e032} + + + {c7a576bb-27b2-486e-aa14-3c51aa86c50f} + + + {422da6a1-e57e-4a96-9fce-e5958c16026e} + + + {ccdc0c8e-f77a-486e-ba2f-29c10ec97f18} + + + {beb81776-4aad-401d-8826-81478dbbf30b} + + + {493db217-b3e4-4b08-97b2-a2d753cc8c35} + + + {1b2e8962-c087-4453-8107-7077c2de5846} + + + {91538dcf-b219-4c80-9861-bb4949089775} + + + {5df65855-1ccd-4997-97c1-f9788924ee2b} + + + {2f5b95a8-1adf-4319-8464-ddc2b2e03f0b} + + + {bf498396-2e1f-4903-be68-3053ba439af5} + + + {08ec13ba-4058-4ad7-afbb-cbb1c6e2fc4a} + + + {92d1bb42-289a-4444-85c7-cb87540f2fff} + + + {8832eb52-53f9-4850-8dc9-1d579a386a0e} + + + {5904368f-a0f2-4d26-a031-8cbe4448dc3f} + + + {ac367054-ddbf-4118-a41a-07bea34d32c8} + + + {c0724499-ab69-40c3-90e2-65242dbd2eaa} + + + {f7252567-a5bb-4be2-bbd0-c9d9b62298de} + + + + + beast_core + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\json + + + beast_core\logging + + + beast_core\logging + + + beast_core\maths + + + beast_core\maths + + + beast_core\maths + + + beast_core\maths + + + beast_core\maths + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\misc + + + beast_core\misc + + + beast_core\misc + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\network + + + beast_core\network + + + beast_core\network + + + beast_core\network + + + beast_core\network + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\time + + + beast_core\time + + + beast_core\time + + + beast_core\xml + + + beast_core\xml + + + beast_core\zip + + + beast_core\zip + + + beast_core\zip + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\containers + + + beast_core\containers + + + beast_core\threads + + + beast_core\memory + + + beast_core\containers + + + beast_core\containers + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\memory + + + beast_core\memory + + + beast_core\maths + + + beast_core\time + + + beast_core\diagnostic + + + beast_crypto\math + + + beast_crypto + + + beast_core\containers + + + beast_core\files + + + beast_core\diagnostic + + + beast_core\memory + + + beast_db + + + beast_db\keyvalue + + + beast_sqlite + + + beast_sqlite\sqlite + + + beast_sqlite\sqlite + + + beast_sqdb + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_core\maths + + + beast_core\diagnostic + + + beast_core\misc + + + beast_core\text + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\maths + + + beast_core\memory + + + beast_core\memory + + + beast_core\diagnostic + + + beast_core\threads + + + beast_core\threads + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread\detail + + + beast_core\thread\detail + + + beast_core\thread\impl + + + beast_core\thread\impl + + + beast_core\thread\impl + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\maths + + + beast_core\functional + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_asio\sockets + + + beast_asio\basics + + + beast_asio + + + beast_asio\system + + + beast_extras\traits + + + beast_extras + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\system + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers\detail + + + beast_core\containers\detail + + + beast_core\text + + + beast_core\text + + + beast\intrusive + + + beast\intrusive + + + beast\mpl + + + beast\mpl + + + beast\mpl + + + beast\mpl + + + beast\mpl + + + beast + + + beast\mpl + + + beast_core\memory + + + beast_core\memory + + + beast_core\diagnostic + + + beast_asio\parsehttp + + + beast_asio\async + + + beast_asio\async + + + beast_asio\async + + + beast_asio\async + + + beast_asio\async + + + beast_asio\basics + + + beast_asio\basics + + + beast_asio\sockets + + + beast_asio\sockets + + + beast_asio\sockets + + + beast_asio\system + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\protocol + + + beast_asio\protocol + + + beast_asio\protocol + + + beast_asio\protocol + + + beast_asio\protocol + + + beast_asio\protocol + + + beast_asio\protocol + + + beast_core\functional + + + beast_asio\basics + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast\mpl + + + beast_asio\basics + + + beast_asio\basics + + + + + beast_core + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\files + + + beast_core\json + + + beast_core\logging + + + beast_core\logging + + + beast_core\maths + + + beast_core\maths + + + beast_core\maths + + + beast_core\memory + + + beast_core\misc + + + beast_core\misc + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\network + + + beast_core\network + + + beast_core\network + + + beast_core\network + + + beast_core\network + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\streams + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\text + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\threads + + + beast_core\time + + + beast_core\time + + + beast_core\time + + + beast_core\xml + + + beast_core\xml + + + beast_core\zip + + + beast_core\zip + + + beast_core\zip + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\zip\zlib + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\native + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_core\threads + + + beast_core\native + + + beast_core\native + + + beast_core\time + + + beast_core\diagnostic + + + beast_crypto + + + beast_crypto\math + + + beast_core\files + + + beast_core\diagnostic + + + beast_db + + + beast_db\keyvalue + + + beast_sqlite + + + beast_sqlite\sqlite + + + beast_sqdb + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_core\maths + + + beast_core\diagnostic + + + beast_core\misc + + + beast_core\text + + + beast_core\diagnostic + + + beast_core\diagnostic + + + beast_asio + + + beast_core\threads + + + beast_core\thread\impl + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\thread + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_core\memory + + + beast_asio\basics + + + beast_extras + + + beast_core\system + + + beast_core\system + + + beast_core\containers + + + beast_core\containers + + + beast_core\containers + + + beast_asio\parsehttp + + + beast_asio\async + + + beast_asio\basics + + + beast_asio\sockets + + + beast_asio\sockets + + + beast_asio\system + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\tests + + + beast_asio\protocol + + + beast_asio\basics + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + beast_asio\http + + + + + + \ No newline at end of file diff --git a/CodingStyle.md b/CodingStyle.md new file mode 100644 index 0000000000..92b35da4ef --- /dev/null +++ b/CodingStyle.md @@ -0,0 +1,228 @@ +Write code in a clear, self-documenting style but use comments where necessary. +Use Test Driven Development. It encourages designing interfaces first, before implementation. +Don't Repeat Yourself, “D.R.Y.”. Put redundant code in a class so it can be re-used and unit tested. +Expose as little of a class as possible. Prefer private over protected. Prefer protected over public. The smaller the interface footprint, the easier it is to write unit tests and comprehend the operation of the class. This is the Interface Segregation Principle. +Use language constants (enum or static const) with descriptive names instead of hard-coded “magic numbers.” +Make classes depend on as few external classes or routines as possible. Ideally, no dependencies. +Don't limit flexibility of parameters by forcing the caller to use specific types where general types would work. + +-------------------------------------------------------------------------------- + +# Coding Standards + +Coding standards used here are extreme strict and consistent. The style +evolved gradually over the years, incorporating generally acknowledged +best-practice C++ advice, experience, and personal preference. + +## Don't Repeat Yourself! + +The [Don't Repeat Yourself][1] principle summarises the essence of what it +means to write good code, in all languages, at all levels. + +## Formatting + +The goal of source code formatting should always be to make things as easy to +read as possible. White space is used to guide the eye so that details are not +overlooked. Blank lines are used to separate code into "paragraphs." + +* No tab characters please. +* Tab stops are set to 4 spaces. +* Braces are indented in the [Allman style][2]. +* Always place a space before and after all binary operators, + especially assignments (`operator=`). +* The `!` operator should always be followed by a space. +* The `~` operator should be preceded by a space, but not followed by one. +* The `++` and `--` operators should have no spaces between the operator and + the operand. +* A space never appears before a comma, and always appears after a comma. +* Always place a space before an opening parenthesis. One exception is if + the parentheses are empty. +* Don't put spaces after a parenthesis. A typical member function call might + look like this: `foobar (1, 2, 3);` +* In general, leave a blank line before an `if` statement. +* In general, leave a blank line after a closing brace `}`. +* Do not place code or comments on the same line as any opening or + closing brace. +* Do not write `if` statements all-on-one-line. The exception to this is when + you've got a sequence of similar `if` statements, and are aligning them all + vertically to highlight their similarities. +* In an `if-else` statement, if you surround one half of the statement with + braces, you also need to put braces around the other half, to match. +* When writing a pointer type, use this spacing: `SomeObject* myObject`. + Technically, a more correct spacing would be `SomeObject *myObject`, but + it makes more sense for the asterisk to be grouped with the type name, + since being a pointer is part of the type, not the variable name. The only + time that this can lead to any problems is when you're declaring multiple + pointers of the same type in the same statement - which leads on to the next + rule: +* When declaring multiple pointers, never do so in a single statement, e.g. + `SomeObject* p1, *p2;` - instead, always split them out onto separate lines + and write the type name again, to make it quite clear what's going on, and + avoid the danger of missing out any vital asterisks. +* The previous point also applies to references, so always put the `&` next to + the type rather than the variable, e.g. `void foo (Thing const& thing)`. And + don't put a space on both sides of the `*` or `&` - always put a space after + it, but never before it. +* The word `const` should be placed to the right of the thing that it modifies, + for consistency. For example `int const` refers to an int which is const. + `int const*` is a pointer to an int which is const. `int *const` is a const + pointer to an int. +* Always place a space in between the template angle brackets and the type + name. Template code is already hard enough to read! + +## Naming conventions + +* Member variables and method names are written with camel-case, and never + begin with a capital letter. +* Class names are also written in camel-case, but always begin with a capital + letter. +* For global variables... well, you shouldn't have any, so it doesn't matter. +* Class data members begin with `m_`, static data members begin with `s_`. + Global variables begin with `g_`. This is so the scope of the corresponding + declaration can be easily determined. +* Avoid underscores in your names, especially leading or trailing underscores. + In particular, leading underscores should be avoided, as these are often used + in standard library code, so to use them in your own code looks quite jarring. +* If you really have to write a macro for some reason, then make it all caps, + with underscores to separate the words. And obviously make sure that its name + is unlikely to clash with symbols used in other libraries or 3rd party code. + +## Types, const-correctness + +* If a method can (and should!) be const, make it const! +* If a method definitely doesn't throw an exception (be careful!), mark it as + `noexcept` +* When returning a temporary object, e.g. a String, the returned object should + be non-const, so that if the class has a C++11 move operator, it can be used. +* If a local variable can be const, then make it const! +* Remember that pointers can be const as well as primitives; For example, if + you have a `char*` whose contents are going to be altered, you may still be + able to make the pointer itself const, e.g. `char* const foobar = getFoobar();`. +* Do not declare all your local variables at the top of a function or method + (i.e. in the old-fashioned C-style). Declare them at the last possible moment, + and give them as small a scope as possible. +* Object parameters should be passed as `const&` wherever possible. Only + pass a parameter as a copy-by-value object if you really need to mutate + a local copy inside the method, and if making a local copy inside the method + would be difficult. +* Use portable `for()` loop variable scoping (i.e. do not have multiple for + loops in the same scope that each re-declare the same variable name, as + this fails on older compilers) +* When you're testing a pointer to see if it's null, never write + `if (myPointer)`. Always avoid that implicit cast-to-bool by writing it more + fully: `if (myPointer != nullptr)`. And likewise, never ever write + `if (! myPointer)`, instead always write `if (myPointer == nullptr)`. + It is more readable that way. +* Avoid C-style casts except when converting between primitive numeric types. + Some people would say "avoid C-style casts altogether", but `static_cast` is + a bit unreadable when you just want to cast an `int` to a `float`. But + whenever a pointer is involved, or a non-primitive object, always use + `static_cast`. And when you're reinterpreting data, always use + `reinterpret_cast`. +* Until C++ gets a universal 64-bit primitive type (part of the C++11 + standard), it's best to stick to the `int64` and `uint64` typedefs. + +## Object lifetime and ownership + +* Absolutely do NOT use `delete`, `deleteAndZero`, etc. There are very very few + situations where you can't use a `ScopedPointer` or some other automatic + lifetime management class. +* Do not use `new` unless there's no alternative. Whenever you type `new`, always + treat it as a failure to find a better solution. If a local variable can be + allocated on the stack rather than the heap, then always do so. +* Do not ever use `new` or `malloc` to allocate a C++ array. Always use a + `HeapBlock` instead. +* And just to make it doubly clear: Never use `malloc` or `calloc`. +* If a parent object needs to create and own some kind of child object, always + use composition as your first choice. If that's not possible (e.g. if the + child needs a pointer to the parent for its constructor), then use a + `ScopedPointer`. +* If possible, pass an object as a reference rather than a pointer. If possible, + make it a `const` reference. +* Obviously avoid static and global values. Sometimes there's no alternative, + but if there is an alternative, then use it, no matter how much effort it + involves. +* If allocating a local POD structure (e.g. an operating-system structure in + native code), and you need to initialise it with zeros, use the `= { 0 };` + syntax as your first choice for doing this. If for some reason that's not + appropriate, use the `zerostruct()` function, or in case that isn't suitable, + use `zeromem()`. Don't use `memset()`. + +## Classes + +* Declare a class's public section first, and put its constructors and + destructor first. Any protected items come next, and then private ones. +* Use the most restrictive access-specifier possible for each member. Prefer + `private` over `protected`, and `protected` over `public`. Don't expose + things unnecessarily. +* Preferred positioning for any inherited classes is to put them to the right + of the class name, vertically aligned, e.g.: + class Thing : public Foo, + private Bar + { + } +* Put a class's member variables (which should almost always be private, of course), + after all the public and protected method declarations. +* Any private methods can go towards the end of the class, after the member + variables. +* If your class does not have copy-by-value semantics, derive the class from + `Uncopyable`. +* If your class is likely to be leaked, then derive your class from + `LeakChecked<>`. +* Constructors that take a single parameter should be default be marked + `explicit`. Obviously there are cases where you do want implicit conversion, + but always think about it carefully before writing a non-explicit constructor. +* Do not use `NULL`, `null`, or 0 for a null-pointer. And especially never use + '0L', which is particulary burdensome. Use `nullptr` instead - this is the + C++2011 standard, so get used to it. There's a fallback definition for `nullptr` + in Beast, so it's always possible to use it even if your compiler isn't yet + C++2011 compliant. +* All the C++ 'guru' books and articles are full of excellent and detailed advice + on when it's best to use inheritance vs composition. If you're not already + familiar with the received wisdom in these matters, then do some reading! + +## Miscellaneous + +* Constrain the scope of identifiers to the smallest area that needs it. Consider + using nested classes or classes inside functions, if doing so will expose less + interface and implementation overall. +* `goto` statements should not be used at all, even if the alternative is + more verbose code. The only exception is when implementing an algorithm in + a function as a state machine. +* Don't use macros! OK, obviously there are many situations where they're the + right tool for the job, but treat them as a last resort. Certainly don't ever + use a macro just to hold a constant value or to perform any kind of function + that could have been done as a real inline function. And it goes without saying + that you should give them names which aren't going to clash with other code. + And `#undef` them after you've used them, if possible. +* When using the `++` or `--` operators, never use post-increment if + pre-increment could be used instead. Although it doesn't matter for + primitive types, it's good practice to pre-increment since this can be + much more efficient for more complex objects. In particular, if you're + writing a for loop, always use pre-increment, + e.g. `for (int = 0; i < 10; ++i)` +* Never put an "else" statement after a "return"! This is well-explained in the + LLVM coding standards...and a couple of other very good pieces of advice from + the LLVM standards are in there as well. +* When getting a possibly-null pointer and using it only if it's non-null, limit + the scope of the pointer as much as possible - e.g. Do NOT do this: + + Foo* f = getFoo (); + if (f != nullptr) + f->doSomething (); + // other code + f->doSomething (); // oops! f may be null! + + ..instead, prefer to write it like this, which reduces the scope of the + pointer, making it impossible to write code that accidentally uses a null + pointer: + + if (Foo* f = getFoo ()) + f->doSomethingElse (); + + // f is out-of-scope here, so impossible to use it if it's null + + (This also results in smaller, cleaner code) + +[1]: http://en.wikipedia.org/wiki/Don%27t_repeat_yourself +[2]: http://en.wikipedia.org/wiki/Indent_style#Allman_style diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000000..869f9dd0e5 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,302 @@ +# Doxyfile 1.8.3.1 + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "Beast" +PROJECT_NUMBER = +PROJECT_BRIEF = +PROJECT_LOGO = +OUTPUT_DIRECTORY = Docs +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 4 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +AUTOLINK_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +SYMBOL_CACHE_SIZE = 0 +LOOKUP_CACHE_SIZE = 0 +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = modules +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = +RECURSIVE = YES +EXCLUDE = modules/beast_core/beast_core.h \ + modules/beast_core/beast_core.cpp \ + modules/beast_basics/beast_basics.cpp \ + modules/beast_basics/native \ + modules/beast_basics/zip/zlib +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +USE_MDFILE_AS_MAINPAGE = +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = . +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_EXTRA_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = YES +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_FORMAT = HTML-CSS +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +SEARCHENGINE = YES +SERVER_BASED_SEARCH = NO +EXTERNAL_SEARCH = NO +SEARCHENGINE_URL = +SEARCHDATA_FILE = searchdata.xml +EXTERNAL_SEARCH_ID = +EXTRA_SEARCH_MAPPINGS = +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4 +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +DOT_NUM_THREADS = 0 +DOT_FONTNAME = Helvetica +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES + diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000000..81be44cd33 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,31 @@ +# Beast: An amazing cross platform library + +Contains cross platform objects to do a variety of useful things. +No external dependencies, no complicated build steps. + +Things people need for building peer to peer, concurrent, cryptographic systems. + +The hope is that this will replace the use of boost and other cumbersome jalopies. + +## JUCE + +Parts of Beast are based on the juce_core module which is provided under the ISC +license. More information about JUCE is available at + +http://www.juce.com + +## License + +Beast is provided under the terms of the ISC license: + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000000..bf1437e8e0 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,87 @@ +-------------------------------------------------------------------------------- +BEAST TODO +-------------------------------------------------------------------------------- + +- Use new file naming convention + +- Rename ReadWriteMutex to SharedMutex + +- Use SemanticVersion for beast version numbers to replace BEAST_VERSION + +- add support for a __PRETTY_FUNCTION__ equivalent for all environments + +- add expectThrow() to UnitTest, where it expects an exception + +- Import secp256k1 from sipa + +- HashMap work: + - Add unit test + - Return size_t from hash function, take out upperLimit, move mod % to caller + - Make hash function a functor using operator() + - Implement HardenedHashFunctions + - Fix problem with assigning to the result of operator[] maybe use a proxy? + +- Set sqlite thread safety model to '2' in beast_sqlite + +- Document and rename all the sqdb files and classes + +- Specialize UnsignedInteger<> for peformance in the storage format + +- Rename HeapBlock routines to not conflict with _CRTDBG_MAP_ALLOC macros + +- Design a WeakPtr / SharedPtr / SharedObject intrusive system + +- Implement beast::Bimap? + +- Use Bimap for storage in the DeadlineTimer::Manager, to support + thousands of timers. + +- Think about adding a shouldStop bool to InterruptibleThread, along + with a shouldStop () function returning bool, and a stop() method. + +- Make OwnedArray add routines return a pointer instead of reference + +- Tidy up CacheLine, MemoryAlignment + +- Remove anything having to do with DLL builds like + BEAST_DLL, BEAST_DLL_BUILD, BEAST_DISABLE_DLL_ALLOCATORS + +- Fix FifoFreeStoreWithTLS reference counting bug + +- Implement a reasonable substitute for boost's thread_local_storage + +- Think about doing away with BEAST_CALLTYPE and BEAST_API + +- Decide if headers should just include BeastConfig.h instead of making the + host program do it. + +- Rename malloc/calloc JUCE members that conflict with the debug CRT from MSVC + +- Make beast::HashMap support assignment via operator[] + +- Reformat every Doxygen comment +- Fix Doxygen metatags +- update Beast Doxyfile + +- Rename include guards to boost style, e.g. BEAST_THROW_H_INCLUDED + +- Decide if we should get rid of AtomicCounter, AtomicFlag, AtomicPointer, AtomicState + +- Clean up CacheLine, StaticObject + +- Clean up ConcurrentObject + +- Rename SharedData to SharedState or something? + +- Figure out what to do with ReadWriteLock, and NamedPipe which uses it? + +- Put BEAST_PUBLIC_FUNCTION in front of all loose functions + +- restructure the repo sources to look like this: + /Source/beast/beast_core/beast_core.h + etc... +- Put the BeastConfig.h at the root of the repo. +- Make sure the template BeastConfig.h is included in the Doxyfile + +- Implement robust key/value database with bulk write + diff --git a/beast/intrusive/ForwardList.h b/beast/intrusive/ForwardList.h new file mode 100644 index 0000000000..2a88225b97 --- /dev/null +++ b/beast/intrusive/ForwardList.h @@ -0,0 +1,445 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_INTRUSIVE_FORWARDLIST_H_INCLUDED +#define BEAST_INTRUSIVE_FORWARDLIST_H_INCLUDED + +#include + +#include "PointerTraits.h" +#include "../mpl.h" + +// Ideas based on boost + +namespace beast { +namespace intrusive { + +//------------------------------------------------------------------------------ + +namespace detail { + +// Holds the size field +struct SizeHolder +{ +public: + typedef std::size_t size_type; + + inline size_type size () const noexcept + { + return m_size; + } + + inline void set (size_type new_size) noexcept + { + m_size = new_size; + } + + inline void increment () noexcept + { + ++m_size; + } + + inline void decrement () noexcept + { + --m_size; + } + +private: + size_type m_size; +}; + +} + +//------------------------------------------------------------------------------ + +template +struct ForwardListNode +{ + typedef typename PointerTraits ::template rebind_pointer ::type node_ptr; + + node_ptr next; +}; + +//------------------------------------------------------------------------------ + +// Provides value_traits for when T derives from Node +template +struct DerivedValueTraits +{ + typedef NodeTraits node_traits; + typedef T value_type; + typedef typename node_traits::node node; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::const_node_ptr const_node_ptr; + typedef typename mpl::PointerToOther ::type pointer; + typedef typename mpl::PointerToOther ::type const_pointer; + typedef typename PointerTraits ::reference reference; + typedef typename PointerTraits ::reference const_reference; + + static node_ptr to_node_ptr (reference value) + { + return node_ptr (&value); + } + + static const_node_ptr to_node_ptr (const_reference value) + { + return node_ptr (&value); + } + + static pointer to_value_ptr (node_ptr const& n) + { + return pointer (&static_cast (*n)); + } + + static const_pointer to_value_ptr (const_node_ptr const &n) + { + return const_pointer (&static_cast (*n)); + } +}; + +//------------------------------------------------------------------------------ + +template +struct ForwardListNodeTraits +{ + typedef ForwardListNode node; + + typedef typename PointerTraits :: + template rebind_pointer node_ptr; + + typedef typename PointerTraits :: + template rebind_pointer const_node_ptr; + + static node_ptr get_next (const_node_ptr const& n) + { + return n->m_next; + } + + static node_ptr get_next (node_ptr const& n) + { + return n->m_next; + } + + static void set_next (node_ptr const& n, node_ptr const& next) + { + n->m_next = next; + } +}; + +//------------------------------------------------------------------------------ + +template +class ForwardListIterator + : public std::iterator < + std::forward_iterator_tag, + typename Container::value_type, + typename Container::difference_type, + typename mpl::IfCond ::type, + typename mpl::IfCond ::type> +{ +protected: + typedef typename Container::value_traits value_traits; + typedef typename Container::node_traits node_traits; + typedef typename node_traits::node node; + typedef typename node_traits::node_ptr node_ptr; + typedef typename PointerTraits :: + template rebind_pointer ::type void_pointer; + +public: + typedef typename Container::value_type value_type; + typedef typename mpl::IfCond ::type pointer; + typedef typename mpl::IfCond ::type reference; + + ForwardListIterator () + : m_node () + { + } + + explicit ForwardListIterator (ForwardListIterator const& other) + : m_node (other.pointed_node ()) + { + } + + node_ptr const& pointed_node () const noexcept + { + return m_node; + } + + ForwardListIterator& operator= (node_ptr const& node) + { + m_node = node; + return static_cast (*this); + } + + ForwardListIterator& operator++ () + { + m_node = node_traits::get_next (m_node); + return static_cast (*this); + } + + ForwardListIterator operator++ (int) + { + ForwardListIterator result (*this); + m_node = node_traits::get_next (m_node); + return result; + } + + friend bool operator== (ForwardListIterator const& lhs, + ForwardListIterator const& rhs) + { + return lhs.m_node == rhs.m_node; + } + + friend bool operator!= (ForwardListIterator const& lhs, + ForwardListIterator const& rhs) + { + return ! (lhs == rhs); + } + + reference operator* () const + { + return *this->operator-> (); + } + + pointer operator-> () const + { + return value_traits::to_value_ptr (m_node); + } + +private: + node_ptr m_node; +}; + +//------------------------------------------------------------------------------ + +template +class ForwardListAlgorithms +{ +public: + typedef typename NodeTraits::node node; + typedef typename NodeTraits::node_ptr node_ptr; + typedef typename NodeTraits::const_node_ptr const_node_ptr; + typedef NodeTraits node_traits; + + static void init (node_ptr const& n) + { + NodeTraits::set_next (n, node_ptr()); + } + + static bool unique (const_node_ptr const& this_node) + { + node_ptr next = NodeTraits::get_next (this_node); + return !next || next == this_node; + } + + static void link_after (node_ptr const& prev_node, node_ptr const& this_node) + { + NodeTraits::set_next (this_node, NodeTraits::get_next (prev_node)); + NodeTraits::set_next (prev_node, this_node); + } + + static void unlink_after (node_ptr const& prev_node) + { + const_node_ptr this_node (NodeTraits::get_next (prev_node)); + NodeTraits::set_next (prev_node, NodeTraits::get_next (this_node)); + } +}; + +//------------------------------------------------------------------------------ + +/** Singly-linked intrusive list. */ +template +class ForwardList +{ +public: + typedef DerivedValueTraits > + value_traits; + typedef typename value_traits::pointer pointer; + typedef typename value_traits::const_pointer const_pointer; + typedef typename PointerTraits ::element_type value_type; + typedef typename PointerTraits ::reference reference; + typedef typename PointerTraits ::const_reference const_reference; + typedef typename PointerTraits ::difference_type difference_type; + typedef std::size_t size_type; + typedef ForwardListIterator iterator; + typedef ForwardListIterator const_iterator; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::node node; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::const_node_ptr const_node_ptr; + typedef ForwardListAlgorithms node_algorithms; + + typedef node Node; + +private: + typedef detail::SizeHolder size_traits; + + void default_construct () + { + get_size_traits ().set (size_type (0)); + node_algorithms::init (this->get_root_node ()); + } + + node_ptr get_end_node () + { + return node_ptr (); + } + + const_node_ptr get_end_node () const + { + return const_node_ptr (); + } + + node_ptr get_root_node () + { + return PointerTraits ::pointer_to (m_root); + } + + const_node_ptr get_root_node () const + { + return PointerTraits ::pointer_to (m_root); + } + + size_traits& get_size_traits () noexcept + { + return m_size; + } + + size_traits const& get_size_traits () const noexcept + { + return m_size; + } + + static node_ptr uncast (const_node_ptr const& ptr) + { + return PointerTraits ::const_cast_from (ptr); + } + +public: + ForwardList () + { + default_construct (); + } + + void clear () + { + default_construct (); + } + + void push_front (reference value) + { + node_ptr this_node (value_traits::to_node_ptr (value)); + node_algorithms::link_after (this->get_root_node (), this_node); + this->get_size_traits ().increment (); + } + + void pop_front () + { + //node_ptr this_node (node_traits::get_next (this->get_root ())); + node_algorithms::unlink_after (this->get_root_node ()); + this->get_size_traits ().decrement (); + } + + reference front () + { + return *value_traits::to_value_ptr (node_traits::get_next (this->get_root_node ())); + } + + const_reference front () const + { + return *value_traits::to_value_ptr (uncat (node_traits::get_next (this->get_root_node ()))); + } + + iterator begin () + { + return iterator (node_traits::get_next (this->get_root_node (), this)); + } + + const_iterator begin () const + { + return const_iterator (node_traits::get_next (this->get_root_node (), this)); + } + + const_iterator cbegin () const + { + return this->begin (); + } + + iterator end () + { + return iterator (this->get_end_node (), this); + } + + const_iterator end () const + { + return const_iterator (this->get_end_node (), this); + } + + const_iterator cend () const + { + return this->end (); + } + + iterator before_begin () + { + return iterator (this->get_root_node (), this); + } + + const_iterator before_begin () const + { + return const_iterator (this->get_root_node (), this); + } + + const_iterator cbefore_begin () const + { + return before_begin (); + } + + bool empty () const + { + return node_algorithms::unique (this->get_root_node ()); + } + + iterator iterator_to (reference value) + { + return iterator (value_traits::to_node_ptr (value), this); + } + + const_iterator iterator_to (const_reference value) const + { + return const_iterator (value_traits::to_node_ptr (const_cast (value)), this); + } + +private: + node m_root; + size_traits m_size; +}; + +} +} + +#endif diff --git a/beast/intrusive/PointerTraits.h b/beast/intrusive/PointerTraits.h new file mode 100644 index 0000000000..e4e733e38b --- /dev/null +++ b/beast/intrusive/PointerTraits.h @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_INTRUSIVE_POINTERTRAITS_H_INCLUDED +#define BEAST_INTRUSIVE_POINTERTRAITS_H_INCLUDED + +namespace beast { +namespace intrusive { + +// an unspecialized PointerTraits is ill-defined +template +struct PointerTraits; + +// specializations to remove cv-qualifiers +template +struct PointerTraits

: PointerTraits

{ }; +template +struct PointerTraits

: PointerTraits

{ }; +template +struct PointerTraits

: PointerTraits

{ }; +// specialization to remove a reference attribute +template +struct PointerTraits : PointerTraits

{ }; + +// specialization for raw pointers +template +struct PointerTraits +{ + typedef T element_type; + typedef T* pointer; + typedef T& reference; + typedef std::ptrdiff_t difference_type; + + template + struct rebind_pointer + { + typedef U* type; + }; + + static pointer pointer_to (reference r) + { + return static_cast ( + static_cast ( + const_cast ( + &reinterpret_cast ( + r)))); + } + + template + static pointer static_cast_from (U* u) + { + return static_cast (u); + } + + template + static pointer const_cast_from (U* u) + { + return const_cast (u); + } + + template + static pointer dynamic_cast_from (U* u) + { + return dynamic_cast (u); + } +}; + +} +} + +#endif diff --git a/beast/mpl.h b/beast/mpl.h new file mode 100644 index 0000000000..051931e688 --- /dev/null +++ b/beast/mpl.h @@ -0,0 +1,31 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_H_INCLUDED +#define BEAST_MPL_H_INCLUDED + +#include "mpl/AddConst.h" +#include "mpl/IfCond.h" +#include "mpl/PointerToOther.h" +#include "mpl/RemoveConst.h" +#include "mpl/RemoveConstVolatile.h" +#include "mpl/RemoveReference.h" +#include "mpl/RemoveVolatile.h" + +#endif diff --git a/beast/mpl/AddConst.h b/beast/mpl/AddConst.h new file mode 100644 index 0000000000..4b25ecd0bd --- /dev/null +++ b/beast/mpl/AddConst.h @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_ADDCONST_H_INCLUDED +#define BEAST_MPL_ADDCONST_H_INCLUDED + +// Ideas based on boost + +namespace beast { +namespace mpl { + +/// Add the `const` qualifier to a type. +template +struct AddConst +{ + typedef T const type; +}; + +} +} + +#endif diff --git a/beast/mpl/IfCond.h b/beast/mpl/IfCond.h new file mode 100644 index 0000000000..499dfced76 --- /dev/null +++ b/beast/mpl/IfCond.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_IFCOND_H_INCLUDED +#define BEAST_MPL_IFCOND_H_INCLUDED + +namespace beast { +namespace mpl { + +// Ideas based on boost + +/// Select between T1 or T2 depending on Condition. +/// @{ +template +struct IfCond +{ + typedef T1 type; +}; + +template +struct IfCond +{ + typedef T2 type; +}; +/// @} + +} +} + +#endif diff --git a/beast/mpl/PointerToOther.h b/beast/mpl/PointerToOther.h new file mode 100644 index 0000000000..868d46bb0f --- /dev/null +++ b/beast/mpl/PointerToOther.h @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_POINTERTOOTHERH_INCLUDED +#define BEAST_MPL_POINTERTOOTHERH_INCLUDED + +namespace beast { +namespace mpl { + +// Ideas based on boost + +/** Declares a type which is a pointer or smart pointer to U, depending on T. + This works for smart pointer containers with up to three template + parameters. More specializations can be added for containers with + more than three template parameters. +*/ +/// @{ +template +struct PointerToOther; + +template class SmartPointer> +struct PointerToOther , U> +{ + typedef SmartPointer type; +}; + +template class SmartPointer> +struct PointerToOther , U> +{ + typedef SmartPointer type; +}; + +template class SmartPointer> +struct PointerToOther , U> +{ + typedef SmartPointer type; +}; + +template +struct PointerToOther +{ + typedef U* type; +}; +/// @} + +} +} + +#endif diff --git a/beast/mpl/RemoveConst.h b/beast/mpl/RemoveConst.h new file mode 100644 index 0000000000..4f555f26a8 --- /dev/null +++ b/beast/mpl/RemoveConst.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_REMOVECONST_H_INCLUDED +#define BEAST_MPL_REMOVECONST_H_INCLUDED + +// Ideas based on boost + +namespace beast { +namespace mpl { + +/// Remove the `const` qualifier from a type. +/// @{ +template +struct RemoveConst +{ + typedef T type; +}; + +template +struct RemoveConst +{ + typedef T type; +}; +/// @} + +} +} + +#endif diff --git a/beast/mpl/RemoveConstVolatile.h b/beast/mpl/RemoveConstVolatile.h new file mode 100644 index 0000000000..361f0255ac --- /dev/null +++ b/beast/mpl/RemoveConstVolatile.h @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_REMOVECONSTVOLATILE_H_INCLUDED +#define BEAST_MPL_REMOVECONSTVOLATILE_H_INCLUDED + +#include "RemoveConst.h" +#include "RemoveVolatile.h" + +// Ideas based on boost + +namespace beast { +namespace mpl { + +/// Remove both the `const` and `volatile` qualifiers from a type. +template +struct RemoveConstVolatile +{ + typedef typename RemoveConst < + typename RemoveVolatile ::type + >::type type; +}; + +} +} + +#endif diff --git a/beast/mpl/RemoveReference.h b/beast/mpl/RemoveReference.h new file mode 100644 index 0000000000..239addcca7 --- /dev/null +++ b/beast/mpl/RemoveReference.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_REMOVEREFERENCE_H_INCLUDED +#define BEAST_MPL_REMOVEREFERENCE_H_INCLUDED + +namespace beast { +namespace mpl { + +// Ideas based on boost + +/// Remove the reference qualifier from a type. +/// @{ +template +struct RemoveReference +{ + typedef T type; +}; + +template +struct RemoveReference +{ + typedef T type; +}; +/// @} + +} +} + +#endif diff --git a/beast/mpl/RemoveVolatile.h b/beast/mpl/RemoveVolatile.h new file mode 100644 index 0000000000..26a848724e --- /dev/null +++ b/beast/mpl/RemoveVolatile.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_MPL_REMOVEVOLATILE_H_INCLUDED +#define BEAST_MPL_REMOVEVOLATILE_H_INCLUDED + +// Ideas based on boost + +namespace beast { +namespace mpl { + +/// Remove the `volatile` qualifier from a type. +/// @{ +template +struct RemoveVolatile +{ + typedef T type; +}; + +template +struct RemoveVolatile +{ + typedef T type; +}; +/// @} + +} +} + +#endif diff --git a/modules/beast_asio/async/ComposedAsyncOperation.h b/modules/beast_asio/async/ComposedAsyncOperation.h new file mode 100644 index 0000000000..54fffe055f --- /dev/null +++ b/modules/beast_asio/async/ComposedAsyncOperation.h @@ -0,0 +1,100 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_ASYNC_COMPOSEDASYNCOPERATION_H_INCLUDED +#define BEAST_ASIO_ASYNC_COMPOSEDASYNCOPERATION_H_INCLUDED + +/** Base class for creating composed asynchronous operations. + The composed operation will have its operator() overloads called with + the same context and execution safety guarantees as the original + SharedHandler. +*/ +class ComposedAsyncOperation : public SharedHandler +{ +protected: + /** Construct the composed operation. + The composed operation will execute in the context of the + SharedHandler. A reference to the SharedHandler is maintained + for the lifetime of the composed operation. + */ + ComposedAsyncOperation (std::size_t size, SharedHandlerPtr const& ptr) + : m_size (size) + , m_ptr (ptr) + { + // Illegal to do anything with handler here, because + // usually it hasn't been assigned by the derived class yet. + } + + ~ComposedAsyncOperation () + { + } + + void invoke (invoked_type& invoked) + { + boost_asio_handler_invoke_helpers:: + invoke (invoked, *m_ptr); + } + + void* allocate (std::size_t size) + { + return boost_asio_handler_alloc_helpers:: + allocate (size, *m_ptr); + } + + void deallocate (void* p, std::size_t size) + { + boost_asio_handler_alloc_helpers:: + deallocate (p, size, *m_ptr); + } + + /** Override this function as needed. + Usually you will logical-and your own continuation condition. In + the following example, isContinuing is a derived class member: + + @code + + bool derived::is_continuation () + { + bool const ourResult = this->isContinuing () + return ourResult || ComposedAsyncOperation ::is_contiation (); + } + + @endcode + */ + bool is_continuation () + { +#if BEAST_ASIO_HAS_CONTINUATION_HOOKS + return boost_asio_handler_cont_helpers:: + is_continuation (*m_ptr); +#else + return false; +#endif + } + + void destroy () + { + delete this; + } + +private: + std::size_t const m_size; + SharedHandlerPtr const m_ptr; +}; + +#endif diff --git a/modules/beast_asio/async/SharedHandler.cpp b/modules/beast_asio/async/SharedHandler.cpp new file mode 100644 index 0000000000..cf4cea5ca7 --- /dev/null +++ b/modules/beast_asio/async/SharedHandler.cpp @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +void SharedHandler::operator() () +{ + pure_virtual_called (__FILE__, __LINE__); +} + +void SharedHandler::operator() (error_code const&) +{ + pure_virtual_called (__FILE__, __LINE__); +} + +void SharedHandler::operator() (error_code const&, std::size_t) +{ + pure_virtual_called (__FILE__, __LINE__); +} + +void SharedHandler::pure_virtual_called (char const* fileName, int lineNumber) +{ + // These shouldn't be getting called. But since the object returned + // by most implementations of bind have operator() up to high arity + // levels, it is not generally possible to write a traits test that + // works in all scenarios for detecting a particular signature of a + // handler. + // + // We use Throw here so beast has a chance to dump the stack BEFORE + // the stack is unwound. + // + Throw (std::runtime_error ("pure virtual called"), fileName, lineNumber); +} diff --git a/modules/beast_asio/async/SharedHandler.h b/modules/beast_asio/async/SharedHandler.h new file mode 100644 index 0000000000..cd6543c9f0 --- /dev/null +++ b/modules/beast_asio/async/SharedHandler.h @@ -0,0 +1,121 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_ASYNC_SHAREDHANDLER_H_INCLUDED +#define BEAST_ASIO_ASYNC_SHAREDHANDLER_H_INCLUDED + +template +struct SharedHandlerAllocator; + +/** Reference counted wrapper that can hold any other boost::asio handler. + + This object will match these signatures: + + @code + + void (void) + void (system::error_code) + void (system::error_code, std::size_t) + + @endcode + + If the underlying implementation does not support the signature, + undefined behavior will result. + + Supports these concepts: + Destructible +*/ +class SharedHandler : public SharedObject +{ +protected: + typedef boost::system::error_code error_code; +#if 0 + typedef boost::function invoked_type; +#else + typedef SharedFunction > invoked_type; +#endif + + SharedHandler () noexcept { } + +public: + // For asio::async_result<> + typedef void result_type; + + typedef SharedPtr Ptr; + + virtual void operator() (); + virtual void operator() (error_code const&); + virtual void operator() (error_code const&, std::size_t); + + template + void invoke (BOOST_ASIO_MOVE_ARG(Function) f) +#if 0 + ; +#else + { + // The allocator will hold a reference to the SharedHandler + // so that we can safely destroy the function object. + invoked_type invoked (f, + SharedHandlerAllocator (this)); + invoke (invoked); + } +#endif + + virtual void invoke (invoked_type& invoked) = 0; + virtual void* allocate (std::size_t size) = 0; + virtual void deallocate (void* p, std::size_t size) = 0; + virtual bool is_continuation () = 0; + + static void pure_virtual_called (char const* fileName, int lineNumber); + +private: + template + friend void asio_handler_invoke (BOOST_ASIO_MOVE_ARG(Function) f, SharedHandler*); + friend void* asio_handler_allocate (std::size_t, SharedHandler*); + friend void asio_handler_deallocate (void*, std::size_t, SharedHandler*); + friend bool asio_handler_is_continuation (SharedHandler*); +}; + +//-------------------------------------------------------------------------- +// +// Context execution guarantees +// + +template +void asio_handler_invoke (BOOST_ASIO_MOVE_ARG(Function) f, SharedHandler* handler) +{ + handler->invoke (BOOST_ASIO_MOVE_CAST(Function)(f)); +} + +inline void* asio_handler_allocate (std::size_t size, SharedHandler* handler) +{ + return handler->allocate (size); +} + +inline void asio_handler_deallocate (void* p, std::size_t size, SharedHandler* handler) +{ + handler->deallocate (p, size); +} + +inline bool asio_handler_is_continuation (SharedHandler* handler) +{ + return handler->is_continuation (); +} + +#endif diff --git a/modules/beast_asio/async/SharedHandlerAllocator.h b/modules/beast_asio/async/SharedHandlerAllocator.h new file mode 100644 index 0000000000..86d894e951 --- /dev/null +++ b/modules/beast_asio/async/SharedHandlerAllocator.h @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_ASYNC_SHAREDHANDLERALLOCATOR_H_INCLUDED +#define BEAST_ASIO_ASYNC_SHAREDHANDLERALLOCATOR_H_INCLUDED + +/** Custom Allocator using the allocation hooks from the Handler. + + This class is compatible with std::allocator and can be used in any + boost interface which takes a template parameter of type Allocator. + This includes boost::function and especially boost::asio::streambuf + and relatives. This is vastly more efficient in a variety of situations + especially during an upcall and when using stackful coroutines. + + The Allocator holds a reference to the underlying SharedHandler. The + SharedHandler will not be destroyed as long as any Allocator is still + using it. +*/ +template +struct SharedHandlerAllocator +{ + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef T const* const_pointer; + typedef T const& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + SharedHandlerAllocator (SharedHandler* handler) noexcept + : m_ptr (handler) + { + } + + SharedHandlerAllocator (SharedHandlerPtr const& handler) noexcept + : m_ptr (handler) + { + } + + template + SharedHandlerAllocator (SharedHandlerAllocator const& other) + : m_ptr (other.m_ptr) + { + } + + template + struct rebind + { + typedef SharedHandlerAllocator other; + }; + + pointer address (reference x) const + { + return &x; + } + + const_pointer address (const_reference x) const + { + return &x; + } + + pointer allocate (size_type n) const + { + size_type const bytes = n * sizeof (value_type); + return static_cast (m_ptr->allocate (bytes)); + } + + void deallocate (pointer p, size_type n) const + { + size_type const bytes = n * sizeof (value_type); + m_ptr->deallocate (p, bytes); + } + + size_type max_size () const noexcept + { + return std::numeric_limits ::max () / sizeof (value_type); + } + + void construct (pointer p, const_reference val) const + { + ::new ((void *)p) value_type (val); + } + + void destroy (pointer p) const + { + p->~value_type (); + } + +private: + template + friend struct SharedHandlerAllocator; + friend class SharedHandler; + + SharedHandlerPtr m_ptr; +}; + +//------------------------------------------------------------------------------ + +#if 0 +template +void SharedHandler::invoke (BOOST_ASIO_MOVE_ARG(Function) f) +{ + // The allocator will hold a reference to the SharedHandler + // so that we can safely destroy the function object. + invoked_type invoked (BOOST_ASIO_MOVE_CAST(Function)(f), + SharedHandlerAllocator (this)); + invoke (invoked); +} +#endif + +#endif diff --git a/modules/beast_asio/async/SharedHandlerPtr.h b/modules/beast_asio/async/SharedHandlerPtr.h new file mode 100644 index 0000000000..d864ca8cc9 --- /dev/null +++ b/modules/beast_asio/async/SharedHandlerPtr.h @@ -0,0 +1,327 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_ASYNC_SHAREDHANDLERPTR_H_INCLUDED +#define BEAST_ASIO_ASYNC_SHAREDHANDLERPTR_H_INCLUDED + +/** RAII container for a SharedHandler. + + This object behaves exactly like a SharedHandler except that it + merely contains a shared pointer to the underlying SharedHandler. + All calls are forwarded to the underlying SharedHandler, and all + of the execution safety guarantees are met by forwarding them through + to the underlying SharedHandler. +*/ +class SharedHandlerPtr +{ +protected: + typedef boost::system::error_code error_code; + +public: + // For asio::async_result<> + typedef void result_type; + + /** Construct a null handler. + A null handler cannot be called. It can, however, be checked + for validity by calling isNull, and later assigned. + + @see isNull, isNotNull + */ + inline SharedHandlerPtr () noexcept + { + } + + /** Construct from an existing SharedHandler. + Ownership of the handler is transferred to the container. + */ + inline SharedHandlerPtr (SharedHandler* handler) + : m_ptr (handler) + { + } + + /** Construct a reference from an existing container. + */ + inline SharedHandlerPtr (SharedHandlerPtr const& other) noexcept + : m_ptr (other.m_ptr) + { + } + + /** Assign a reference from an existing container. */ + inline SharedHandlerPtr& operator= (SharedHandlerPtr const& other) noexcept + { + m_ptr = other.m_ptr; + return *this; + } + +#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS + /** Move-construct a reference from an existing container. + The other container is set to a null handler. + */ + inline SharedHandlerPtr (SharedHandlerPtr&& other) noexcept + : m_ptr (other.m_ptr) + { + other.m_ptr = nullptr; + } + + /** Move-assign a reference from an existing container. + The other container is set to a null handler. + */ + inline SharedHandlerPtr& operator= (SharedHandlerPtr&& other) noexcept + { + m_ptr = other.m_ptr; + other.m_ptr = nullptr; + return *this; + } +#endif + + /** Returns true if the handler is a null handler. */ + inline bool isNull () const noexcept + { + return m_ptr == nullptr; + } + + /** Returns true if the handler is not a null handler. */ + inline bool isNotNull () const noexcept + { + return m_ptr != nullptr; + } + + /** Dereference the container. + This returns a reference to the underlying SharedHandler object. + */ + inline SharedHandler& operator* () const noexcept + { + return *m_ptr; + } + + /** SharedHandler member access. + This lets you call functions directly on the SharedHandler. + */ + inline SharedHandler* operator-> () const noexcept + { + return m_ptr.get (); + } + + /** Retrieve the SharedHandler as a Context. + + This can be used for invoking functions in the context: + + @code + + template + void callOnHandler (Function f, SharedHandlerPtr ptr) + { + boost::asio_handler_invoke (f, ptr.get ()); + } + + @endcode + */ + inline SharedHandler* get () const noexcept + { + return m_ptr.get (); + } + + /** Invoke the SharedHandler with signature void(void) + Normally this is called by a dispatcher, you shouldn't call it directly. + */ + inline void operator() () const + { + (*m_ptr)(); + } + + /** Invoke the SharedHandler with signature void(error_code) + Normally this is called by a dispatcher, you shouldn't call it directly. + */ + inline void operator() (error_code const& ec) const + { + (*m_ptr)(ec); + } + + /** Invoke the SharedHandler with signature void(error_code, size_t) + Normally this is called by a dispatcher, you shouldn't call it directly. + */ + inline void operator() (error_code const& ec, std::size_t bytes_transferred) const + { + (*m_ptr)(ec, bytes_transferred); + } + +private: + // These ensure that SharedHandlerPtr invocations adhere to + // the asio::io_service execution guarantees of the underlying SharedHandler. + // + template + friend void asio_handler_invoke (BOOST_ASIO_MOVE_ARG(Function) f, SharedHandlerPtr*); + friend void* asio_handler_allocate (std::size_t, SharedHandlerPtr*); + friend void asio_handler_deallocate (void*, std::size_t, SharedHandlerPtr*); + friend bool asio_handler_is_continuation (SharedHandlerPtr*); + + SharedHandler::Ptr m_ptr; +}; + +//-------------------------------------------------------------------------- +// +// Context execution guarantees +// + +template +inline void asio_handler_invoke (BOOST_ASIO_MOVE_ARG(Function) f, SharedHandlerPtr* ptr) +{ + boost_asio_handler_invoke_helpers:: + invoke + (BOOST_ASIO_MOVE_CAST(Function)(f), *ptr->get ()); +} + +inline void* asio_handler_allocate (std::size_t size, SharedHandlerPtr* ptr) +{ + return boost_asio_handler_alloc_helpers:: + allocate (size, *ptr->get ()); +} + +inline void asio_handler_deallocate (void* p, std::size_t size, SharedHandlerPtr* ptr) +{ + boost_asio_handler_alloc_helpers:: + deallocate (p, size, *ptr->get ()); +} + +inline bool asio_handler_is_continuation (SharedHandlerPtr* ptr) +{ +#if BEAST_ASIO_HAS_CONTINUATION_HOOKS + return boost_asio_handler_cont_helpers:: + is_continuation (*ptr->get ()); +#else + return false; +#endif +} + +//-------------------------------------------------------------------------- +// +// Helpers +// +//-------------------------------------------------------------------------- + +// void(error_code) +template +SharedHandlerPtr newErrorHandler ( + BOOST_ASIO_MOVE_ARG(Handler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(Handler)(handler)); +} + +// void(error_code, size_t) +template +SharedHandlerPtr newTransferHandler ( + BOOST_ASIO_MOVE_ARG(Handler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(Handler)(handler)); +} + +//-------------------------------------------------------------------------- + +// CompletionHandler +// +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/CompletionHandler.html +// +template +SharedHandlerPtr newCompletionHandler ( + BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)); +} + +// AcceptHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AcceptHandler.html +// +template +SharedHandlerPtr newAcceptHandler ( + BOOST_ASIO_MOVE_ARG(AcceptHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler)); +} + +// ConnectHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ConnectHandler.html +// +template +SharedHandlerPtr newConnectHandler ( + BOOST_ASIO_MOVE_ARG(ConnectHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(ConnectHandler)(handler)); +} + +// ShutdownHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ShutdownHandler.html +// +template +SharedHandlerPtr newShutdownHandler( + BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler)); +} + +// HandshakeHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/HandshakeHandler.html +// +template +SharedHandlerPtr newHandshakeHandler( + BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler)); +} + +// ReadHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ReadHandler.html +// +template +SharedHandlerPtr newReadHandler( + BOOST_ASIO_MOVE_ARG(ReadHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); +} + +// WriteHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/WriteHandler.html +// +template +SharedHandlerPtr newWriteHandler( + BOOST_ASIO_MOVE_ARG(WriteHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); +} + +// BufferedHandshakeHandler +// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/BufferedHandshakeHandler.html +// +template +SharedHandlerPtr newBufferedHandshakeHandler( + BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler) +{ + return newSharedHandlerContainer ( + BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler)); +} + +#endif diff --git a/modules/beast_asio/async/SharedHandlerType.h b/modules/beast_asio/async/SharedHandlerType.h new file mode 100644 index 0000000000..40de9f3262 --- /dev/null +++ b/modules/beast_asio/async/SharedHandlerType.h @@ -0,0 +1,222 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_ASIO_ASYNC_SHAREDHANDLERTYPE_H_INCLUDED +#define BEAST_ASIO_ASYNC_SHAREDHANDLERTYPE_H_INCLUDED + +/** An instance of SharedHandler that wraps an existing Handler. + + The wrapped handler will meet all the execution guarantees of + the original Handler object. +*/ +template +class SharedHandlerType : public SharedHandler +{ +protected: + SharedHandlerType (std::size_t size, + BOOST_ASIO_MOVE_ARG(Handler) handler) + : m_size (size) + , m_handler (BOOST_ASIO_MOVE_CAST(Handler)(handler)) + { + } + + ~SharedHandlerType () + { + + } + + void invoke (invoked_type& invoked) + { + boost_asio_handler_invoke_helpers:: + invoke (invoked, m_handler); + } + + void* allocate (std::size_t size) + { + return boost_asio_handler_alloc_helpers:: + allocate (size, m_handler); + } + + void deallocate (void* p, std::size_t size) + { + boost_asio_handler_alloc_helpers:: + deallocate (p, size, m_handler); + } + + bool is_continuation () + { +#if BEAST_ASIO_HAS_CONTINUATION_HOOKS + return boost_asio_handler_cont_helpers:: + is_continuation (m_handler); +#else + return false; +#endif + } + + // Called by SharedObject hook to destroy the object. We need + // this because we allocated it using a custom allocator. + // Destruction is tricky, the algorithm is as follows: + // + // First we move-assign the handler to our stack. If the build + // doesn't support move-assignment it will be a copy, still ok. + // We convert 'this' to a pointer to the polymorphic base, to + // ensure that the following direct destructor call will reach + // the most derived class. Finally, we deallocate the memory + // using the handler that is local to the stack. + // + // For this to work we need to make sure regular operator delete + // is never called for our object (it's private). We also need + // the size from the original allocation, which we saved at + // the time of construction. + // + void destroy () + { + Handler local (BOOST_ASIO_MOVE_CAST(Handler)(m_handler)); + std::size_t const size (m_size); + SharedHandler* const shared (static_cast (this)); + shared->~SharedHandler (); + boost_asio_handler_alloc_helpers:: + deallocate (shared, size, local); + } + + // If these somehow get called, bad things will happen + // + void* operator new (std::size_t) + { + return pure_virtual_called (__FILE__, __LINE__); + } + + void operator delete (void*) + { + return pure_virtual_called (__FILE__, __LINE__); + } + +protected: + std::size_t const m_size; + Handler m_handler; +}; + +//-------------------------------------------------------------------------- +// +// A SharedHandlerType for this signature: +// void(void) +// +template +class PostSharedHandlerType : public SharedHandlerType +{ +public: + PostSharedHandlerType (std::size_t size, + BOOST_ASIO_MOVE_ARG(Handler) handler) + : SharedHandlerType (size, + BOOST_ASIO_MOVE_CAST(Handler)(handler)) + { + } + +protected: + void operator() () + { + this->m_handler (); + } +}; + +//-------------------------------------------------------------------------- +// +// A SharedHandlerType for this signature: +// void(error_code) +// +template +class ErrorSharedHandlerType : public SharedHandlerType +{ +public: + ErrorSharedHandlerType (std::size_t size, + BOOST_ASIO_MOVE_ARG(Handler) handler) + : SharedHandlerType (size, + BOOST_ASIO_MOVE_CAST(Handler)(handler)) + { + } + +protected: + void operator() (boost::system::error_code const& ec) + { + this->m_handler (ec); + } +}; + +//-------------------------------------------------------------------------- +// +// A SharedHandlerType for this signature: +// void(error_code, size_t) +// +template +class TransferSharedHandlerType : public SharedHandlerType +{ +public: + TransferSharedHandlerType (std::size_t size, + BOOST_ASIO_MOVE_ARG(Handler) handler) + : SharedHandlerType (size, + BOOST_ASIO_MOVE_CAST(Handler)(handler)) + { + } + +protected: + void operator() (boost::system::error_code const& ec, + std::size_t bytes_transferred) + { + this->m_handler (ec, bytes_transferred); + } +}; + +//-------------------------------------------------------------------------- +// +// These specializations will make sure we don't do +// anything silly like wrap ourselves in our own wrapper... +// +#if 1 +template <> +class PostSharedHandlerType +{ +}; + +template <> +class ErrorSharedHandlerType +{ +}; +template <> +class TransferSharedHandlerType +{ +}; +#endif + + +//-------------------------------------------------------------------------- + +/** Construct a wrapped handler using the context's allocation hooks. +*/ +template