From 9930b12d9d034847d00e9d2b071678935c589d9f Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Mon, 25 May 2015 17:36:21 -0700 Subject: [PATCH] Beast clean up: * Remove binding, dispatch handling and exit hooks in favor of std alternatives; remove crash-handling infrastructure, error message framework, system-specific process handling and Objective-C interop helpers. * Simplify Beast function profiling * Simplify beast::Time interface * Simplify beast::String interface * Simplify beast::File interface --- beast/Version.h | 33 +- beast/module/core/core.h | 4 - beast/module/core/core.unity.cpp | 6 - beast/module/core/diagnostic/FatalError.cpp | 2 +- .../core/diagnostic/MeasureFunctionCallTime.h | 61 +-- beast/module/core/files/File.cpp | 398 ------------------ beast/module/core/files/File.h | 236 +---------- beast/module/core/maths/Random.cpp | 3 - beast/module/core/native/bsd_Files.cpp | 35 -- beast/module/core/native/bsd_SystemStats.cpp | 37 +- beast/module/core/native/bsd_Threads.cpp | 39 -- beast/module/core/native/linux_Files.cpp | 37 +- .../module/core/native/linux_SystemStats.cpp | 48 +-- beast/module/core/native/linux_Threads.cpp | 50 --- beast/module/core/native/mac_Files.mm | 23 - beast/module/core/native/mac_Strings.mm | 19 - beast/module/core/native/mac_SystemStats.mm | 71 +--- beast/module/core/native/mac_Threads.mm | 48 --- beast/module/core/native/osx_ObjCHelpers.h | 98 ----- beast/module/core/native/posix_SharedCode.h | 132 +----- beast/module/core/native/win32_Files.cpp | 100 ----- .../module/core/native/win32_SystemStats.cpp | 59 +-- beast/module/core/native/win32_Threads.cpp | 24 -- beast/module/core/streams/FileInputSource.cpp | 56 --- beast/module/core/streams/FileInputSource.h | 66 --- beast/module/core/streams/InputSource.h | 2 - beast/module/core/system/SystemStats.cpp | 48 +-- beast/module/core/system/SystemStats.h | 42 +- beast/module/core/threads/Process.h | 56 --- beast/module/core/time/AtExitHook.cpp | 140 ------ beast/module/core/time/AtExitHook.h | 94 ----- beast/module/core/time/Time.cpp | 44 -- beast/module/core/time/Time.h | 69 --- beast/strings/String.h | 9 - beast/threads/detail/BindHandler.h | 276 ------------ beast/threads/detail/DispatchedHandler.h | 173 -------- beast/utility/Error.h | 134 ------ beast/utility/Utility.unity.cpp | 2 - beast/utility/impl/Error.cpp | 259 ------------ beast/utility/is_call_possible.h | 284 ------------- 40 files changed, 96 insertions(+), 3221 deletions(-) delete mode 100644 beast/module/core/native/bsd_Threads.cpp delete mode 100644 beast/module/core/native/linux_Threads.cpp delete mode 100644 beast/module/core/native/mac_Threads.mm delete mode 100644 beast/module/core/streams/FileInputSource.cpp delete mode 100644 beast/module/core/streams/FileInputSource.h delete mode 100644 beast/module/core/threads/Process.h delete mode 100644 beast/module/core/time/AtExitHook.cpp delete mode 100644 beast/module/core/time/AtExitHook.h delete mode 100644 beast/threads/detail/BindHandler.h delete mode 100644 beast/threads/detail/DispatchedHandler.h delete mode 100644 beast/utility/Error.h delete mode 100644 beast/utility/impl/Error.cpp delete mode 100644 beast/utility/is_call_possible.h diff --git a/beast/Version.h b/beast/Version.h index e409692fb6..468a0b0210 100644 --- a/beast/Version.h +++ b/beast/Version.h @@ -20,21 +20,26 @@ #ifndef BEAST_VERSION_H_INCLUDED #define BEAST_VERSION_H_INCLUDED -/** Current BEAST version number. - See also SystemStats::getBeastVersion() for a string version. -*/ -// VFALCO TODO Replace this with SemanticVerson -#define BEAST_MAJOR_VERSION 1 -#define BEAST_MINOR_VERSION 0 -#define BEAST_BUILDNUMBER 0 +#include -/** Current Beast version number. - Bits 16 to 32 = major version. - Bits 8 to 16 = minor version. - Bits 0 to 8 = point release. - See also SystemStats::getBeastVersion() for a string version. -*/ -#define BEAST_VERSION ((BEAST_MAJOR_VERSION << 16) + (BEAST_MINOR_VERSION << 8) + BEAST_BUILDNUMBER) +/** Current BEAST version number. */ +unsigned int const BEAST_VERSION_MAJOR = 1; +unsigned int const BEAST_VERSION_MINOR = 0; +unsigned int const BEAST_VERSION_BUILD = 0; + +unsigned int const BEAST_VERSION = + (BEAST_VERSION_MAJOR << 16) + + (BEAST_VERSION_MINOR << 8) + + BEAST_VERSION_BUILD; + +inline +std::string +getBeastVersion() +{ + return "Beast v" + std::to_string (BEAST_VERSION_MAJOR) + + "." + std::to_string (BEAST_VERSION_MINOR) + + "." + std::to_string (BEAST_VERSION_BUILD); +} #endif diff --git a/beast/module/core/core.h b/beast/module/core/core.h index 2ecc4619ed..5f9a5d5eeb 100644 --- a/beast/module/core/core.h +++ b/beast/module/core/core.h @@ -50,7 +50,6 @@ #include #include -#include #include #include @@ -69,7 +68,6 @@ class FileOutputStream; // Order matters, since headers don't have their own #include lines. // Add new includes to the bottom. -#include #include #include #include @@ -139,14 +137,12 @@ class FileOutputStream; #include #include #include -#include #include #include #include #include #include -#include #include #include diff --git a/beast/module/core/core.unity.cpp b/beast/module/core/core.unity.cpp index 7d74933a53..4bb04f390d 100644 --- a/beast/module/core/core.unity.cpp +++ b/beast/module/core/core.unity.cpp @@ -141,7 +141,6 @@ #include -#include #include #include #include @@ -155,7 +154,6 @@ #include #include -#include #include #if BEAST_MAC || BEAST_IOS @@ -174,22 +172,18 @@ #include #include #include -#include #elif BEAST_WINDOWS #include #include -#include #elif BEAST_LINUX #include #include -#include #elif BEAST_BSD #include #include -#include #elif BEAST_ANDROID #include "native/android_Files.cpp" diff --git a/beast/module/core/diagnostic/FatalError.cpp b/beast/module/core/diagnostic/FatalError.cpp index 6806a20652..e8d7b2f7e9 100644 --- a/beast/module/core/diagnostic/FatalError.cpp +++ b/beast/module/core/diagnostic/FatalError.cpp @@ -54,7 +54,7 @@ FatalError (char const* message, char const* file, int line) if (file != nullptr && file [0] != 0) std::cerr << " File: " << file << ":" << line << '\n'; - auto const backtrace = SystemStats::getStackBacktrace (); + auto const backtrace = getStackBacktrace (); if (!backtrace.empty ()) { diff --git a/beast/module/core/diagnostic/MeasureFunctionCallTime.h b/beast/module/core/diagnostic/MeasureFunctionCallTime.h index 413b741bf3..9671513d1b 100644 --- a/beast/module/core/diagnostic/MeasureFunctionCallTime.h +++ b/beast/module/core/diagnostic/MeasureFunctionCallTime.h @@ -20,66 +20,23 @@ #ifndef BEAST_MODULE_CORE_DIAGNOSTIC_MEASUREFUNCTIONCALLTIME_H_INCLUDED #define BEAST_MODULE_CORE_DIAGNOSTIC_MEASUREFUNCTIONCALLTIME_H_INCLUDED +#include + namespace beast { /** Measures the speed of invoking a function. */ -/** @{ */ -template -double measureFunctionCallTime (Function f) +template +std::chrono::high_resolution_clock::duration +measureFunctionCallTime (Function f, Args&&... args) { - std::int64_t const startTime (Time::getHighResolutionTicks ()); - f (); - return Time::highResolutionTicksToSeconds ( - Time::getHighResolutionTicks () - startTime); -} + auto start = std::chrono::high_resolution_clock::now (); + f (std::forward(args)...); + auto end = std::chrono::high_resolution_clock::now (); -#if 0 -template -double measureFunctionCallTime (Function f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) -{ - std::int64_t const startTime (Time::getHighResolutionTicks ()); - f (p1, p2, p3, p4, p5 ,p6 ,p7 ,p8); - return Time::highResolutionTicksToSeconds ( - Time::getHighResolutionTicks () - startTime); + return end - start; } -template -double measureFunctionCallTime (Function f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) -{ - std::int64_t const startTime (Time::getHighResolutionTicks ()); - f (p1, p2, p3, p4, p5 ,p6 ,p7 ,p8); - return Time::highResolutionTicksToSeconds ( - Time::getHighResolutionTicks () - startTime); -} - -template -double measureFunctionCallTime (Function f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) -{ - std::int64_t const startTime (Time::getHighResolutionTicks ()); - f (p1, p2, p3, p4, p5 ,p6 ,p7 ,p8); - return Time::highResolutionTicksToSeconds ( - Time::getHighResolutionTicks () - startTime); -} - -template -double measureFunctionCallTime (Function f, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) -{ - std::int64_t const startTime (Time::getHighResolutionTicks ()); - f (p1, p2, p3, p4, p5 ,p6 ,p7 ,p8); - return Time::highResolutionTicksToSeconds ( - Time::getHighResolutionTicks () - startTime); -} -#endif - } // beast #endif diff --git a/beast/module/core/files/File.cpp b/beast/module/core/files/File.cpp index 8ed627ad5e..23bd032d57 100644 --- a/beast/module/core/files/File.cpp +++ b/beast/module/core/files/File.cpp @@ -21,7 +21,6 @@ */ //============================================================================== -#include #include #include #include @@ -205,23 +204,6 @@ bool File::operator< (const File& other) const { return compareFilenames (f bool File::operator> (const File& other) const { return compareFilenames (fullPath, other.fullPath) > 0; } //============================================================================== -bool File::setReadOnly (const bool shouldBeReadOnly, - const bool applyRecursively) const -{ - bool worked = true; - - if (applyRecursively && isDirectory()) - { - Array subFiles; - findChildFiles (subFiles, File::findFilesAndDirectories, false); - - for (int i = subFiles.size(); --i >= 0;) - worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked; - } - - return setFileReadOnlyInternal (shouldBeReadOnly) && worked; -} - bool File::deleteRecursively() const { bool worked = true; @@ -238,53 +220,6 @@ bool File::deleteRecursively() const return deleteFile() && worked; } -bool File::moveFileTo (const File& newFile) const -{ - if (newFile.fullPath == fullPath) - return true; - - if (! exists()) - return false; - - #if ! NAMES_ARE_CASE_SENSITIVE - if (*this != newFile) - #endif - if (! newFile.deleteFile()) - return false; - - return moveInternal (newFile); -} - -bool File::copyFileTo (const File& newFile) const -{ - return (*this == newFile) - || (exists() && newFile.deleteFile() && copyInternal (newFile)); -} - -bool File::copyDirectoryTo (const File& newDirectory) const -{ - if (isDirectory() && newDirectory.createDirectory()) - { - Array subFiles; - findChildFiles (subFiles, File::findFiles, false); - - for (int i = 0; i < subFiles.size(); ++i) - if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName()))) - return false; - - subFiles.clear(); - findChildFiles (subFiles, File::findDirectories, false); - - for (int i = 0; i < subFiles.size(); ++i) - if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName()))) - return false; - - return true; - } - - return false; -} - //============================================================================== String File::getPathUpToLastSlash() const { @@ -339,9 +274,6 @@ bool File::isAChildOf (const File& potentialParent) const return getParentDirectory().isAChildOf (potentialParent); } -int File::hashCode() const { return fullPath.hashCode(); } -std::int64_t File::hashCode64() const { return fullPath.hashCode64(); } - //============================================================================== bool File::isAbsolutePath (const String& path) { @@ -447,15 +379,6 @@ Result File::createDirectory() const return r; } -//============================================================================== -Time File::getLastModificationTime() const { std::int64_t m, a, c; getFileTimesInternal (m, a, c); return Time (m); } -Time File::getLastAccessTime() const { std::int64_t m, a, c; getFileTimesInternal (m, a, c); return Time (a); } -Time File::getCreationTime() const { std::int64_t m, a, c; getFileTimesInternal (m, a, c); return Time (c); } - -bool File::setLastModificationTime (Time t) const { return setFileTimesInternal (t.toMilliseconds(), 0, 0); } -bool File::setLastAccessTime (Time t) const { return setFileTimesInternal (0, t.toMilliseconds(), 0); } -bool File::setCreationTime (Time t) const { return setFileTimesInternal (0, 0, t.toMilliseconds()); } - //============================================================================== int File::findChildFiles (Array& results, const int whatToLookFor, @@ -485,75 +408,6 @@ int File::getNumberOfChildFiles (const int whatToLookFor, const String& wildCard return total; } -bool File::containsSubDirectories() const -{ - if (! isDirectory()) - return false; - - DirectoryIterator di (*this, false, "*", findDirectories); - return di.next(); -} - -//============================================================================== -File File::getNonexistentChildFile (const String& suggestedPrefix, - const String& suffix, - bool putNumbersInBrackets) const -{ - File f (getChildFile (suggestedPrefix + suffix)); - - if (f.exists()) - { - int number = 1; - String prefix (suggestedPrefix); - - // remove any bracketed numbers that may already be on the end.. - if (prefix.trim().endsWithChar (')')) - { - putNumbersInBrackets = true; - - const int openBracks = prefix.lastIndexOfChar ('('); - const int closeBracks = prefix.lastIndexOfChar (')'); - - if (openBracks > 0 - && closeBracks > openBracks - && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789")) - { - number = prefix.substring (openBracks + 1, closeBracks).getIntValue(); - prefix = prefix.substring (0, openBracks); - } - } - - // also use brackets if it ends in a digit. - putNumbersInBrackets = putNumbersInBrackets - || CharacterFunctions::isDigit (prefix.getLastCharacter()); - - do - { - String newName (prefix); - - if (putNumbersInBrackets) - newName << '(' << ++number << ')'; - else - newName << ++number; - - f = getChildFile (newName + suffix); - - } while (f.exists()); - } - - return f; -} - -File File::getNonexistentSibling (const bool putNumbersInBrackets) const -{ - if (! exists()) - return *this; - - return getParentDirectory().getNonexistentChildFile (getFileNameWithoutExtension(), - getFileExtension(), - putNumbersInBrackets); -} - //============================================================================== String File::getFileExtension() const { @@ -656,126 +510,6 @@ bool File::appendText (const String& text, return true; } -//============================================================================== -String File::createLegalPathName (const String& original) -{ - String s (original); - String start; - - if (s[1] == ':') - { - start = s.substring (0, 2); - s = s.substring (2); - } - - return start + s.removeCharacters ("\"#@,;:<>*^|?") - .substring (0, 1024); -} - -String File::createLegalFileName (const String& original) -{ - String s (original.removeCharacters ("\"#@,;:<>*^|?\\/")); - - const int maxLength = 128; // only the length of the filename, not the whole path - const int len = s.length(); - - if (len > maxLength) - { - const int lastDot = s.lastIndexOfChar ('.'); - - if (lastDot > std::max (0, len - 12)) - { - s = s.substring (0, maxLength - (len - lastDot)) - + s.substring (lastDot); - } - else - { - s = s.substring (0, maxLength); - } - } - - return s; -} - -//============================================================================== -static int countNumberOfSeparators (String::CharPointerType s) -{ - int num = 0; - - for (;;) - { - const beast_wchar c = s.getAndAdvance(); - - if (c == 0) - break; - - if (c == File::separator) - ++num; - } - - return num; -} - -String File::getRelativePathFrom (const File& dir) const -{ - String thisPath (fullPath); - - while (thisPath.endsWithChar (separator)) - thisPath = thisPath.dropLastCharacters (1); - - String dirPath (addTrailingSeparator (dir.existsAsFile() ? dir.getParentDirectory().getFullPathName() - : dir.fullPath)); - - int commonBitLength = 0; - String::CharPointerType thisPathAfterCommon (thisPath.getCharPointer()); - String::CharPointerType dirPathAfterCommon (dirPath.getCharPointer()); - - { - String::CharPointerType thisPathIter (thisPath.getCharPointer()); - String::CharPointerType dirPathIter (dirPath.getCharPointer()); - - for (int i = 0;;) - { - const beast_wchar c1 = thisPathIter.getAndAdvance(); - const beast_wchar c2 = dirPathIter.getAndAdvance(); - - #if NAMES_ARE_CASE_SENSITIVE - if (c1 != c2 - #else - if ((c1 != c2 && CharacterFunctions::toLowerCase (c1) != CharacterFunctions::toLowerCase (c2)) - #endif - || c1 == 0) - break; - - ++i; - - if (c1 == separator) - { - thisPathAfterCommon = thisPathIter; - dirPathAfterCommon = dirPathIter; - commonBitLength = i; - } - } - } - - // if the only common bit is the root, then just return the full path.. - if (commonBitLength == 0 || (commonBitLength == 1 && thisPath[1] == separator)) - return fullPath; - - const int numUpDirectoriesNeeded = countNumberOfSeparators (dirPathAfterCommon); - - if (numUpDirectoriesNeeded == 0) - return thisPathAfterCommon; - - #if BEAST_WINDOWS - String s (String::repeatedString ("..\\", numUpDirectoriesNeeded)); - #else - String s (String::repeatedString ("../", numUpDirectoriesNeeded)); - #endif - s.appendCharPointer (thisPathAfterCommon); - return s; -} - //============================================================================== File File::createTempFile (const String& fileNameEnding) { @@ -789,136 +523,4 @@ File File::createTempFile (const String& fileNameEnding) return tempFile; } -//============================================================================== - -class File_test : public unit_test::suite -{ -public: - template - bool - expectEquals (T1 const& t1, T2 const& t2) - { - return expect (t1 == t2); - } - - void run() - { - testcase ("Reading"); - - const File home (File::getSpecialLocation (File::userHomeDirectory)); - const File temp (File::getSpecialLocation (File::tempDirectory)); - - expect (! File::nonexistent ().exists()); - expect (home.isDirectory()); - expect (home.exists()); - expect (! home.existsAsFile()); - expect (File::getSpecialLocation (File::userDocumentsDirectory).isDirectory()); - expect (File::getSpecialLocation (File::userApplicationDataDirectory).isDirectory()); - expect (home.getVolumeTotalSize() > 1024 * 1024); - expect (home.getBytesFreeOnVolume() > 0); - expect (File::getCurrentWorkingDirectory().exists()); - expect (home.setAsCurrentWorkingDirectory()); - #if BEAST_WINDOWS - expect (File::getCurrentWorkingDirectory() == home); - #endif - - testcase ("Writing"); - - File demoFolder (temp.getChildFile ("Beast UnitTests Temp Folder.folder")); - expect (demoFolder.deleteRecursively()); - expect (demoFolder.createDirectory()); - expect (demoFolder.isDirectory()); - expect (demoFolder.getParentDirectory() == temp); - expect (temp.isDirectory()); - - { - Array files; - temp.findChildFiles (files, File::findFilesAndDirectories, false, "*"); - expect (files.contains (demoFolder)); - } - - { - Array files; - temp.findChildFiles (files, File::findDirectories, true, "*.folder"); - expect (files.contains (demoFolder)); - } - - File tempFile (demoFolder.getNonexistentChildFile ("test", ".txt", false)); - - expect (tempFile.getFileExtension() == ".txt"); - expect (tempFile.hasFileExtension (".txt")); - expect (tempFile.hasFileExtension ("txt")); - expect (tempFile.withFileExtension ("xyz").hasFileExtension (".xyz")); - expect (tempFile.withFileExtension ("xyz").hasFileExtension ("abc;xyz;foo")); - expect (tempFile.withFileExtension ("xyz").hasFileExtension ("xyz;foo")); - expect (! tempFile.withFileExtension ("h").hasFileExtension ("bar;foo;xx")); - expect (tempFile.getSiblingFile ("foo").isAChildOf (temp)); - expect (tempFile.hasWriteAccess()); - - { - FileOutputStream fo (tempFile); - fo.write ("0123456789", 10); - } - - expect (tempFile.exists()); - expect (tempFile.getSize() == 10); - expect (std::abs ((int) (tempFile.getLastModificationTime().toMilliseconds() - Time::getCurrentTime().toMilliseconds())) < 3000); - expect (! demoFolder.containsSubDirectories()); - - expectEquals (tempFile.getRelativePathFrom (demoFolder.getParentDirectory()), demoFolder.getFileName() + File::separatorString + tempFile.getFileName()); - expectEquals (demoFolder.getParentDirectory().getRelativePathFrom (tempFile), ".." + File::separatorString + ".." + File::separatorString + demoFolder.getParentDirectory().getFileName()); - - expect (demoFolder.getNumberOfChildFiles (File::findFiles) == 1); - expect (demoFolder.getNumberOfChildFiles (File::findFilesAndDirectories) == 1); - expect (demoFolder.getNumberOfChildFiles (File::findDirectories) == 0); - demoFolder.getNonexistentChildFile ("tempFolder", "", false).createDirectory(); - expect (demoFolder.getNumberOfChildFiles (File::findDirectories) == 1); - expect (demoFolder.getNumberOfChildFiles (File::findFilesAndDirectories) == 2); - expect (demoFolder.containsSubDirectories()); - - expect (tempFile.hasWriteAccess()); - tempFile.setReadOnly (true); - expect (! tempFile.hasWriteAccess()); - tempFile.setReadOnly (false); - expect (tempFile.hasWriteAccess()); - - Time t (Time::getCurrentTime()); - tempFile.setLastModificationTime (t); - Time t2 = tempFile.getLastModificationTime(); - expect (std::abs ((int) (t2.toMilliseconds() - t.toMilliseconds())) <= 1000); - - { - expect (tempFile.getSize() == 10); - FileOutputStream fo (tempFile); - expect (fo.openedOk()); - - expect (fo.setPosition (7)); - expect (fo.truncate().wasOk()); - expect (tempFile.getSize() == 7); - fo.write ("789", 3); - fo.flush(); - expect (tempFile.getSize() == 10); - } - - testcase ("More writing"); - - expect (tempFile.appendData ("abcdefghij", 10)); - expect (tempFile.getSize() == 20); - - File tempFile2 (tempFile.getNonexistentSibling (false)); - expect (tempFile.copyFileTo (tempFile2)); - expect (tempFile2.exists()); - expect (tempFile.deleteFile()); - expect (! tempFile.exists()); - expect (tempFile2.moveFileTo (tempFile)); - expect (tempFile.exists()); - expect (! tempFile2.exists()); - - expect (demoFolder.deleteRecursively()); - expect (! demoFolder.exists()); - } -}; - -BEAST_DEFINE_TESTSUITE_MANUAL (File,beast_core,beast); - } // beast diff --git a/beast/module/core/files/File.h b/beast/module/core/files/File.h index 428a45af13..8f4225b994 100644 --- a/beast/module/core/files/File.h +++ b/beast/module/core/files/File.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -144,7 +143,7 @@ public: If you just want the file's name, you should use getFileName() or getFileNameWithoutExtension(). - @see getFileName, getRelativePathFrom + @see getFileName */ const String& getFullPathName() const noexcept { return fullPath; } @@ -163,23 +162,6 @@ public: */ String getFileName() const; - /** Creates a relative path that refers to a file relatively to a given directory. - - e.g. File ("/moose/foo.txt").getRelativePathFrom (File ("/moose/fish/haddock")) - would return "../../foo.txt". - - If it's not possible to navigate from one file to the other, an absolute - path is returned. If the paths are invalid, an empty string may also be - returned. - - @param directoryToBeRelativeTo the directory which the resultant string will - be relative to. If this is actually a file rather than - a directory, its parent directory will be used instead. - If it doesn't exist, it's assumed to be a directory. - @see getChildFile, isAbsolutePath - */ - String getRelativePathFrom (const File& directoryToBeRelativeTo) const; - //============================================================================== /** Returns the file's extension. @@ -224,21 +206,6 @@ public: */ String getFileNameWithoutExtension() const; - //============================================================================== - /** Returns a 32-bit hash-code that identifies this file. - - This is based on the filename. Obviously it's possible, although unlikely, that - two files will have the same hash-code. - */ - int hashCode() const; - - /** Returns a 64-bit hash-code that identifies this file. - - This is based on the filename. Obviously it's possible, although unlikely, that - two files will have the same hash-code. - */ - std::int64_t hashCode64() const; - //============================================================================== /** Returns a file that represents a relative (or absolute) sub-path of the current one. @@ -252,7 +219,7 @@ public: If the string is actually an absolute path, it will be treated as such, e.g. File ("/moose/fish").getChildFile ("/foo.txt") will produce "/foo.txt" - @see getSiblingFile, getParentDirectory, getRelativePathFrom, isAChildOf + @see getSiblingFile, getParentDirectory, isAChildOf */ File getChildFile (String relativeOrAbsolutePath) const; @@ -282,39 +249,6 @@ public: */ bool isAChildOf (const File& potentialParentDirectory) const; - //============================================================================== - /** Chooses a filename relative to this one that doesn't already exist. - - If this file is a directory, this will return a child file of this - directory that doesn't exist, by adding numbers to a prefix and suffix until - it finds one that isn't already there. - - If the prefix + the suffix doesn't exist, it won't bother adding a number. - - e.g. File ("/moose/fish").getNonexistentChildFile ("foo", ".txt", true) might - return "/moose/fish/foo(2).txt" if there's already a file called "foo.txt". - - @param prefix the string to use for the filename before the number - @param suffix the string to add to the filename after the number - @param putNumbersInBrackets if true, this will create filenames in the - format "prefix(number)suffix", if false, it will leave the - brackets out. - */ - File getNonexistentChildFile (const String& prefix, - const String& suffix, - bool putNumbersInBrackets = true) const; - - /** Chooses a filename for a sibling file to this one that doesn't already exist. - - If this file doesn't exist, this will just return itself, otherwise it - will return an appropriate sibling that doesn't exist, e.g. if a file - "/moose/fish/foo.txt" exists, this might return "/moose/fish/foo(2).txt". - - @param putNumbersInBrackets whether to add brackets around the numbers that - get appended to the new filename. - */ - File getNonexistentSibling (bool putNumbersInBrackets = true) const; - //============================================================================== /** Compares the pathnames for two files. */ bool operator== (const File&) const; @@ -325,74 +259,6 @@ public: /** Compares the pathnames for two files. */ bool operator> (const File&) const; - //============================================================================== - /** Checks whether a file can be created or written to. - - @returns true if it's possible to create and write to this file. If the file - doesn't already exist, this will check its parent directory to - see if writing is allowed. - @see setReadOnly - */ - bool hasWriteAccess() const; - - /** Changes the write-permission of a file or directory. - - @param shouldBeReadOnly whether to add or remove write-permission - @param applyRecursively if the file is a directory and this is true, it will - recurse through all the subfolders changing the permissions - of all files - @returns true if it manages to change the file's permissions. - @see hasWriteAccess - */ - bool setReadOnly (bool shouldBeReadOnly, - bool applyRecursively = false) const; - - //============================================================================== - /** Returns the last modification time of this file. - - @returns the time, or an invalid time if the file doesn't exist. - @see setLastModificationTime, getLastAccessTime, getCreationTime - */ - Time getLastModificationTime() const; - - /** Returns the last time this file was accessed. - - @returns the time, or an invalid time if the file doesn't exist. - @see setLastAccessTime, getLastModificationTime, getCreationTime - */ - Time getLastAccessTime() const; - - /** Returns the time that this file was created. - - @returns the time, or an invalid time if the file doesn't exist. - @see getLastModificationTime, getLastAccessTime - */ - Time getCreationTime() const; - - /** Changes the modification time for this file. - - @param newTime the time to apply to the file - @returns true if it manages to change the file's time. - @see getLastModificationTime, setLastAccessTime, setCreationTime - */ - bool setLastModificationTime (Time newTime) const; - - /** Changes the last-access time for this file. - - @param newTime the time to apply to the file - @returns true if it manages to change the file's time. - @see getLastAccessTime, setLastModificationTime, setCreationTime - */ - bool setLastAccessTime (Time newTime) const; - - /** Changes the creation date for this file. - - @param newTime the time to apply to the file - @returns true if it manages to change the file's time. - @see getCreationTime, setLastModificationTime, setLastAccessTime - */ - bool setCreationTime (Time newTime) const; - //============================================================================== /** Creates an empty file if it doesn't already exist. @@ -439,44 +305,6 @@ public: */ bool deleteRecursively() const; - /** Moves or renames a file. - - Tries to move a file to a different location. - If the target file already exists, this will attempt to delete it first, and - will fail if this can't be done. - - Note that the destination file isn't the directory to put it in, it's the actual - filename that you want the new file to have. - - @returns true if the operation succeeds - */ - bool moveFileTo (const File& targetLocation) const; - - /** Copies a file. - - Tries to copy a file to a different location. - If the target file already exists, this will attempt to delete it first, and - will fail if this can't be done. - - @returns true if the operation succeeds - */ - bool copyFileTo (const File& targetLocation) const; - - /** Copies a directory. - - Tries to copy an entire directory, recursively. - - If this file isn't a directory or if any target files can't be created, this - will return false. - - @param newDirectory the directory that this one should be copied to. Note that this - is the name of the actual directory to create, not the directory - into which the new one should be placed, so there must be enough - write privileges to create it if it doesn't exist. Any files inside - it will be overwritten by similarly named ones that are copied. - */ - bool copyDirectoryTo (const File& newDirectory) const; - //============================================================================== /** Used in file searching, to specify whether to return files, directories, or both. */ @@ -529,11 +357,6 @@ public: int getNumberOfChildFiles (int whatToLookFor, const String& wildCardPattern = "*") const; - /** Returns true if this file is a directory that contains one or more subdirectories. - @see isDirectory, findChildFiles - */ - bool containsSubDirectories() const; - //============================================================================== /** Creates a stream to read from this file. @@ -581,21 +404,6 @@ public: bool asUnicode = false, bool writeUnicodeHeaderBytes = false) const; - //============================================================================== - /** Returns the number of bytes free on the drive that this file lives on. - - @returns the number of bytes free, or 0 if there's a problem finding this out - @see getVolumeTotalSize - */ - std::int64_t getBytesFreeOnVolume() const; - - /** Returns the total size of the drive that contains this file. - - @returns the total number of bytes that the volume can hold - @see getBytesFreeOnVolume - */ - std::int64_t getVolumeTotalSize() const; - //============================================================================== /** A set of types of location that can be passed to the getSpecialLocation() method. */ @@ -674,20 +482,9 @@ public: //============================================================================== - /** Returns the current working directory. - @see setAsCurrentWorkingDirectory - */ + /** Returns the current working directory. */ static File getCurrentWorkingDirectory(); - /** Sets the current working directory to be this file. - - For this to work the file must point to a valid directory. - - @returns true if the current directory has been changed. - @see getCurrentWorkingDirectory - */ - bool setAsCurrentWorkingDirectory() const; - //============================================================================== /** The system-specific file separator character. On Windows, this will be '\', on Mac/Linux, it'll be '/' @@ -700,28 +497,6 @@ public: static const String separatorString; //============================================================================== - /** Returns a version of a filename with any illegal characters removed. - - This will return a copy of the given string after removing characters - that are not allowed in a legal filename, and possibly shortening the - string if it's too long. - - Because this will remove slashes, don't use it on an absolute pathname - use - createLegalPathName() for that. - - @see createLegalPathName - */ - static String createLegalFileName (const String& fileNameToFix); - - /** Returns a version of a path with any illegal characters removed. - - Similar to createLegalFileName(), but this won't remove slashes, so can - be used on a complete pathname. - - @see createLegalFileName - */ - static String createLegalPathName (const String& pathNameToFix); - /** Indicates whether filenames are case-sensitive on the current operating system. */ static bool areFileNamesCaseSensitive(); @@ -746,11 +521,6 @@ private: String getPathUpToLastSlash() const; Result createDirectoryInternal (const String&) const; - bool copyInternal (const File&) const; - bool moveInternal (const File&) const; - bool setFileTimesInternal (std::int64_t m, std::int64_t a, std::int64_t c) const; - void getFileTimesInternal (std::int64_t& m, std::int64_t& a, std::int64_t& c) const; - bool setFileReadOnlyInternal (bool) const; }; } // beast diff --git a/beast/module/core/maths/Random.cpp b/beast/module/core/maths/Random.cpp index 86e23b1ebb..ce0519ad1b 100644 --- a/beast/module/core/maths/Random.cpp +++ b/beast/module/core/maths/Random.cpp @@ -58,9 +58,6 @@ void Random::setSeedRandomly() static std::int64_t globalSeed = 0; combineSeed (globalSeed ^ (std::int64_t) (std::intptr_t) this); - combineSeed (Time::getMillisecondCounter()); - combineSeed (Time::getHighResolutionTicks()); - combineSeed (Time::getHighResolutionTicksPerSecond()); combineSeed (Time::currentTimeMillis()); globalSeed ^= seed; diff --git a/beast/module/core/native/bsd_Files.cpp b/beast/module/core/native/bsd_Files.cpp index 0680925ff1..b67b3d5c48 100644 --- a/beast/module/core/native/bsd_Files.cpp +++ b/beast/module/core/native/bsd_Files.cpp @@ -23,38 +23,6 @@ namespace beast { - -enum -{ - U_ISOFS_SUPER_MAGIC = 5, - U_MSDOS_SUPER_MAGIC = 2, - U_NFS_SUPER_MAGIC = 1, - U_SMB_SUPER_MAGIC = 8 -}; - -//============================================================================== -bool File::copyInternal (const File& dest) const -{ - FileInputStream in (*this); - - if (dest.deleteFile()) - { - { - FileOutputStream out (dest); - - if (out.failedToOpen()) - return false; - - if (out.writeFromInputStream (in, -1) == getSize()) - return true; - } - - dest.deleteFile(); - } - - return false; -} - //============================================================================== static File resolveXDGFolder (const char* const type, const char* const fallbackFolder) { @@ -88,9 +56,6 @@ static File resolveXDGFolder (const char* const type, const char* const fallback return File (fallbackFolder); } -const char* const* beast_argv = nullptr; -int beast_argc = 0; - File File::getSpecialLocation (const SpecialLocationType type) { switch (type) diff --git a/beast/module/core/native/bsd_SystemStats.cpp b/beast/module/core/native/bsd_SystemStats.cpp index 2886e9ed3d..399e2b7d8b 100644 --- a/beast/module/core/native/bsd_SystemStats.cpp +++ b/beast/module/core/native/bsd_SystemStats.cpp @@ -28,7 +28,15 @@ void outputDebugString (std::string const& text) } //============================================================================== -std::string SystemStats::getComputerName() +bool beast_isRunningUnderDebugger() +{ + // XXX not implemented for FreeBSD! + // bassertfalse; // commented out since it calls isRunningUnderDebugger recursively + return false; +} + +//============================================================================== +std::string getComputerName() { char name [256] = { 0 }; if (gethostname (name, sizeof (name) - 1) == 0) @@ -37,31 +45,4 @@ std::string SystemStats::getComputerName() return std::string{}; } -//============================================================================== -std::uint32_t beast_millisecondsSinceStartup() noexcept -{ - timespec t; - clock_gettime (CLOCK_MONOTONIC, &t); - - return t.tv_sec * 1000 + t.tv_nsec / 1000000; -} - -std::int64_t Time::getHighResolutionTicks() noexcept -{ - timespec t; - clock_gettime (CLOCK_MONOTONIC, &t); - - return (t.tv_sec * (std::int64_t) 1000000) + (t.tv_nsec / 1000); -} - -std::int64_t Time::getHighResolutionTicksPerSecond() noexcept -{ - return 1000000; // (microseconds) -} - -double Time::getMillisecondCounterHiRes() noexcept -{ - return getHighResolutionTicks() * 0.001; -} - } // beast diff --git a/beast/module/core/native/bsd_Threads.cpp b/beast/module/core/native/bsd_Threads.cpp deleted file mode 100644 index 4b53bf2997..0000000000 --- a/beast/module/core/native/bsd_Threads.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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. -*/ -//============================================================================== - -namespace beast -{ -//============================================================================== -bool beast_isRunningUnderDebugger() -{ - // XXX not implemented for FreeBSD! - // bassertfalse; // commented out since it calls isRunningUnderDebugger recursively - return false; -} - -bool Process::isRunningUnderDebugger() -{ - return beast_isRunningUnderDebugger(); -} - -} // beast diff --git a/beast/module/core/native/linux_Files.cpp b/beast/module/core/native/linux_Files.cpp index 62004fb58d..b465848acc 100644 --- a/beast/module/core/native/linux_Files.cpp +++ b/beast/module/core/native/linux_Files.cpp @@ -23,38 +23,6 @@ namespace beast { - -enum -{ - U_ISOFS_SUPER_MAGIC = 0x9660, // linux/iso_fs.h - U_MSDOS_SUPER_MAGIC = 0x4d44, // linux/msdos_fs.h - U_NFS_SUPER_MAGIC = 0x6969, // linux/nfs_fs.h - U_SMB_SUPER_MAGIC = 0x517B // linux/smb_fs.h -}; - -//============================================================================== -bool File::copyInternal (const File& dest) const -{ - FileInputStream in (*this); - - if (dest.deleteFile()) - { - { - FileOutputStream out (dest); - - if (out.failedToOpen()) - return false; - - if (out.writeFromInputStream (in, -1) == getSize()) - return true; - } - - dest.deleteFile(); - } - - return false; -} - //============================================================================== static File resolveXDGFolder (const char* const type, const char* const fallbackFolder) { @@ -88,9 +56,6 @@ static File resolveXDGFolder (const char* const type, const char* const fallback return File (fallbackFolder); } -const char* const* beast_argv = nullptr; -int beast_argc = 0; - File File::getSpecialLocation (const SpecialLocationType type) { switch (type) @@ -104,7 +69,7 @@ File File::getSpecialLocation (const SpecialLocationType type) if (struct passwd* const pw = getpwuid (getuid())) return File (CharPointer_UTF8 (pw->pw_dir)); - + return File (CharPointer_UTF8 (homeDir)); } diff --git a/beast/module/core/native/linux_SystemStats.cpp b/beast/module/core/native/linux_SystemStats.cpp index ca330f2a4f..f40ea7c8b3 100644 --- a/beast/module/core/native/linux_SystemStats.cpp +++ b/beast/module/core/native/linux_SystemStats.cpp @@ -30,7 +30,26 @@ void outputDebugString (std::string const& text) } //============================================================================== -std::string SystemStats::getComputerName() +bool beast_isRunningUnderDebugger() +{ + static char testResult = 0; + + if (testResult == 0) + { + testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0); + + if (testResult >= 0) + { + ptrace (PT_DETACH, 0, (caddr_t) 1, 0); + testResult = 1; + } + } + + return testResult < 0; +} + +//============================================================================== +std::string getComputerName() { char name [256] = { 0 }; if (gethostname (name, sizeof (name) - 1) == 0) @@ -39,31 +58,4 @@ std::string SystemStats::getComputerName() return std::string{}; } -//============================================================================== -std::uint32_t beast_millisecondsSinceStartup() noexcept -{ - timespec t; - clock_gettime (CLOCK_MONOTONIC, &t); - - return t.tv_sec * 1000 + t.tv_nsec / 1000000; -} - -std::int64_t Time::getHighResolutionTicks() noexcept -{ - timespec t; - clock_gettime (CLOCK_MONOTONIC, &t); - - return (t.tv_sec * (std::int64_t) 1000000) + (t.tv_nsec / 1000); -} - -std::int64_t Time::getHighResolutionTicksPerSecond() noexcept -{ - return 1000000; // (microseconds) -} - -double Time::getMillisecondCounterHiRes() noexcept -{ - return getHighResolutionTicks() * 0.001; -} - } // beast diff --git a/beast/module/core/native/linux_Threads.cpp b/beast/module/core/native/linux_Threads.cpp deleted file mode 100644 index 16f1acab6e..0000000000 --- a/beast/module/core/native/linux_Threads.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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. -*/ -//============================================================================== - -namespace beast -{ -//============================================================================== -bool beast_isRunningUnderDebugger() -{ - static char testResult = 0; - - if (testResult == 0) - { - testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0); - - if (testResult >= 0) - { - ptrace (PT_DETACH, 0, (caddr_t) 1, 0); - testResult = 1; - } - } - - return testResult < 0; -} - -bool Process::isRunningUnderDebugger() -{ - return beast_isRunningUnderDebugger(); -} - -} // beast diff --git a/beast/module/core/native/mac_Files.mm b/beast/module/core/native/mac_Files.mm index 751115249c..cd36a43b38 100644 --- a/beast/module/core/native/mac_Files.mm +++ b/beast/module/core/native/mac_Files.mm @@ -29,26 +29,6 @@ namespace beast live in beast_posix_SharedCode.h! */ -//============================================================================== -bool File::copyInternal (const File& dest) const -{ - BEAST_AUTORELEASEPOOL - { - NSFileManager* fm = [NSFileManager defaultManager]; - - return [fm fileExistsAtPath: beastStringToNS (fullPath)] - #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 - && [fm copyItemAtPath: beastStringToNS (fullPath) - toPath: beastStringToNS (dest.getFullPathName()) - error: nil]; - #else - && [fm copyPath: beastStringToNS (fullPath) - toPath: beastStringToNS (dest.getFullPathName()) - handler: nil]; - #endif - } -} - //============================================================================== namespace FileHelpers { @@ -123,9 +103,6 @@ namespace FileHelpers } //============================================================================== -const char* const* beast_argv = nullptr; -int beast_argc = 0; - File File::getSpecialLocation (const SpecialLocationType type) { BEAST_AUTORELEASEPOOL diff --git a/beast/module/core/native/mac_Strings.mm b/beast/module/core/native/mac_Strings.mm index 5c80696a9d..9c444f6646 100644 --- a/beast/module/core/native/mac_Strings.mm +++ b/beast/module/core/native/mac_Strings.mm @@ -24,25 +24,6 @@ namespace beast { -String String::fromCFString (CFStringRef cfString) -{ - if (cfString == 0) - return String::empty; - - CFRange range = { 0, CFStringGetLength (cfString) }; - HeapBlock u ((size_t) range.length + 1); - CFStringGetCharacters (cfString, range, u); - u[range.length] = 0; - - return String (CharPointer_UTF16 ((const CharPointer_UTF16::CharType*) u.getData())); -} - -CFStringRef String::toCFString() const -{ - CharPointer_UTF16 utf16 (toUTF16()); - return CFStringCreateWithCharacters (kCFAllocatorDefault, (const UniChar*) utf16.getAddress(), (CFIndex) utf16.length()); -} - String String::convertToPrecomposedUnicode() const { #if BEAST_IOS diff --git a/beast/module/core/native/mac_SystemStats.mm b/beast/module/core/native/mac_SystemStats.mm index e2b2495c52..cfb9684752 100644 --- a/beast/module/core/native/mac_SystemStats.mm +++ b/beast/module/core/native/mac_SystemStats.mm @@ -62,7 +62,24 @@ static RLimitInitialiser rLimitInitialiser; #endif //============================================================================== -std::string SystemStats::getComputerName() +bool beast_isRunningUnderDebugger() +{ + static char testResult = 0; + + if (testResult == 0) + { + struct kinfo_proc info; + int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; + size_t sz = sizeof (info); + sysctl (m, 4, &info, &sz, 0, 0); + testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1; + } + + return testResult > 0; +} + +//============================================================================== +std::string getComputerName() { char name [256] = { 0 }; if (gethostname (name, sizeof (name) - 1) == 0) @@ -71,56 +88,4 @@ std::string SystemStats::getComputerName() return std::string{}; } -//============================================================================== -class HiResCounterHandler -{ -public: - HiResCounterHandler() - { - mach_timebase_info_data_t timebase; - (void) mach_timebase_info (&timebase); - - if (timebase.numer % 1000000 == 0) - { - numerator = timebase.numer / 1000000; - denominator = timebase.denom; - } - else - { - numerator = timebase.numer; - denominator = timebase.denom * (std::uint64_t) 1000000; - } - - highResTimerFrequency = (timebase.denom * (std::uint64_t) 1000000000) / timebase.numer; - highResTimerToMillisecRatio = numerator / (double) denominator; - } - - inline std::uint32_t millisecondsSinceStartup() const noexcept - { - return (std::uint32_t) ((mach_absolute_time() * numerator) / denominator); - } - - inline double getMillisecondCounterHiRes() const noexcept - { - return mach_absolute_time() * highResTimerToMillisecRatio; - } - - std::int64_t highResTimerFrequency; - -private: - std::uint64_t numerator, denominator; - double highResTimerToMillisecRatio; -}; - -static HiResCounterHandler& hiResCounterHandler() -{ - static HiResCounterHandler hiResCounterHandler; - return hiResCounterHandler; -} - -std::uint32_t beast_millisecondsSinceStartup() noexcept { return hiResCounterHandler().millisecondsSinceStartup(); } -double Time::getMillisecondCounterHiRes() noexcept { return hiResCounterHandler().getMillisecondCounterHiRes(); } -std::int64_t Time::getHighResolutionTicksPerSecond() noexcept { return hiResCounterHandler().highResTimerFrequency; } -std::int64_t Time::getHighResolutionTicks() noexcept { return (std::int64_t) mach_absolute_time(); } - } // beast diff --git a/beast/module/core/native/mac_Threads.mm b/beast/module/core/native/mac_Threads.mm deleted file mode 100644 index 5478628228..0000000000 --- a/beast/module/core/native/mac_Threads.mm +++ /dev/null @@ -1,48 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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. -*/ -//============================================================================== - -namespace beast -{ -//============================================================================== -bool beast_isRunningUnderDebugger() -{ - static char testResult = 0; - - if (testResult == 0) - { - struct kinfo_proc info; - int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; - size_t sz = sizeof (info); - sysctl (m, 4, &info, &sz, 0, 0); - testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1; - } - - return testResult > 0; -} - -bool Process::isRunningUnderDebugger() -{ - return beast_isRunningUnderDebugger(); -} - -} // beast diff --git a/beast/module/core/native/osx_ObjCHelpers.h b/beast/module/core/native/osx_ObjCHelpers.h index 8503932bdc..9d6d4c4ce1 100644 --- a/beast/module/core/native/osx_ObjCHelpers.h +++ b/beast/module/core/native/osx_ObjCHelpers.h @@ -54,104 +54,6 @@ namespace } } -//============================================================================== -template -struct NSObjectRetainer -{ - inline NSObjectRetainer (ObjectType* o) : object (o) { [object retain]; } - inline ~NSObjectRetainer() { [object release]; } - - ObjectType* object; -}; - -//============================================================================== -template -struct ObjCClass -{ - ObjCClass (const char* nameRoot) - : cls (objc_allocateClassPair ([SuperclassType class], getRandomisedName (nameRoot).toUTF8(), 0)) - { - } - - ObjCClass (ObjCClass const&); - ObjCClass& operator= (ObjCClass const&); - - ~ObjCClass() - { - objc_disposeClassPair (cls); - } - - void registerClass() - { - objc_registerClassPair (cls); - } - - SuperclassType* createInstance() const - { - return class_createInstance (cls, 0); - } - - template - void addIvar (const char* name) - { - BOOL b = class_addIvar (cls, name, sizeof (Type), (uint8_t) rint (log2 (sizeof (Type))), @encode (Type)); - bassert (b); (void) b; - } - - template - void addMethod (SEL selector, FunctionType callbackFn, const char* signature) - { - BOOL b = class_addMethod (cls, selector, (IMP) callbackFn, signature); - bassert (b); (void) b; - } - - template - void addMethod (SEL selector, FunctionType callbackFn, const char* sig1, const char* sig2) - { - addMethod (selector, callbackFn, (String (sig1) + sig2).toUTF8()); - } - - template - void addMethod (SEL selector, FunctionType callbackFn, const char* sig1, const char* sig2, const char* sig3) - { - addMethod (selector, callbackFn, (String (sig1) + sig2 + sig3).toUTF8()); - } - - template - void addMethod (SEL selector, FunctionType callbackFn, const char* sig1, const char* sig2, const char* sig3, const char* sig4) - { - addMethod (selector, callbackFn, (String (sig1) + sig2 + sig3 + sig4).toUTF8()); - } - - void addProtocol (Protocol* protocol) - { - BOOL b = class_addProtocol (cls, protocol); - bassert (b); (void) b; - } - - static id sendSuperclassMessage (id self, SEL selector) - { - objc_super s = { self, [SuperclassType class] }; - return objc_msgSendSuper (&s, selector); - } - - template - static Type getIvar (id self, const char* name) - { - void* v = nullptr; - object_getInstanceVariable (self, name, &v); - return static_cast (v); - } - - Class cls; - -private: - static String getRandomisedName (const char* root) - { - return root + String::toHexString (beast::Random::getSystemRandom().nextInt64()); - } -}; - } // beast #endif // BEAST_OSX_OBJCHELPERS_H_INCLUDED diff --git a/beast/module/core/native/posix_SharedCode.h b/beast/module/core/native/posix_SharedCode.h index c1d18bce19..11594f998d 100644 --- a/beast/module/core/native/posix_SharedCode.h +++ b/beast/module/core/native/posix_SharedCode.h @@ -21,6 +21,9 @@ */ //============================================================================== +#ifndef BEAST_MODULE_CORE_NATIVE_POSIX_SHAREDCODE_H_INCLUDED +#define BEAST_MODULE_CORE_NATIVE_POSIX_SHAREDCODE_H_INCLUDED + namespace beast { @@ -41,21 +44,6 @@ void CriticalSection::enter() const noexcept { pthread_mutex_lock (&mutex); } bool CriticalSection::tryEnter() const noexcept { return pthread_mutex_trylock (&mutex) == 0; } void CriticalSection::exit() const noexcept { pthread_mutex_unlock (&mutex); } -//============================================================================== - -void Process::terminate() -{ -#ifndef BEAST_MODULE_CORE_NATIVE_POSIX_SHAREDCODE_H_INCLUDED -#define BEAST_MODULE_CORE_NATIVE_POSIX_SHAREDCODE_H_INCLUDED - -#if BEAST_ANDROID || BEAST_BSD - // http://www.unix.com/man-page/FreeBSD/2/_exit/ - ::_exit (EXIT_FAILURE); -#else - std::_Exit (EXIT_FAILURE); -#endif -} - //============================================================================== const beast_wchar File::separator = '/'; const String File::separatorString ("/"); @@ -79,26 +67,6 @@ File File::getCurrentWorkingDirectory() return File (CharPointer_UTF8 (cwd)); } -bool File::setAsCurrentWorkingDirectory() const -{ - return chdir (getFullPathName().toUTF8()) == 0; -} - -//============================================================================== -// The unix siginterrupt function is deprecated - this does the same job. -int beast_siginterrupt (int sig, int flag) -{ - struct ::sigaction act; - (void) ::sigaction (sig, nullptr, &act); - - if (flag != 0) - act.sa_flags &= ~SA_RESTART; - else - act.sa_flags |= SA_RESTART; - - return ::sigaction (sig, &act, nullptr); -} - //============================================================================== namespace { @@ -189,65 +157,6 @@ std::int64_t File::getSize() const } //============================================================================== -bool File::hasWriteAccess() const -{ - if (exists()) - return access (fullPath.toUTF8(), W_OK) == 0; - - if ((! isDirectory()) && fullPath.containsChar (separator)) - return getParentDirectory().hasWriteAccess(); - - return false; -} - -bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const -{ - beast_statStruct info; - if (! beast_stat (fullPath, info)) - return false; - - info.st_mode &= 0777; // Just permissions - - if (shouldBeReadOnly) - info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); - else - // Give everybody write permission? - info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; - - return chmod (fullPath.toUTF8(), info.st_mode) == 0; -} - -void File::getFileTimesInternal (std::int64_t& modificationTime, std::int64_t& accessTime, std::int64_t& creationTime) const -{ - modificationTime = 0; - accessTime = 0; - creationTime = 0; - - beast_statStruct info; - if (beast_stat (fullPath, info)) - { - modificationTime = (std::int64_t) info.st_mtime * 1000; - accessTime = (std::int64_t) info.st_atime * 1000; - creationTime = (std::int64_t) info.st_ctime * 1000; - } -} - -bool File::setFileTimesInternal (std::int64_t modificationTime, std::int64_t accessTime, std::int64_t /*creationTime*/) const -{ - beast_statStruct info; - - if ((modificationTime != 0 || accessTime != 0) && beast_stat (fullPath, info)) - { - struct utimbuf times; - times.actime = accessTime != 0 ? (time_t) (accessTime / 1000) : info.st_atime; - times.modtime = modificationTime != 0 ? (time_t) (modificationTime / 1000) : info.st_mtime; - - return utime (fullPath.toUTF8(), ×) == 0; - } - - return false; -} - bool File::deleteFile() const { if (! exists()) @@ -259,22 +168,6 @@ bool File::deleteFile() const return remove (fullPath.toUTF8()) == 0; } -bool File::moveInternal (const File& dest) const -{ - if (rename (fullPath.toUTF8(), dest.getFullPathName().toUTF8()) == 0) - return true; - - if (hasWriteAccess() && copyInternal (dest)) - { - if (deleteFile()) - return true; - - dest.deleteFile(); - } - - return false; -} - Result File::createDirectoryInternal (const String& fileName) const { return getResultForReturnValue (mkdir (fileName.toUTF8(), 0777)); @@ -442,24 +335,5 @@ File beast_getExecutableFile() #endif } -//============================================================================== -std::int64_t File::getBytesFreeOnVolume() const -{ - struct statfs buf; - if (beast_doStatFS (*this, buf)) - return (std::int64_t) buf.f_bsize * (std::int64_t) buf.f_bavail; // Note: this returns space available to non-super user - - return 0; -} - -std::int64_t File::getVolumeTotalSize() const -{ - struct statfs buf; - if (beast_doStatFS (*this, buf)) - return (std::int64_t) buf.f_bsize * (std::int64_t) buf.f_blocks; - - return 0; -} - } // beast #endif diff --git a/beast/module/core/native/win32_Files.cpp b/beast/module/core/native/win32_Files.cpp index f4748d3757..bc29abebc1 100644 --- a/beast/module/core/native/win32_Files.cpp +++ b/beast/module/core/native/win32_Files.cpp @@ -69,17 +69,6 @@ namespace WindowsFileHelpers return path; } - std::int64_t getDiskSpaceInfo (const String& path, const bool total) - { - ULARGE_INTEGER spc, tot, totFree; - - if (GetDiskFreeSpaceEx (getDriveFromPath (path).toWideCharPointer(), &spc, &tot, &totFree)) - return total ? (std::int64_t) tot.QuadPart - : (std::int64_t) spc.QuadPart; - - return 0; - } - unsigned int getWindowsDriveType (const String& path) { return GetDriveType (getDriveFromPath (path).toWideCharPointer()); @@ -139,29 +128,6 @@ bool File::isDirectory() const return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES); } -bool File::hasWriteAccess() const -{ - if (exists()) - return (WindowsFileHelpers::getAtts (fullPath) & FILE_ATTRIBUTE_READONLY) == 0; - - // on windows, it seems that even read-only directories can still be written into, - // so checking the parent directory's permissions would return the wrong result.. - return true; -} - -bool File::setFileReadOnlyInternal (const bool shouldBeReadOnly) const -{ - const DWORD oldAtts = WindowsFileHelpers::getAtts (fullPath); - - if (oldAtts == INVALID_FILE_ATTRIBUTES) - return false; - - const DWORD newAtts = shouldBeReadOnly ? (oldAtts | FILE_ATTRIBUTE_READONLY) - : (oldAtts & ~FILE_ATTRIBUTE_READONLY); - return newAtts == oldAtts - || SetFileAttributes (fullPath.toWideCharPointer(), newAtts) != FALSE; -} - //============================================================================== bool File::deleteFile() const { @@ -172,16 +138,6 @@ bool File::deleteFile() const : DeleteFile (fullPath.toWideCharPointer()) != 0; } -bool File::copyInternal (const File& dest) const -{ - return CopyFile (fullPath.toWideCharPointer(), dest.getFullPathName().toWideCharPointer(), false) != 0; -} - -bool File::moveInternal (const File& dest) const -{ - return MoveFile (fullPath.toWideCharPointer(), dest.getFullPathName().toWideCharPointer()) != 0; -} - Result File::createDirectoryInternal (const String& fileName) const { return CreateDirectory (fileName.toWideCharPointer(), 0) ? Result::ok() @@ -298,57 +254,6 @@ std::int64_t File::getSize() const return 0; } -void File::getFileTimesInternal (std::int64_t& modificationTime, std::int64_t& accessTime, std::int64_t& creationTime) const -{ - using namespace WindowsFileHelpers; - WIN32_FILE_ATTRIBUTE_DATA attributes; - - if (GetFileAttributesEx (fullPath.toWideCharPointer(), GetFileExInfoStandard, &attributes)) - { - modificationTime = fileTimeToTime (&attributes.ftLastWriteTime); - creationTime = fileTimeToTime (&attributes.ftCreationTime); - accessTime = fileTimeToTime (&attributes.ftLastAccessTime); - } - else - { - creationTime = accessTime = modificationTime = 0; - } -} - -bool File::setFileTimesInternal (std::int64_t modificationTime, std::int64_t accessTime, std::int64_t creationTime) const -{ - using namespace WindowsFileHelpers; - - bool ok = false; - HANDLE h = CreateFile (fullPath.toWideCharPointer(), GENERIC_WRITE, FILE_SHARE_READ, 0, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - if (h != INVALID_HANDLE_VALUE) - { - FILETIME m, a, c; - - ok = SetFileTime (h, - timeToFileTime (creationTime, &c), - timeToFileTime (accessTime, &a), - timeToFileTime (modificationTime, &m)) != 0; - - CloseHandle (h); - } - - return ok; -} - -//============================================================================== -std::int64_t File::getBytesFreeOnVolume() const -{ - return WindowsFileHelpers::getDiskSpaceInfo (getFullPathName(), false); -} - -std::int64_t File::getVolumeTotalSize() const -{ - return WindowsFileHelpers::getDiskSpaceInfo (getFullPathName(), true); -} - //============================================================================== File File::getSpecialLocation (const SpecialLocationType type) { @@ -392,11 +297,6 @@ File File::getCurrentWorkingDirectory() return File (String (dest)); } -bool File::setAsCurrentWorkingDirectory() const -{ - return SetCurrentDirectory (getFullPathName().toWideCharPointer()) != FALSE; -} - //============================================================================== class DirectoryIterator::NativeIterator::Pimpl { diff --git a/beast/module/core/native/win32_SystemStats.cpp b/beast/module/core/native/win32_SystemStats.cpp index 49d32eae52..09f936b154 100644 --- a/beast/module/core/native/win32_SystemStats.cpp +++ b/beast/module/core/native/win32_SystemStats.cpp @@ -30,66 +30,13 @@ void outputDebugString (std::string const& text) } //============================================================================== -std::uint32_t beast_millisecondsSinceStartup() noexcept +bool beast_isRunningUnderDebugger() { - return (std::uint32_t) timeGetTime(); + return IsDebuggerPresent() != FALSE; } //============================================================================== -class HiResCounterHandler -{ -public: - HiResCounterHandler() - : hiResTicksOffset (0) - { - const MMRESULT res = timeBeginPeriod (1); - (void) res; - bassert (res == TIMERR_NOERROR); - - LARGE_INTEGER f; - QueryPerformanceFrequency (&f); - hiResTicksPerSecond = f.QuadPart; - hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond; - } - - inline std::int64_t getHighResolutionTicks() noexcept - { - LARGE_INTEGER ticks; - QueryPerformanceCounter (&ticks); - - const std::int64_t mainCounterAsHiResTicks = (beast_millisecondsSinceStartup() * hiResTicksPerSecond) / 1000; - const std::int64_t newOffset = mainCounterAsHiResTicks - ticks.QuadPart; - - std::int64_t offsetDrift = newOffset - hiResTicksOffset; - - // fix for a very obscure PCI hardware bug that can make the counter - // sometimes jump forwards by a few seconds.. - if (offsetDrift < 0) - offsetDrift = -offsetDrift; - - if (offsetDrift > (hiResTicksPerSecond >> 1)) - hiResTicksOffset = newOffset; - - return ticks.QuadPart + hiResTicksOffset; - } - - inline double getMillisecondCounterHiRes() noexcept - { - return getHighResolutionTicks() * hiResTicksScaleFactor; - } - - std::int64_t hiResTicksPerSecond, hiResTicksOffset; - double hiResTicksScaleFactor; -}; - -static HiResCounterHandler hiResCounterHandler; - -std::int64_t Time::getHighResolutionTicksPerSecond() noexcept { return hiResCounterHandler.hiResTicksPerSecond; } -std::int64_t Time::getHighResolutionTicks() noexcept { return hiResCounterHandler.getHighResolutionTicks(); } -double Time::getMillisecondCounterHiRes() noexcept { return hiResCounterHandler.getMillisecondCounterHiRes(); } - -//============================================================================== -std::string SystemStats::getComputerName() +std::string getComputerName() { char text [MAX_COMPUTERNAME_LENGTH + 2] = { 0 }; DWORD len = MAX_COMPUTERNAME_LENGTH + 1; diff --git a/beast/module/core/native/win32_Threads.cpp b/beast/module/core/native/win32_Threads.cpp index 0c91b0c909..9a8c5bb888 100644 --- a/beast/module/core/native/win32_Threads.cpp +++ b/beast/module/core/native/win32_Threads.cpp @@ -76,28 +76,4 @@ void CriticalSection::enter() const noexcept { EnterCriticalSection ((CRITICAL_S bool CriticalSection::tryEnter() const noexcept { return TryEnterCriticalSection ((CRITICAL_SECTION*) section) != FALSE; } void CriticalSection::exit() const noexcept { LeaveCriticalSection ((CRITICAL_SECTION*) section); } -//============================================================================== -bool beast_isRunningUnderDebugger() -{ - return IsDebuggerPresent() != FALSE; -} - -bool Process::isRunningUnderDebugger() -{ - return beast_isRunningUnderDebugger(); -} - -//------------------------------------------------------------------------------ -void Process::terminate() -{ - #if BEAST_MSVC && BEAST_CHECK_MEMORY_LEAKS - _CrtDumpMemoryLeaks(); - #endif - - // bullet in the head in case there's a problem shutting down.. - ExitProcess (0); -} - -//============================================================================== - } // beast diff --git a/beast/module/core/streams/FileInputSource.cpp b/beast/module/core/streams/FileInputSource.cpp deleted file mode 100644 index 2602febdc7..0000000000 --- a/beast/module/core/streams/FileInputSource.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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. -*/ -//============================================================================== - -namespace beast -{ - -FileInputSource::FileInputSource (const File& f, bool useFileTimeInHash) - : file (f), useFileTimeInHashGeneration (useFileTimeInHash) -{ -} - -FileInputSource::~FileInputSource() -{ -} - -InputStream* FileInputSource::createInputStream() -{ - return file.createInputStream(); -} - -InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath) -{ - return file.getSiblingFile (relatedItemPath).createInputStream(); -} - -std::int64_t FileInputSource::hashCode() const -{ - std::int64_t h = file.hashCode(); - - if (useFileTimeInHashGeneration) - h ^= file.getLastModificationTime().toMilliseconds(); - - return h; -} - -} // beast diff --git a/beast/module/core/streams/FileInputSource.h b/beast/module/core/streams/FileInputSource.h deleted file mode 100644 index 5e35312b4a..0000000000 --- a/beast/module/core/streams/FileInputSource.h +++ /dev/null @@ -1,66 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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_MODULE_CORE_STREAMS_FILEINPUTSOURCE_H_INCLUDED -#define BEAST_MODULE_CORE_STREAMS_FILEINPUTSOURCE_H_INCLUDED - -namespace beast -{ - -//============================================================================== -/** - A type of InputSource that represents a normal file. - - @see InputSource -*/ -class FileInputSource - : public InputSource -{ -public: - //============================================================================== - /** Creates a FileInputSource for a file. - If the useFileTimeInHashGeneration parameter is true, then this object's - hashCode() method will incorporate the file time into its hash code; if - false, only the file name will be used for the hash. - */ - FileInputSource (const File& file, bool useFileTimeInHashGeneration = false); - - FileInputSource (FileInputSource const&) = delete; - FileInputSource& operator= (FileInputSource const&) = delete; - - /** Destructor. */ - ~FileInputSource(); - - InputStream* createInputStream(); - InputStream* createInputStreamFor (const String& relatedItemPath); - std::int64_t hashCode() const; - -private: - //============================================================================== - const File file; - bool useFileTimeInHashGeneration; -}; - -} // beast - -#endif // BEAST_FILEINPUTSOURCE_H_INCLUDED diff --git a/beast/module/core/streams/InputSource.h b/beast/module/core/streams/InputSource.h index cf39bf9bb7..5880c400ee 100644 --- a/beast/module/core/streams/InputSource.h +++ b/beast/module/core/streams/InputSource.h @@ -33,8 +33,6 @@ namespace beast This may be used to refer to a file, or some other kind of source, allowing a caller to create an input stream that can read from it when required. - - @see FileInputSource */ class InputSource { diff --git a/beast/module/core/system/SystemStats.cpp b/beast/module/core/system/SystemStats.cpp index 0a121402e4..4f95ea1933 100644 --- a/beast/module/core/system/SystemStats.cpp +++ b/beast/module/core/system/SystemStats.cpp @@ -42,18 +42,9 @@ static_assert (sizeof (std::uint64_t) == 8, "std::uint64_t must be exactly 8 byt namespace beast { - -std::string -SystemStats::getBeastVersion() -{ - return "Beast v" + std::to_string (BEAST_MAJOR_VERSION) + - "." + std::to_string (BEAST_MINOR_VERSION) + - "." + std::to_string (BEAST_BUILDNUMBER); -} - //============================================================================== std::vector -SystemStats::getStackBacktrace() +getStackBacktrace() { std::vector result; @@ -121,41 +112,4 @@ SystemStats::getStackBacktrace() return result; } -//============================================================================== -static SystemStats::CrashHandlerFunction globalCrashHandler = nullptr; - -#if BEAST_WINDOWS -static LONG WINAPI handleCrash (LPEXCEPTION_POINTERS) -{ - globalCrashHandler(); - return EXCEPTION_EXECUTE_HANDLER; -} -#else -static void handleCrash (int) -{ - globalCrashHandler(); - kill (getpid(), SIGKILL); -} - -int beast_siginterrupt (int sig, int flag); -#endif - -void SystemStats::setApplicationCrashHandler (CrashHandlerFunction handler) -{ - bassert (handler != nullptr); // This must be a valid function. - globalCrashHandler = handler; - - #if BEAST_WINDOWS - SetUnhandledExceptionFilter (handleCrash); - #else - const int signals[] = { SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGABRT, SIGSYS }; - - for (int i = 0; i < numElementsInArray (signals); ++i) - { - ::signal (signals[i], handleCrash); - beast_siginterrupt (signals[i], 1); - } - #endif -} - } // beast diff --git a/beast/module/core/system/SystemStats.h b/beast/module/core/system/SystemStats.h index 81e1ccf802..0e6bd8ae2a 100644 --- a/beast/module/core/system/SystemStats.h +++ b/beast/module/core/system/SystemStats.h @@ -28,40 +28,16 @@ namespace beast { //============================================================================== -/** - Contains methods for finding out about the current hardware and OS configuration. +/** Returns the host-name of the computer. */ +std::string getComputerName(); + +//============================================================================== +/** Returns a backtrace of the current call-stack. + The usefulness of the result will depend on the level of debug symbols + that are available in the executable. */ -namespace SystemStats -{ - //============================================================================== - /** Returns the current version of BEAST, - See also the BEAST_VERSION, BEAST_MAJOR_VERSION and BEAST_MINOR_VERSION macros. - */ - std::string getBeastVersion(); - - //============================================================================== - /** Returns the host-name of the computer. */ - std::string getComputerName(); - - //============================================================================== - /** Returns a backtrace of the current call-stack. - The usefulness of the result will depend on the level of debug symbols - that are available in the executable. - */ - std::vector - getStackBacktrace(); - - /** A void() function type, used by setApplicationCrashHandler(). */ - using CrashHandlerFunction = void (*)(); - - /** Sets up a global callback function that will be called if the application - executes some kind of illegal instruction. - - You may want to call getStackBacktrace() in your handler function, to find out - where the problem happened and log it, etc. - */ - void setApplicationCrashHandler (CrashHandlerFunction); -}; +std::vector +getStackBacktrace(); } // beast diff --git a/beast/module/core/threads/Process.h b/beast/module/core/threads/Process.h deleted file mode 100644 index 54a964af9d..0000000000 --- a/beast/module/core/threads/Process.h +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Portions of this file are from JUCE. - Copyright (c) 2013 - Raw Material Software Ltd. - Please visit http://www.juce.com - - 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_MODULE_CORE_THREADS_PROCESS_H_INCLUDED -#define BEAST_MODULE_CORE_THREADS_PROCESS_H_INCLUDED - -namespace beast { - -//============================================================================== -/** Represents the current executable's process. - - This contains methods for controlling the current application at the - process-level. - - @see Thread, BEASTApplication -*/ -namespace Process -{ - /** Kills the current process immediately. - - This is an emergency process terminator that kills the application - immediately - it's intended only for use only when something goes - horribly wrong. - - @see BEASTApplication::quit - */ - void terminate(); - - //============================================================================== - /** Returns true if this process is being hosted by a debugger. */ - bool isRunningUnderDebugger(); -}; - -} // beast - -#endif // BEAST_PROCESS_H_INCLUDED diff --git a/beast/module/core/time/AtExitHook.cpp b/beast/module/core/time/AtExitHook.cpp deleted file mode 100644 index 2ed6129f6e..0000000000 --- a/beast/module/core/time/AtExitHook.cpp +++ /dev/null @@ -1,140 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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. -*/ -//============================================================================== - -#include - -namespace beast { - -// Manages the list of hooks, and calls -// whoever is in the list at exit time. -// -class AtExitHook::Manager -{ -public: - Manager () - : m_didStaticDestruction (false) - { - } - - static inline Manager& get () - { - static beast::static_initializer< - Manager> instance; - return *instance; - } - - void insert (Item& item) - { - ScopedLockType lock (m_mutex); - - // Adding a new AtExitHook during or after the destruction - // of objects with static storage duration has taken place? - // Surely something has gone wrong. - // - bassert (! m_didStaticDestruction); - m_list.push_front (item); - } - - void erase (Item& item) - { - ScopedLockType lock (m_mutex); - - m_list.erase (m_list.iterator_to (item)); - } - -private: - // Called at program exit when destructors for objects - // with static storage duration are invoked. - // - void doStaticDestruction () - { - // In theory this shouldn't be needed (?) - ScopedLockType lock (m_mutex); - - bassert (! m_didStaticDestruction); - m_didStaticDestruction = true; - - for (List ::iterator iter (m_list.begin()); iter != m_list.end();) - { - Item& item (*iter++); - AtExitHook* const hook (item.hook ()); - hook->onExit (); - } - } - - struct StaticDestructor - { - ~StaticDestructor () - { - Manager::get().doStaticDestruction(); - } - }; - - using MutexType = CriticalSection; - using ScopedLockType = MutexType::ScopedLockType; - - static StaticDestructor s_staticDestructor; - - MutexType m_mutex; - List m_list; - bool m_didStaticDestruction; -}; - -// This is an object with static storage duration. -// When it gets destroyed, we will call into the Manager to -// call all of the AtExitHook items in the list. -// -AtExitHook::Manager::StaticDestructor AtExitHook::Manager::s_staticDestructor; - -//------------------------------------------------------------------------------ - -AtExitHook::Item::Item (AtExitHook* hook) - : m_hook (hook) -{ -} - -AtExitHook* AtExitHook::Item::hook () -{ - return m_hook; -} - -//------------------------------------------------------------------------------ - -AtExitHook::AtExitHook () - : m_item (this) -{ -#if BEAST_IOS - // Patrick Dehne: - // AtExitHook::Manager::insert crashes on iOS - // if the storage is not accessed before it is used. - // - // VFALCO TODO Figure out why and fix it cleanly if needed. - // - char* hack = AtExitHook::Manager::s_list.s_storage; -#endif - - Manager::get().insert (m_item); -} - -AtExitHook::~AtExitHook () -{ - Manager::get().erase (m_item); -} - -} // beast diff --git a/beast/module/core/time/AtExitHook.h b/beast/module/core/time/AtExitHook.h deleted file mode 100644 index 3d035df620..0000000000 --- a/beast/module/core/time/AtExitHook.h +++ /dev/null @@ -1,94 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_MODULE_CORE_TIME_ATEXITHOOK_H_INCLUDED -#define BEAST_MODULE_CORE_TIME_ATEXITHOOK_H_INCLUDED - -#include - -namespace beast { - -/** Hook for performing activity on program exit. - - These hooks execute when objects with static storage duration are - destroyed. The hooks are called in the reverse order that they were - created. - - To use, derive your class from AtExitHook and implement onExit. - Alternatively, add AtExitMemberHook as a data member of your class and - then provide your own onExit function with this signature: - - @code - - void onExit () - - @endcode - - @see AtExitMemberHook -*/ -/** @{ */ -class AtExitHook -{ -protected: - AtExitHook (); - virtual ~AtExitHook (); - -protected: - /** Called at program exit. */ - virtual void onExit () = 0; - -private: - class Manager; - - class Item : public List ::Node - { - public: - explicit Item (AtExitHook* hook); - AtExitHook* hook (); - - private: - AtExitHook* m_hook; - }; - - Item m_item; -}; - -/** Helper for utilizing the AtExitHook as a data member. -*/ -template -class AtExitMemberHook : public AtExitHook -{ -public: - explicit AtExitMemberHook (Object* owner) : m_owner (owner) - { - } - -private: - void onExit () - { - m_owner->onExit (); - } - - Object* m_owner; -}; -/** @} */ - -} // beast - -#endif diff --git a/beast/module/core/time/Time.cpp b/beast/module/core/time/Time.cpp index 40b18aec04..649ffa03af 100644 --- a/beast/module/core/time/Time.cpp +++ b/beast/module/core/time/Time.cpp @@ -116,8 +116,6 @@ namespace TimeHelpers StringType (buffer) + (int) numChars); } } - - static std::uint32_t lastMSCounterValue = 0; } //============================================================================== @@ -216,48 +214,6 @@ Time Time::getCurrentTime() noexcept return Time (currentTimeMillis()); } -//============================================================================== -std::uint32_t beast_millisecondsSinceStartup() noexcept; - -std::uint32_t Time::getMillisecondCounter() noexcept -{ - const std::uint32_t now = beast_millisecondsSinceStartup(); - - if (now < TimeHelpers::lastMSCounterValue) - { - // in multi-threaded apps this might be called concurrently, so - // make sure that our last counter value only increases and doesn't - // go backwards.. - if (now < TimeHelpers::lastMSCounterValue - 1000) - TimeHelpers::lastMSCounterValue = now; - } - else - { - TimeHelpers::lastMSCounterValue = now; - } - - return now; -} - -std::uint32_t Time::getApproximateMillisecondCounter() noexcept -{ - if (TimeHelpers::lastMSCounterValue == 0) - getMillisecondCounter(); - - return TimeHelpers::lastMSCounterValue; -} - -//============================================================================== -double Time::highResolutionTicksToSeconds (const std::int64_t ticks) noexcept -{ - return ticks / (double) getHighResolutionTicksPerSecond(); -} - -std::int64_t Time::secondsToHighResolutionTicks (const double seconds) noexcept -{ - return (std::int64_t) (seconds * (double) getHighResolutionTicksPerSecond()); -} - //============================================================================== String Time::toString (const bool includeDate, const bool includeTime, diff --git a/beast/module/core/time/Time.h b/beast/module/core/time/Time.h index 0f779f440a..425c78d3ed 100644 --- a/beast/module/core/time/Time.h +++ b/beast/module/core/time/Time.h @@ -301,75 +301,6 @@ public: */ static std::int64_t currentTimeMillis() noexcept; - /** Returns the number of millisecs since a fixed event (usually system startup). - - This returns a monotonically increasing value which it unaffected by changes to the - system clock. It should be accurate to within a few millisecs, depending on platform, - hardware, etc. - - Being a 32-bit return value, it will of course wrap back to 0 after 2^32 seconds of - uptime, so be careful to take that into account. If you need a 64-bit time, you can - use currentTimeMillis() instead. - - @see getApproximateMillisecondCounter - */ - static std::uint32_t getMillisecondCounter() noexcept; - - /** Returns the number of millisecs since a fixed event (usually system startup). - - This has the same function as getMillisecondCounter(), but returns a more accurate - value, using a higher-resolution timer if one is available. - - @see getMillisecondCounter - */ - static double getMillisecondCounterHiRes() noexcept; - - /** Less-accurate but faster version of getMillisecondCounter(). - - This will return the last value that getMillisecondCounter() returned, so doesn't - need to make a system call, but is less accurate - it shouldn't be more than - 100ms away from the correct time, though, so is still accurate enough for a - lot of purposes. - - @see getMillisecondCounter - */ - static std::uint32_t getApproximateMillisecondCounter() noexcept; - - //============================================================================== - // High-resolution timers.. - - /** Returns the current high-resolution counter's tick-count. - - This is a similar idea to getMillisecondCounter(), but with a higher - resolution. - - @see getHighResolutionTicksPerSecond, highResolutionTicksToSeconds, - secondsToHighResolutionTicks - */ - static std::int64_t getHighResolutionTicks() noexcept; - - /** Returns the resolution of the high-resolution counter in ticks per second. - - @see getHighResolutionTicks, highResolutionTicksToSeconds, - secondsToHighResolutionTicks - */ - static std::int64_t getHighResolutionTicksPerSecond() noexcept; - - /** Converts a number of high-resolution ticks into seconds. - - @see getHighResolutionTicks, getHighResolutionTicksPerSecond, - secondsToHighResolutionTicks - */ - static double highResolutionTicksToSeconds (std::int64_t ticks) noexcept; - - /** Converts a number seconds into high-resolution ticks. - - @see getHighResolutionTicks, getHighResolutionTicksPerSecond, - highResolutionTicksToSeconds - */ - static std::int64_t secondsToHighResolutionTicks (double seconds) noexcept; - - private: //============================================================================== std::int64_t millisSinceEpoch; diff --git a/beast/strings/String.h b/beast/strings/String.h index bad0fdc677..9cd20b8c7f 100644 --- a/beast/strings/String.h +++ b/beast/strings/String.h @@ -1201,15 +1201,6 @@ public: //============================================================================== #if BEAST_MAC || BEAST_IOS || DOXYGEN - /** MAC ONLY - Creates a String from an OSX CFString. */ - static String fromCFString (CFStringRef cfString); - - /** MAC ONLY - Converts this string to a CFString. - Remember that you must use CFRelease() to free the returned string when you're - finished with it. - */ - CFStringRef toCFString() const; - /** MAC ONLY - Returns a copy of this string in which any decomposed unicode characters have been converted to their precomposed equivalents. */ String convertToPrecomposedUnicode() const; diff --git a/beast/threads/detail/BindHandler.h b/beast/threads/detail/BindHandler.h deleted file mode 100644 index aa0fd38e38..0000000000 --- a/beast/threads/detail/BindHandler.h +++ /dev/null @@ -1,276 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_THREADS_DETAIL_BINDHANDLER_H_INCLUDED -#define BEAST_THREADS_DETAIL_BINDHANDLER_H_INCLUDED - -namespace beast { -namespace detail { - -/** Overloaded function that re-binds arguments to a handler. */ -/** @{ */ -template -class BindHandler1 -{ -private: - Handler handler; - P1 p1; - -public: - BindHandler1 (Handler const& handler_, P1 const& p1_) - : handler (handler_) - , p1 (p1_) - { } - - BindHandler1 (Handler& handler_, P1 const& p1_) - : handler (BEAST_MOVE_CAST(Handler)(handler_)) - , p1 (p1_) - { } - - void operator()() - { - handler ( - static_cast (p1) - ); - } - - void operator()() const - { - handler (p1); - } -}; - -template -BindHandler1 bindHandler (Handler handler, P1 const& p1) -{ - return BindHandler1 (handler, p1); -} - -//------------------------------------------------------------------------------ - -template -class BindHandler2 -{ -private: - Handler handler; - P1 p1; P2 p2; - -public: - BindHandler2 (Handler const& handler_, - P1 const& p1_, P2 const& p2_) - : handler (handler_) - , p1 (p1_), p2 (p2_) - { } - - BindHandler2 (Handler& handler_, - P1 const& p1_, P2 const& p2_) - : handler (BEAST_MOVE_CAST(Handler)(handler_)) - , p1 (p1_), p2 (p2_) - { } - - void operator()() - { - handler ( - static_cast (p1), static_cast (p2)); - } - - void operator()() const - { handler (p1, p2); } -}; - -template -BindHandler2 bindHandler (Handler handler, - P1 const& p1, P2 const& p2) -{ - return BindHandler2 ( - handler, p1, p2); -} - -//------------------------------------------------------------------------------ - -template -class BindHandler3 -{ -private: - Handler handler; - P1 p1; P2 p2; P3 p3; - -public: - BindHandler3 (Handler const& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_) - : handler (handler_) - , p1 (p1_), p2 (p2_), p3 (p3_) - { } - - BindHandler3 (Handler& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_) - : handler (BEAST_MOVE_CAST(Handler)(handler_)) - , p1 (p1_), p2 (p2_), p3 (p3_) - { } - - void operator()() - { - handler ( - static_cast (p1), static_cast (p2), static_cast (p3)); - } - - void operator()() const - { handler (p1, p2, p3); } -}; - -template -BindHandler3 bindHandler (Handler handler, - P1 const& p1, P2 const& p2, P3 const& p3) -{ - return BindHandler3 ( - handler, p1, p2, p3); -} - -//------------------------------------------------------------------------------ - -template -class BindHandler4 -{ -private: - Handler handler; - P1 p1; P2 p2; P3 p3; P4 p4; - -public: - BindHandler4 (Handler const& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_, P4 const& p4_) - : handler (handler_) - , p1 (p1_), p2 (p2_), p3 (p3_), p4 (p4_) - { } - - BindHandler4 (Handler& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_, P4 const& p4_) - : handler (BEAST_MOVE_CAST(Handler)(handler_)) - , p1 (p1_), p2 (p2_), p3 (p3_), p4 (p4_) - { } - - void operator()() - { - handler ( - static_cast (p1), static_cast (p2), static_cast (p3), - static_cast (p4) - ); - } - - void operator()() const - { handler (p1, p2, p3, p4); } -}; - -template -BindHandler4 bindHandler (Handler handler, - P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4) -{ - return BindHandler4 ( - handler, p1, p2, p3, p4); -} - -//------------------------------------------------------------------------------ - -template -class BindHandler5 -{ -private: - Handler handler; - P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; - -public: - BindHandler5 (Handler const& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_, P4 const& p4_, P5 const& p5_) - : handler (handler_) - , p1 (p1_), p2 (p2_), p3 (p3_), p4 (p4_), p5 (p5_) - { } - - BindHandler5 (Handler& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_, P4 const& p4_, P5 const& p5_) - : handler (BEAST_MOVE_CAST(Handler)(handler_)) - , p1 (p1_), p2 (p2_), p3 (p3_), p4 (p4_), p5 (p5_) - { } - - void operator()() - { - handler ( - static_cast (p1), static_cast (p2), static_cast (p3), - static_cast (p4), static_cast (p5) - ); - } - - void operator()() const - { handler (p1, p2, p3, p4, p5); } -}; - -template -BindHandler5 bindHandler (Handler handler, - P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5) -{ - return BindHandler5 ( - handler, p1, p2, p3, p4, p5); -} - -//------------------------------------------------------------------------------ - -template -class BindHandler6 -{ -private: - Handler handler; - P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; - -public: - BindHandler6 (Handler const& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_, P4 const& p4_, P5 const& p5_, P6 const& p6_) - : handler (handler_) - , p1 (p1_), p2 (p2_), p3 (p3_), p4 (p4_), p5 (p5_), p6 (p6_) - { } - - BindHandler6 (Handler& handler_, - P1 const& p1_, P2 const& p2_, P3 const& p3_, P4 const& p4_, P5 const& p5_, P6 const& p6_) - : handler (BEAST_MOVE_CAST(Handler)(handler_)) - , p1 (p1_), p2 (p2_), p3 (p3_), p4 (p4_), p5 (p5_), p6 (p6_) - { } - - void operator()() - { - handler ( - static_cast (p1), static_cast (p2), static_cast (p3), - static_cast (p4), static_cast (p5), static_cast (p6) - ); - } - - void operator()() const - { handler (p1, p2, p3, p4, p5, p6); } -}; - -template -BindHandler6 bindHandler (Handler handler, - P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4, P5 const& p5, P6 const& p6) -{ - return BindHandler6 ( - handler, p1, p2, p3, p4, p5, p6); -} - -/** @} */ - -} -} - -#endif diff --git a/beast/threads/detail/DispatchedHandler.h b/beast/threads/detail/DispatchedHandler.h deleted file mode 100644 index a18d51e409..0000000000 --- a/beast/threads/detail/DispatchedHandler.h +++ /dev/null @@ -1,173 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_THREADS_DETAIL_DISPATCHEDHANDLER_H_INCLUDED -#define BEAST_THREADS_DETAIL_DISPATCHEDHANDLER_H_INCLUDED - -#include - -namespace beast { -namespace detail { - -/** A wrapper that packages function call arguments into a dispatch. */ -template -class DispatchedHandler -{ -private: - Dispatcher m_dispatcher; - Handler m_handler; - -public: - using result_type = void; - - DispatchedHandler (Dispatcher dispatcher, Handler& handler) - : m_dispatcher (dispatcher) - , m_handler (BEAST_MOVE_CAST(Handler)(handler)) - { - } - -#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS - DispatchedHandler (DispatchedHandler const& other) - : m_dispatcher (other.m_dispatcher) - , m_handler (other.m_handler) - { - } - - DispatchedHandler (DispatchedHandler&& other) - : m_dispatcher (other.m_dispatcher) - , m_handler (BEAST_MOVE_CAST(Handler)(other.m_handler)) - { - } -#endif - - void operator()() - { - m_dispatcher.dispatch (m_handler); - } - - void operator()() const - { - m_dispatcher.dispatch (m_handler); - } - - template - void operator() (P1 const& p1) - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1)); - } - - template - void operator() (P1 const& p1) const - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1)); - } - - template - void operator() (P1 const& p1, P2 const& p2) - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2)); - } - - template - void operator() (P1 const& p1, P2 const& p2) const - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3) - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3) const - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4) - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3, p4)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4) const - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3, p4)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, - P4 const& p4, P5 const& p5) - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3, p4, p5)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, - P4 const& p4, P5 const& p5) const - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3, p4, p5)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, - P4 const& p4, P5 const& p5, P6 const& p6) - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3, p4, p5, p6)); - } - - template - void operator() (P1 const& p1, P2 const& p2, P3 const& p3, - P4 const& p4, P5 const& p5, P6 const& p6) const - { - m_dispatcher.dispatch ( - detail::bindHandler (m_handler, - p1, p2, p3, p4, p5, p6)); - } -}; - -} -} - -#endif diff --git a/beast/utility/Error.h b/beast/utility/Error.h deleted file mode 100644 index 2081eb8adb..0000000000 --- a/beast/utility/Error.h +++ /dev/null @@ -1,134 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_UTILITY_ERROR_H_INCLUDED -#define BEAST_UTILITY_ERROR_H_INCLUDED - -#include - -#include - -#include - -namespace beast { - -/** A concise error report. - - This lightweight but flexible class records lets you record the file and - line where a recoverable error occurred, along with some optional human - readable text. - - A recoverable error can be passed along and turned into a non recoverable - error by throwing the object: it's derivation from std::exception is - fully compliant with the C++ exception interface. - - @ingroup beast_core -*/ -class Error - : public std::exception -{ -public: - /** Numeric code. - - This enumeration is useful when the caller needs to take different - actions depending on the failure. For example, trying again later if - a file is locked. - */ - enum Code - { - success, //!< "the operation was successful" - - general, //!< "a general error occurred" - - canceled, //!< "the operation was canceled" - exception, //!< "an exception was thrown" - unexpected, //!< "an unexpected result was encountered" - platform, //!< "a system exception was signaled" - - noMemory, //!< "there was not enough memory" - noMoreData, //!< "the end of data was reached" - invalidData, //!< "the data is corrupt or invalid" - bufferSpace, //!< "the buffer is too small" - badParameter, //!< "one or more parameters were invalid" - assertFailed, //!< "an assertion failed" - - fileInUse, //!< "the file is in use" - fileExists, //!< "the file exists" - fileNoPerm, //!< "permission was denied" (file attributes conflict) - fileIOError, //!< "an I/O or device error occurred" - fileNoSpace, //!< "there is no space left on the device" - fileNotFound, //!< "the file was not found" - fileNameInvalid //!< "the file name was illegal or malformed" - }; - - Error (); - Error (Error const& other); - Error& operator= (Error const& other); - - virtual ~Error () noexcept; - - Code code () const; - bool failed () const; - - explicit operator bool () const - { - return code () != success; - } - - String const getReasonText () const; - String const getSourceFilename () const; - int getLineNumber () const; - - Error& fail (char const* sourceFileName, - int lineNumber, - String const reasonText, - Code errorCode = general); - - Error& fail (char const* sourceFileName, - int lineNumber, - Code errorCode = general); - - // A function that is capable of recovering from an error (for - // example, by performing a different action) can reset the - // object so it can be passed up. - void reset (); - - // Call this when reporting the error to clear the "checked" flag - void willBeReported () const; - - // for std::exception. This lets you throw an Error that should - // terminate the application. The what() message will be less - // descriptive so ideally you should catch the Error object instead. - char const* what () const noexcept; - - static String const getReasonTextForCode (Code code); - -private: - Code m_code; - String m_reasonText; - String m_sourceFileName; - int m_lineNumber; - mutable bool m_needsToBeChecked; - mutable String m_what; // created on demand - mutable char const* m_szWhat; -}; - -} - -#endif diff --git a/beast/utility/Utility.unity.cpp b/beast/utility/Utility.unity.cpp index ccf58e5b29..d4313c28af 100644 --- a/beast/utility/Utility.unity.cpp +++ b/beast/utility/Utility.unity.cpp @@ -21,8 +21,6 @@ #include #endif -#include - #include #include #include diff --git a/beast/utility/impl/Error.cpp b/beast/utility/impl/Error.cpp deleted file mode 100644 index 021a4b8389..0000000000 --- a/beast/utility/impl/Error.cpp +++ /dev/null @@ -1,259 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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. -*/ -//============================================================================== - -#include -#include - -#include - -// VFALCO TODO Localizable strings -#ifndef TRANS -#define TRANS(s) (s) -#define UNDEF_TRANS -#endif - -namespace beast { - -Error::Error () - : m_code (success) - , m_lineNumber (0) - , m_needsToBeChecked (true) - , m_szWhat (0) -{ -} - -Error::Error (Error const& other) - : m_code (other.m_code) - , m_reasonText (other.m_reasonText) - , m_sourceFileName (other.m_sourceFileName) - , m_lineNumber (other.m_lineNumber) - , m_needsToBeChecked (true) - , m_szWhat (0) -{ - other.m_needsToBeChecked = false; -} - -Error::~Error () noexcept -{ - /* If this goes off it means an error object was created but never tested */ - bassert (!m_needsToBeChecked); -} - -Error& Error::operator= (Error const& other) -{ - m_code = other.m_code; - m_reasonText = other.m_reasonText; - m_sourceFileName = other.m_sourceFileName; - m_lineNumber = other.m_lineNumber; - m_needsToBeChecked = true; - m_what = String::empty; - m_szWhat = 0; - - other.m_needsToBeChecked = false; - - return *this; -} - -Error::Code Error::code () const -{ - m_needsToBeChecked = false; - return m_code; -} - -bool Error::failed () const -{ - return code () != success; -} - -String const Error::getReasonText () const -{ - return m_reasonText; -} - -String const Error::getSourceFilename () const -{ - return m_sourceFileName; -} - -int Error::getLineNumber () const -{ - return m_lineNumber; -} - -Error& Error::fail (char const* sourceFileName, - int lineNumber, - String const reasonText, - Code errorCode) -{ - bassert (m_code == success); - bassert (errorCode != success); - - m_code = errorCode; - m_reasonText = reasonText; - m_sourceFileName = Debug::getFileNameFromPath (sourceFileName); - m_lineNumber = lineNumber; - m_needsToBeChecked = true; - - return *this; -} - -Error& Error::fail (char const* sourceFileName, - int lineNumber, - Code errorCode) -{ - return fail (sourceFileName, - lineNumber, - getReasonTextForCode (errorCode), - errorCode); -} - -void Error::reset () -{ - m_code = success; - m_reasonText = String::empty; - m_sourceFileName = String::empty; - m_lineNumber = 0; - m_needsToBeChecked = true; - m_what = String::empty; - m_szWhat = 0; -} - -void Error::willBeReported () const -{ - m_needsToBeChecked = false; -} - -char const* Error::what () const noexcept -{ - if (! m_szWhat) - { - // The application could not be initialized because sqlite was denied access permission - // The application unexpectedly quit because the exception 'sqlite was denied access permission at file ' was thrown - m_what << - m_reasonText << " " << - TRANS ("at file") << " '" << - m_sourceFileName << "' " << - TRANS ("line") << " " << - String (m_lineNumber) << " " << - TRANS ("with code") << " = " << - String (m_code); - - m_szWhat = (const char*)m_what.toUTF8 (); - } - - return m_szWhat; -} - -String const Error::getReasonTextForCode (Code code) -{ - String s; - - switch (code) - { - case success: - s = TRANS ("the operation was successful"); - break; - - case general: - s = TRANS ("a general error occurred"); - break; - - case canceled: - s = TRANS ("the operation was canceled"); - break; - - case exception: - s = TRANS ("an exception was thrown"); - break; - - case unexpected: - s = TRANS ("an unexpected result was encountered"); - break; - - case platform: - s = TRANS ("a system exception was signaled"); - break; - - case noMemory: - s = TRANS ("there was not enough memory"); - break; - - case noMoreData: - s = TRANS ("the end of data was reached"); - break; - - case invalidData: - s = TRANS ("the data is corrupt or invalid"); - break; - - case bufferSpace: - s = TRANS ("the buffer is too small"); - break; - - case badParameter: - s = TRANS ("one or more parameters were invalid"); - break; - - case assertFailed: - s = TRANS ("an assertion failed"); - break; - - case fileInUse: - s = TRANS ("the file is in use"); - break; - - case fileExists: - s = TRANS ("the file exists"); - break; - - case fileNoPerm: - s = TRANS ("permission was denied"); - break; - - case fileIOError: - s = TRANS ("an I/O or device error occurred"); - break; - - case fileNoSpace: - s = TRANS ("there is no space left on the device"); - break; - - case fileNotFound: - s = TRANS ("the file was not found"); - break; - - case fileNameInvalid: - s = TRANS ("the file name was illegal or malformed"); - break; - - default: - s = TRANS ("an unknown error code was received"); - break; - } - - return s; -} - -#ifdef UNDEF_TRANS -#undef TRANs -#undef UNDEF_TRANS -#endif - -} - diff --git a/beast/utility/is_call_possible.h b/beast/utility/is_call_possible.h deleted file mode 100644 index 08b4c9e456..0000000000 --- a/beast/utility/is_call_possible.h +++ /dev/null @@ -1,284 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_UTILITY_IS_CALL_POSSIBLE_H_INCLUDED -#define BEAST_UTILITY_IS_CALL_POSSIBLE_H_INCLUDED - -#include // - -namespace beast { - -// inspired by Roman Perepelitsa's presentation from comp.lang.c++.moderated -// based on the implementation here: http://www.rsdn.ru/forum/cpp/2759773.1.aspx -// -namespace is_call_possible_detail -{ - template - struct add_reference - { - using type = Z&; - }; - - template - struct add_reference - { - using type = Z&; - }; - - template class void_exp_result {}; - - template - U const& operator,(U const&, void_exp_result); - - template - U& operator,(U&, void_exp_result); - - template - struct clone_constness - { - using type = dest_type; - }; - - template - struct clone_constness - { - using type = const dest_type; - }; -} - -#define BEAST_DEFINE_HAS_MEMBER_FUNCTION(trait_name, member_function_name) \ -template class trait_name; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(); \ - }; \ - struct base : public Z, public base_mixin { private: base(); }; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg); \ - }; \ - struct base : public Z, public base_mixin { private: base(); }; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg1,Arg2); \ - }; \ - struct base : public Z, public base_mixin { private: base(); }; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg1,Arg2,Arg3); \ - }; \ - struct base : public Z, public base_mixin { private: base(); }; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ -}; \ - \ -template \ -class trait_name \ -{ \ - class yes { char m; }; \ - class no { yes m[2]; }; \ - struct base_mixin \ - { \ - Result member_function_name(Arg1,Arg2,Arg3,Arg4); \ - }; \ - struct base : public Z, public base_mixin { private: base(); }; \ - template class helper{}; \ - template \ - static no deduce(U*, helper* = 0); \ - static yes deduce(...); \ -public: \ - static const bool value = sizeof(yes) == sizeof(deduce(static_cast(0))); \ -} - -#define BEAST_DEFINE_IS_CALL_POSSIBLE(trait_name, member_function_name) \ -struct trait_name##_detail \ -{ \ -BEAST_DEFINE_HAS_MEMBER_FUNCTION(has_member, member_function_name); \ -}; \ - \ -template \ -struct trait_name \ -{ \ -private: \ - using Z = std::remove_reference_t
; \ - class yes {}; \ - class no { yes m[2]; }; \ - struct derived : public Z \ - { \ - using Z::member_function_name; \ - no member_function_name(...) const; \ - private: derived (); \ - }; \ - \ - using derived_type = typename beast::is_call_possible_detail::clone_constness::type; \ - \ - template \ - struct return_value_check \ - { \ - static yes deduce(Result); \ - static no deduce(...); \ - static no deduce(no); \ - static no deduce(beast::is_call_possible_detail::void_exp_result); \ - }; \ - \ - template \ - struct return_value_check \ - { \ - static yes deduce(...); \ - static no deduce(no); \ - }; \ - \ - template \ - struct impl \ - { \ - static const bool value = false; \ - }; \ - \ - template \ - struct impl \ - { \ - static typename beast::is_call_possible_detail::add_reference::type test_me; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(), beast::is_call_possible_detail::void_exp_result())) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename beast::is_call_possible_detail::add_reference::type test_me; \ - static typename beast::is_call_possible_detail::add_reference::type arg; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg), beast::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename beast::is_call_possible_detail::add_reference::type test_me; \ - static typename beast::is_call_possible_detail::add_reference::type arg1; \ - static typename beast::is_call_possible_detail::add_reference::type arg2; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg1,arg2), beast::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename beast::is_call_possible_detail::add_reference::type test_me; \ - static typename beast::is_call_possible_detail::add_reference::type arg1; \ - static typename beast::is_call_possible_detail::add_reference::type arg2; \ - static typename beast::is_call_possible_detail::add_reference::type arg3; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg1,arg2,arg3), beast::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - template \ - struct impl \ - { \ - static typename beast::is_call_possible_detail::add_reference::type test_me; \ - static typename beast::is_call_possible_detail::add_reference::type arg1; \ - static typename beast::is_call_possible_detail::add_reference::type arg2; \ - static typename beast::is_call_possible_detail::add_reference::type arg3; \ - static typename beast::is_call_possible_detail::add_reference::type arg4; \ - \ - static const bool value = \ - sizeof( \ - return_value_check::deduce( \ - (test_me.member_function_name(arg1,arg2,arg3,arg4), \ - beast::is_call_possible_detail::void_exp_result()) \ - ) \ - ) == sizeof(yes); \ - }; \ - \ - public: \ - static const bool value = impl::value, \ - IsCallPossibleSignature>::value; \ -} - -} // beast - -#endif