mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 16:57:56 +00:00
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
This commit is contained in:
@@ -20,21 +20,26 @@
|
|||||||
#ifndef BEAST_VERSION_H_INCLUDED
|
#ifndef BEAST_VERSION_H_INCLUDED
|
||||||
#define BEAST_VERSION_H_INCLUDED
|
#define BEAST_VERSION_H_INCLUDED
|
||||||
|
|
||||||
/** Current BEAST version number.
|
#include <string>
|
||||||
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
|
|
||||||
|
|
||||||
/** Current Beast version number.
|
/** Current BEAST version number. */
|
||||||
Bits 16 to 32 = major version.
|
unsigned int const BEAST_VERSION_MAJOR = 1;
|
||||||
Bits 8 to 16 = minor version.
|
unsigned int const BEAST_VERSION_MINOR = 0;
|
||||||
Bits 0 to 8 = point release.
|
unsigned int const BEAST_VERSION_BUILD = 0;
|
||||||
See also SystemStats::getBeastVersion() for a string version.
|
|
||||||
*/
|
unsigned int const BEAST_VERSION =
|
||||||
#define BEAST_VERSION ((BEAST_MAJOR_VERSION << 16) + (BEAST_MINOR_VERSION << 8) + BEAST_BUILDNUMBER)
|
(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
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
#include <beast/Threads.h>
|
#include <beast/Threads.h>
|
||||||
|
|
||||||
#include <beast/utility/Debug.h>
|
#include <beast/utility/Debug.h>
|
||||||
#include <beast/utility/Error.h>
|
|
||||||
#include <beast/utility/Journal.h>
|
#include <beast/utility/Journal.h>
|
||||||
#include <beast/utility/PropertyStream.h>
|
#include <beast/utility/PropertyStream.h>
|
||||||
|
|
||||||
@@ -69,7 +68,6 @@ class FileOutputStream;
|
|||||||
// Order matters, since headers don't have their own #include lines.
|
// Order matters, since headers don't have their own #include lines.
|
||||||
// Add new includes to the bottom.
|
// Add new includes to the bottom.
|
||||||
|
|
||||||
#include <beast/module/core/time/AtExitHook.h>
|
|
||||||
#include <beast/module/core/time/Time.h>
|
#include <beast/module/core/time/Time.h>
|
||||||
#include <beast/module/core/threads/ScopedLock.h>
|
#include <beast/module/core/threads/ScopedLock.h>
|
||||||
#include <beast/module/core/threads/CriticalSection.h>
|
#include <beast/module/core/threads/CriticalSection.h>
|
||||||
@@ -139,14 +137,12 @@ class FileOutputStream;
|
|||||||
#include <beast/module/core/streams/InputStream.h>
|
#include <beast/module/core/streams/InputStream.h>
|
||||||
#include <beast/module/core/files/FileInputStream.h>
|
#include <beast/module/core/files/FileInputStream.h>
|
||||||
#include <beast/module/core/streams/InputSource.h>
|
#include <beast/module/core/streams/InputSource.h>
|
||||||
#include <beast/module/core/streams/FileInputSource.h>
|
|
||||||
#include <beast/module/core/streams/OutputStream.h>
|
#include <beast/module/core/streams/OutputStream.h>
|
||||||
#include <beast/module/core/files/FileOutputStream.h>
|
#include <beast/module/core/files/FileOutputStream.h>
|
||||||
#include <beast/module/core/streams/MemoryOutputStream.h>
|
#include <beast/module/core/streams/MemoryOutputStream.h>
|
||||||
|
|
||||||
#include <beast/module/core/system/SystemStats.h>
|
#include <beast/module/core/system/SystemStats.h>
|
||||||
#include <beast/module/core/diagnostic/SemanticVersion.h>
|
#include <beast/module/core/diagnostic/SemanticVersion.h>
|
||||||
#include <beast/module/core/threads/Process.h>
|
|
||||||
#include <beast/module/core/diagnostic/UnitTestUtilities.h>
|
#include <beast/module/core/diagnostic/UnitTestUtilities.h>
|
||||||
|
|
||||||
#include <beast/module/core/diagnostic/MeasureFunctionCallTime.h>
|
#include <beast/module/core/diagnostic/MeasureFunctionCallTime.h>
|
||||||
|
|||||||
@@ -141,7 +141,6 @@
|
|||||||
|
|
||||||
#include <beast/module/core/misc/Result.cpp>
|
#include <beast/module/core/misc/Result.cpp>
|
||||||
|
|
||||||
#include <beast/module/core/streams/FileInputSource.cpp>
|
|
||||||
#include <beast/module/core/streams/InputStream.cpp>
|
#include <beast/module/core/streams/InputStream.cpp>
|
||||||
#include <beast/module/core/streams/MemoryOutputStream.cpp>
|
#include <beast/module/core/streams/MemoryOutputStream.cpp>
|
||||||
#include <beast/module/core/streams/OutputStream.cpp>
|
#include <beast/module/core/streams/OutputStream.cpp>
|
||||||
@@ -155,7 +154,6 @@
|
|||||||
#include <beast/module/core/thread/DeadlineTimer.cpp>
|
#include <beast/module/core/thread/DeadlineTimer.cpp>
|
||||||
#include <beast/module/core/thread/Workers.cpp>
|
#include <beast/module/core/thread/Workers.cpp>
|
||||||
|
|
||||||
#include <beast/module/core/time/AtExitHook.cpp>
|
|
||||||
#include <beast/module/core/time/Time.cpp>
|
#include <beast/module/core/time/Time.cpp>
|
||||||
|
|
||||||
#if BEAST_MAC || BEAST_IOS
|
#if BEAST_MAC || BEAST_IOS
|
||||||
@@ -174,22 +172,18 @@
|
|||||||
#include <beast/module/core/native/mac_Files.mm>
|
#include <beast/module/core/native/mac_Files.mm>
|
||||||
#include <beast/module/core/native/mac_Strings.mm>
|
#include <beast/module/core/native/mac_Strings.mm>
|
||||||
#include <beast/module/core/native/mac_SystemStats.mm>
|
#include <beast/module/core/native/mac_SystemStats.mm>
|
||||||
#include <beast/module/core/native/mac_Threads.mm>
|
|
||||||
|
|
||||||
#elif BEAST_WINDOWS
|
#elif BEAST_WINDOWS
|
||||||
#include <beast/module/core/native/win32_Files.cpp>
|
#include <beast/module/core/native/win32_Files.cpp>
|
||||||
#include <beast/module/core/native/win32_SystemStats.cpp>
|
#include <beast/module/core/native/win32_SystemStats.cpp>
|
||||||
#include <beast/module/core/native/win32_Threads.cpp>
|
|
||||||
|
|
||||||
#elif BEAST_LINUX
|
#elif BEAST_LINUX
|
||||||
#include <beast/module/core/native/linux_Files.cpp>
|
#include <beast/module/core/native/linux_Files.cpp>
|
||||||
#include <beast/module/core/native/linux_SystemStats.cpp>
|
#include <beast/module/core/native/linux_SystemStats.cpp>
|
||||||
#include <beast/module/core/native/linux_Threads.cpp>
|
|
||||||
|
|
||||||
#elif BEAST_BSD
|
#elif BEAST_BSD
|
||||||
#include <beast/module/core/native/bsd_Files.cpp>
|
#include <beast/module/core/native/bsd_Files.cpp>
|
||||||
#include <beast/module/core/native/bsd_SystemStats.cpp>
|
#include <beast/module/core/native/bsd_SystemStats.cpp>
|
||||||
#include <beast/module/core/native/bsd_Threads.cpp>
|
|
||||||
|
|
||||||
#elif BEAST_ANDROID
|
#elif BEAST_ANDROID
|
||||||
#include "native/android_Files.cpp"
|
#include "native/android_Files.cpp"
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ FatalError (char const* message, char const* file, int line)
|
|||||||
if (file != nullptr && file [0] != 0)
|
if (file != nullptr && file [0] != 0)
|
||||||
std::cerr << " File: " << file << ":" << line << '\n';
|
std::cerr << " File: " << file << ":" << line << '\n';
|
||||||
|
|
||||||
auto const backtrace = SystemStats::getStackBacktrace ();
|
auto const backtrace = getStackBacktrace ();
|
||||||
|
|
||||||
if (!backtrace.empty ())
|
if (!backtrace.empty ())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,66 +20,23 @@
|
|||||||
#ifndef BEAST_MODULE_CORE_DIAGNOSTIC_MEASUREFUNCTIONCALLTIME_H_INCLUDED
|
#ifndef BEAST_MODULE_CORE_DIAGNOSTIC_MEASUREFUNCTIONCALLTIME_H_INCLUDED
|
||||||
#define BEAST_MODULE_CORE_DIAGNOSTIC_MEASUREFUNCTIONCALLTIME_H_INCLUDED
|
#define BEAST_MODULE_CORE_DIAGNOSTIC_MEASUREFUNCTIONCALLTIME_H_INCLUDED
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace beast
|
namespace beast
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Measures the speed of invoking a function. */
|
/** Measures the speed of invoking a function. */
|
||||||
/** @{ */
|
template <typename Function, class... Args>
|
||||||
template <typename Function>
|
std::chrono::high_resolution_clock::duration
|
||||||
double measureFunctionCallTime (Function f)
|
measureFunctionCallTime (Function f, Args&&... args)
|
||||||
{
|
{
|
||||||
std::int64_t const startTime (Time::getHighResolutionTicks ());
|
auto start = std::chrono::high_resolution_clock::now ();
|
||||||
f ();
|
f (std::forward<Args>(args)...);
|
||||||
return Time::highResolutionTicksToSeconds (
|
auto end = std::chrono::high_resolution_clock::now ();
|
||||||
Time::getHighResolutionTicks () - startTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
return end - start;
|
||||||
template <typename Function,
|
|
||||||
typename P1, typename P2, typename P3, typename P4,
|
|
||||||
typename P5, typename P6, typename P7, typename P8>
|
|
||||||
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 <typename Function,
|
|
||||||
typename P1, typename P2, typename P3, typename P4,
|
|
||||||
typename P5, typename P6, typename P7, typename P8>
|
|
||||||
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 <typename Function,
|
|
||||||
typename P1, typename P2, typename P3, typename P4,
|
|
||||||
typename P5, typename P6, typename P7, typename P8>
|
|
||||||
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 <typename Function,
|
|
||||||
typename P1, typename P2, typename P3, typename P4,
|
|
||||||
typename P5, typename P6, typename P7, typename P8>
|
|
||||||
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
|
} // beast
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <beast/unit_test/suite.h>
|
|
||||||
#include <beast/utility/static_initializer.h>
|
#include <beast/utility/static_initializer.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -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::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 <File> 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 File::deleteRecursively() const
|
||||||
{
|
{
|
||||||
bool worked = true;
|
bool worked = true;
|
||||||
@@ -238,53 +220,6 @@ bool File::deleteRecursively() const
|
|||||||
return deleteFile() && worked;
|
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<File> 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
|
String File::getPathUpToLastSlash() const
|
||||||
{
|
{
|
||||||
@@ -339,9 +274,6 @@ bool File::isAChildOf (const File& potentialParent) const
|
|||||||
return getParentDirectory().isAChildOf (potentialParent);
|
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)
|
bool File::isAbsolutePath (const String& path)
|
||||||
{
|
{
|
||||||
@@ -447,15 +379,6 @@ Result File::createDirectory() const
|
|||||||
return r;
|
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<File>& results,
|
int File::findChildFiles (Array<File>& results,
|
||||||
const int whatToLookFor,
|
const int whatToLookFor,
|
||||||
@@ -485,75 +408,6 @@ int File::getNumberOfChildFiles (const int whatToLookFor, const String& wildCard
|
|||||||
return total;
|
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
|
String File::getFileExtension() const
|
||||||
{
|
{
|
||||||
@@ -656,126 +510,6 @@ bool File::appendText (const String& text,
|
|||||||
return true;
|
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)
|
File File::createTempFile (const String& fileNameEnding)
|
||||||
{
|
{
|
||||||
@@ -789,136 +523,4 @@ File File::createTempFile (const String& fileNameEnding)
|
|||||||
return tempFile;
|
return tempFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
class File_test : public unit_test::suite
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template <class T1, class T2>
|
|
||||||
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<File> files;
|
|
||||||
temp.findChildFiles (files, File::findFilesAndDirectories, false, "*");
|
|
||||||
expect (files.contains (demoFolder));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
Array<File> 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
|
} // beast
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
#include <beast/module/core/containers/Array.h>
|
#include <beast/module/core/containers/Array.h>
|
||||||
#include <beast/module/core/memory/MemoryBlock.h>
|
#include <beast/module/core/memory/MemoryBlock.h>
|
||||||
#include <beast/module/core/misc/Result.h>
|
#include <beast/module/core/misc/Result.h>
|
||||||
#include <beast/module/core/time/Time.h>
|
|
||||||
#include <beast/module/core/text/StringArray.h>
|
#include <beast/module/core/text/StringArray.h>
|
||||||
#include <beast/module/core/threads/CriticalSection.h>
|
#include <beast/module/core/threads/CriticalSection.h>
|
||||||
|
|
||||||
@@ -144,7 +143,7 @@ public:
|
|||||||
If you just want the file's name, you should use getFileName() or
|
If you just want the file's name, you should use getFileName() or
|
||||||
getFileNameWithoutExtension().
|
getFileNameWithoutExtension().
|
||||||
|
|
||||||
@see getFileName, getRelativePathFrom
|
@see getFileName
|
||||||
*/
|
*/
|
||||||
const String& getFullPathName() const noexcept { return fullPath; }
|
const String& getFullPathName() const noexcept { return fullPath; }
|
||||||
|
|
||||||
@@ -163,23 +162,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
String getFileName() const;
|
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.
|
/** Returns the file's extension.
|
||||||
|
|
||||||
@@ -224,21 +206,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
String getFileNameWithoutExtension() const;
|
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.
|
/** 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.
|
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"
|
File ("/moose/fish").getChildFile ("/foo.txt") will produce "/foo.txt"
|
||||||
|
|
||||||
@see getSiblingFile, getParentDirectory, getRelativePathFrom, isAChildOf
|
@see getSiblingFile, getParentDirectory, isAChildOf
|
||||||
*/
|
*/
|
||||||
File getChildFile (String relativeOrAbsolutePath) const;
|
File getChildFile (String relativeOrAbsolutePath) const;
|
||||||
|
|
||||||
@@ -282,39 +249,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isAChildOf (const File& potentialParentDirectory) const;
|
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. */
|
/** Compares the pathnames for two files. */
|
||||||
bool operator== (const File&) const;
|
bool operator== (const File&) const;
|
||||||
@@ -325,74 +259,6 @@ public:
|
|||||||
/** Compares the pathnames for two files. */
|
/** Compares the pathnames for two files. */
|
||||||
bool operator> (const File&) const;
|
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.
|
/** Creates an empty file if it doesn't already exist.
|
||||||
|
|
||||||
@@ -439,44 +305,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool deleteRecursively() const;
|
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.
|
/** Used in file searching, to specify whether to return files, directories, or both.
|
||||||
*/
|
*/
|
||||||
@@ -529,11 +357,6 @@ public:
|
|||||||
int getNumberOfChildFiles (int whatToLookFor,
|
int getNumberOfChildFiles (int whatToLookFor,
|
||||||
const String& wildCardPattern = "*") const;
|
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.
|
/** Creates a stream to read from this file.
|
||||||
|
|
||||||
@@ -581,21 +404,6 @@ public:
|
|||||||
bool asUnicode = false,
|
bool asUnicode = false,
|
||||||
bool writeUnicodeHeaderBytes = false) const;
|
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.
|
/** A set of types of location that can be passed to the getSpecialLocation() method.
|
||||||
*/
|
*/
|
||||||
@@ -674,20 +482,9 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
/** Returns the current working directory.
|
/** Returns the current working directory. */
|
||||||
@see setAsCurrentWorkingDirectory
|
|
||||||
*/
|
|
||||||
static File getCurrentWorkingDirectory();
|
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.
|
/** The system-specific file separator character.
|
||||||
On Windows, this will be '\', on Mac/Linux, it'll be '/'
|
On Windows, this will be '\', on Mac/Linux, it'll be '/'
|
||||||
@@ -700,28 +497,6 @@ public:
|
|||||||
static const String separatorString;
|
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. */
|
/** Indicates whether filenames are case-sensitive on the current operating system. */
|
||||||
static bool areFileNamesCaseSensitive();
|
static bool areFileNamesCaseSensitive();
|
||||||
|
|
||||||
@@ -746,11 +521,6 @@ private:
|
|||||||
String getPathUpToLastSlash() const;
|
String getPathUpToLastSlash() const;
|
||||||
|
|
||||||
Result createDirectoryInternal (const String&) 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
|
} // beast
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ void Random::setSeedRandomly()
|
|||||||
static std::int64_t globalSeed = 0;
|
static std::int64_t globalSeed = 0;
|
||||||
|
|
||||||
combineSeed (globalSeed ^ (std::int64_t) (std::intptr_t) this);
|
combineSeed (globalSeed ^ (std::int64_t) (std::intptr_t) this);
|
||||||
combineSeed (Time::getMillisecondCounter());
|
|
||||||
combineSeed (Time::getHighResolutionTicks());
|
|
||||||
combineSeed (Time::getHighResolutionTicksPerSecond());
|
|
||||||
combineSeed (Time::currentTimeMillis());
|
combineSeed (Time::currentTimeMillis());
|
||||||
globalSeed ^= seed;
|
globalSeed ^= seed;
|
||||||
|
|
||||||
|
|||||||
@@ -23,38 +23,6 @@
|
|||||||
|
|
||||||
namespace beast
|
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)
|
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);
|
return File (fallbackFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const* beast_argv = nullptr;
|
|
||||||
int beast_argc = 0;
|
|
||||||
|
|
||||||
File File::getSpecialLocation (const SpecialLocationType type)
|
File File::getSpecialLocation (const SpecialLocationType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
|||||||
@@ -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 };
|
char name [256] = { 0 };
|
||||||
if (gethostname (name, sizeof (name) - 1) == 0)
|
if (gethostname (name, sizeof (name) - 1) == 0)
|
||||||
@@ -37,31 +45,4 @@ std::string SystemStats::getComputerName()
|
|||||||
return std::string{};
|
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
|
} // beast
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -23,38 +23,6 @@
|
|||||||
|
|
||||||
namespace beast
|
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)
|
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);
|
return File (fallbackFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const* beast_argv = nullptr;
|
|
||||||
int beast_argc = 0;
|
|
||||||
|
|
||||||
File File::getSpecialLocation (const SpecialLocationType type)
|
File File::getSpecialLocation (const SpecialLocationType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
@@ -104,7 +69,7 @@ File File::getSpecialLocation (const SpecialLocationType type)
|
|||||||
|
|
||||||
if (struct passwd* const pw = getpwuid (getuid()))
|
if (struct passwd* const pw = getpwuid (getuid()))
|
||||||
return File (CharPointer_UTF8 (pw->pw_dir));
|
return File (CharPointer_UTF8 (pw->pw_dir));
|
||||||
|
|
||||||
return File (CharPointer_UTF8 (homeDir));
|
return File (CharPointer_UTF8 (homeDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 };
|
char name [256] = { 0 };
|
||||||
if (gethostname (name, sizeof (name) - 1) == 0)
|
if (gethostname (name, sizeof (name) - 1) == 0)
|
||||||
@@ -39,31 +58,4 @@ std::string SystemStats::getComputerName()
|
|||||||
return std::string{};
|
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
|
} // beast
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -29,26 +29,6 @@ namespace beast
|
|||||||
live in beast_posix_SharedCode.h!
|
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
|
namespace FileHelpers
|
||||||
{
|
{
|
||||||
@@ -123,9 +103,6 @@ namespace FileHelpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
const char* const* beast_argv = nullptr;
|
|
||||||
int beast_argc = 0;
|
|
||||||
|
|
||||||
File File::getSpecialLocation (const SpecialLocationType type)
|
File File::getSpecialLocation (const SpecialLocationType type)
|
||||||
{
|
{
|
||||||
BEAST_AUTORELEASEPOOL
|
BEAST_AUTORELEASEPOOL
|
||||||
|
|||||||
@@ -24,25 +24,6 @@
|
|||||||
namespace beast
|
namespace beast
|
||||||
{
|
{
|
||||||
|
|
||||||
String String::fromCFString (CFStringRef cfString)
|
|
||||||
{
|
|
||||||
if (cfString == 0)
|
|
||||||
return String::empty;
|
|
||||||
|
|
||||||
CFRange range = { 0, CFStringGetLength (cfString) };
|
|
||||||
HeapBlock <UniChar> 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
|
String String::convertToPrecomposedUnicode() const
|
||||||
{
|
{
|
||||||
#if BEAST_IOS
|
#if BEAST_IOS
|
||||||
|
|||||||
@@ -62,7 +62,24 @@ static RLimitInitialiser rLimitInitialiser;
|
|||||||
#endif
|
#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 };
|
char name [256] = { 0 };
|
||||||
if (gethostname (name, sizeof (name) - 1) == 0)
|
if (gethostname (name, sizeof (name) - 1) == 0)
|
||||||
@@ -71,56 +88,4 @@ std::string SystemStats::getComputerName()
|
|||||||
return std::string{};
|
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
|
} // beast
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -54,104 +54,6 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
template <typename ObjectType>
|
|
||||||
struct NSObjectRetainer
|
|
||||||
{
|
|
||||||
inline NSObjectRetainer (ObjectType* o) : object (o) { [object retain]; }
|
|
||||||
inline ~NSObjectRetainer() { [object release]; }
|
|
||||||
|
|
||||||
ObjectType* object;
|
|
||||||
};
|
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
template <typename SuperclassType>
|
|
||||||
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 <typename Type>
|
|
||||||
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 <typename FunctionType>
|
|
||||||
void addMethod (SEL selector, FunctionType callbackFn, const char* signature)
|
|
||||||
{
|
|
||||||
BOOL b = class_addMethod (cls, selector, (IMP) callbackFn, signature);
|
|
||||||
bassert (b); (void) b;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FunctionType>
|
|
||||||
void addMethod (SEL selector, FunctionType callbackFn, const char* sig1, const char* sig2)
|
|
||||||
{
|
|
||||||
addMethod (selector, callbackFn, (String (sig1) + sig2).toUTF8());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FunctionType>
|
|
||||||
void addMethod (SEL selector, FunctionType callbackFn, const char* sig1, const char* sig2, const char* sig3)
|
|
||||||
{
|
|
||||||
addMethod (selector, callbackFn, (String (sig1) + sig2 + sig3).toUTF8());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename FunctionType>
|
|
||||||
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 <typename Type>
|
|
||||||
static Type getIvar (id self, const char* name)
|
|
||||||
{
|
|
||||||
void* v = nullptr;
|
|
||||||
object_getInstanceVariable (self, name, &v);
|
|
||||||
return static_cast <Type> (v);
|
|
||||||
}
|
|
||||||
|
|
||||||
Class cls;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static String getRandomisedName (const char* root)
|
|
||||||
{
|
|
||||||
return root + String::toHexString (beast::Random::getSystemRandom().nextInt64());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // beast
|
} // beast
|
||||||
|
|
||||||
#endif // BEAST_OSX_OBJCHELPERS_H_INCLUDED
|
#endif // BEAST_OSX_OBJCHELPERS_H_INCLUDED
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef BEAST_MODULE_CORE_NATIVE_POSIX_SHAREDCODE_H_INCLUDED
|
||||||
|
#define BEAST_MODULE_CORE_NATIVE_POSIX_SHAREDCODE_H_INCLUDED
|
||||||
|
|
||||||
namespace beast
|
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; }
|
bool CriticalSection::tryEnter() const noexcept { return pthread_mutex_trylock (&mutex) == 0; }
|
||||||
void CriticalSection::exit() const noexcept { pthread_mutex_unlock (&mutex); }
|
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 beast_wchar File::separator = '/';
|
||||||
const String File::separatorString ("/");
|
const String File::separatorString ("/");
|
||||||
@@ -79,26 +67,6 @@ File File::getCurrentWorkingDirectory()
|
|||||||
return File (CharPointer_UTF8 (cwd));
|
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
|
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
|
bool File::deleteFile() const
|
||||||
{
|
{
|
||||||
if (! exists())
|
if (! exists())
|
||||||
@@ -259,22 +168,6 @@ bool File::deleteFile() const
|
|||||||
return remove (fullPath.toUTF8()) == 0;
|
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
|
Result File::createDirectoryInternal (const String& fileName) const
|
||||||
{
|
{
|
||||||
return getResultForReturnValue (mkdir (fileName.toUTF8(), 0777));
|
return getResultForReturnValue (mkdir (fileName.toUTF8(), 0777));
|
||||||
@@ -442,24 +335,5 @@ File beast_getExecutableFile()
|
|||||||
#endif
|
#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
|
} // beast
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -69,17 +69,6 @@ namespace WindowsFileHelpers
|
|||||||
return path;
|
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)
|
unsigned int getWindowsDriveType (const String& path)
|
||||||
{
|
{
|
||||||
return GetDriveType (getDriveFromPath (path).toWideCharPointer());
|
return GetDriveType (getDriveFromPath (path).toWideCharPointer());
|
||||||
@@ -139,29 +128,6 @@ bool File::isDirectory() const
|
|||||||
return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
|
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
|
bool File::deleteFile() const
|
||||||
{
|
{
|
||||||
@@ -172,16 +138,6 @@ bool File::deleteFile() const
|
|||||||
: DeleteFile (fullPath.toWideCharPointer()) != 0;
|
: 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
|
Result File::createDirectoryInternal (const String& fileName) const
|
||||||
{
|
{
|
||||||
return CreateDirectory (fileName.toWideCharPointer(), 0) ? Result::ok()
|
return CreateDirectory (fileName.toWideCharPointer(), 0) ? Result::ok()
|
||||||
@@ -298,57 +254,6 @@ std::int64_t File::getSize() const
|
|||||||
return 0;
|
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)
|
File File::getSpecialLocation (const SpecialLocationType type)
|
||||||
{
|
{
|
||||||
@@ -392,11 +297,6 @@ File File::getCurrentWorkingDirectory()
|
|||||||
return File (String (dest));
|
return File (String (dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::setAsCurrentWorkingDirectory() const
|
|
||||||
{
|
|
||||||
return SetCurrentDirectory (getFullPathName().toWideCharPointer()) != FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
class DirectoryIterator::NativeIterator::Pimpl
|
class DirectoryIterator::NativeIterator::Pimpl
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
std::string getComputerName()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
char text [MAX_COMPUTERNAME_LENGTH + 2] = { 0 };
|
char text [MAX_COMPUTERNAME_LENGTH + 2] = { 0 };
|
||||||
DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
|
DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
|
||||||
|
|||||||
@@ -76,28 +76,4 @@ void CriticalSection::enter() const noexcept { EnterCriticalSection ((CRITICAL_S
|
|||||||
bool CriticalSection::tryEnter() const noexcept { return TryEnterCriticalSection ((CRITICAL_SECTION*) section) != FALSE; }
|
bool CriticalSection::tryEnter() const noexcept { return TryEnterCriticalSection ((CRITICAL_SECTION*) section) != FALSE; }
|
||||||
void CriticalSection::exit() const noexcept { LeaveCriticalSection ((CRITICAL_SECTION*) section); }
|
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
|
} // beast
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -33,8 +33,6 @@ namespace beast
|
|||||||
|
|
||||||
This may be used to refer to a file, or some other kind of source, allowing a
|
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.
|
caller to create an input stream that can read from it when required.
|
||||||
|
|
||||||
@see FileInputSource
|
|
||||||
*/
|
*/
|
||||||
class InputSource
|
class InputSource
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,18 +42,9 @@ static_assert (sizeof (std::uint64_t) == 8, "std::uint64_t must be exactly 8 byt
|
|||||||
|
|
||||||
namespace beast
|
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 <std::string>
|
std::vector <std::string>
|
||||||
SystemStats::getStackBacktrace()
|
getStackBacktrace()
|
||||||
{
|
{
|
||||||
std::vector <std::string> result;
|
std::vector <std::string> result;
|
||||||
|
|
||||||
@@ -121,41 +112,4 @@ SystemStats::getStackBacktrace()
|
|||||||
return result;
|
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
|
} // beast
|
||||||
|
|||||||
@@ -28,40 +28,16 @@ namespace beast
|
|||||||
{
|
{
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
/**
|
/** Returns the host-name of the computer. */
|
||||||
Contains methods for finding out about the current hardware and OS configuration.
|
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
|
std::vector <std::string>
|
||||||
{
|
getStackBacktrace();
|
||||||
//==============================================================================
|
|
||||||
/** 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 <std::string>
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // beast
|
} // beast
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <beast/utility/static_initializer.h>
|
|
||||||
|
|
||||||
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 <Item>::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 <Item> 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
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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_TIME_ATEXITHOOK_H_INCLUDED
|
|
||||||
#define BEAST_MODULE_CORE_TIME_ATEXITHOOK_H_INCLUDED
|
|
||||||
|
|
||||||
#include <beast/intrusive/List.h>
|
|
||||||
|
|
||||||
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 <Item>::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 Object>
|
|
||||||
class AtExitMemberHook : public AtExitHook
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit AtExitMemberHook (Object* owner) : m_owner (owner)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void onExit ()
|
|
||||||
{
|
|
||||||
m_owner->onExit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
Object* m_owner;
|
|
||||||
};
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
} // beast
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -116,8 +116,6 @@ namespace TimeHelpers
|
|||||||
StringType (buffer) + (int) numChars);
|
StringType (buffer) + (int) numChars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::uint32_t lastMSCounterValue = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@@ -216,48 +214,6 @@ Time Time::getCurrentTime() noexcept
|
|||||||
return Time (currentTimeMillis());
|
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,
|
String Time::toString (const bool includeDate,
|
||||||
const bool includeTime,
|
const bool includeTime,
|
||||||
|
|||||||
@@ -301,75 +301,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static std::int64_t currentTimeMillis() noexcept;
|
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:
|
private:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
std::int64_t millisSinceEpoch;
|
std::int64_t millisSinceEpoch;
|
||||||
|
|||||||
@@ -1201,15 +1201,6 @@ public:
|
|||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
#if BEAST_MAC || BEAST_IOS || DOXYGEN
|
#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
|
/** MAC ONLY - Returns a copy of this string in which any decomposed unicode characters have
|
||||||
been converted to their precomposed equivalents. */
|
been converted to their precomposed equivalents. */
|
||||||
String convertToPrecomposedUnicode() const;
|
String convertToPrecomposedUnicode() const;
|
||||||
|
|||||||
@@ -1,276 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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_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 Handler, class P1>
|
|
||||||
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 const&> (p1)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() const
|
|
||||||
{
|
|
||||||
handler (p1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Handler, class P1>
|
|
||||||
BindHandler1 <Handler, P1> bindHandler (Handler handler, P1 const& p1)
|
|
||||||
{
|
|
||||||
return BindHandler1 <Handler, P1> (handler, p1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2>
|
|
||||||
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 const&> (p1), static_cast <P2 const&> (p2));
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() const
|
|
||||||
{ handler (p1, p2); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2>
|
|
||||||
BindHandler2 <Handler, P1, P2> bindHandler (Handler handler,
|
|
||||||
P1 const& p1, P2 const& p2)
|
|
||||||
{
|
|
||||||
return BindHandler2 <Handler, P1, P2> (
|
|
||||||
handler, p1, p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3>
|
|
||||||
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 const&> (p1), static_cast <P2 const&> (p2), static_cast <P3 const&> (p3));
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() const
|
|
||||||
{ handler (p1, p2, p3); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3>
|
|
||||||
BindHandler3 <Handler, P1, P2, P3> bindHandler (Handler handler,
|
|
||||||
P1 const& p1, P2 const& p2, P3 const& p3)
|
|
||||||
{
|
|
||||||
return BindHandler3 <Handler, P1, P2, P3> (
|
|
||||||
handler, p1, p2, p3);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3, class P4>
|
|
||||||
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 const&> (p1), static_cast <P2 const&> (p2), static_cast <P3 const&> (p3),
|
|
||||||
static_cast <P4 const&> (p4)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() const
|
|
||||||
{ handler (p1, p2, p3, p4); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3, class P4>
|
|
||||||
BindHandler4 <Handler, P1, P2, P3, P4> bindHandler (Handler handler,
|
|
||||||
P1 const& p1, P2 const& p2, P3 const& p3, P4 const& p4)
|
|
||||||
{
|
|
||||||
return BindHandler4 <Handler, P1, P2, P3, P4> (
|
|
||||||
handler, p1, p2, p3, p4);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3, class P4, class P5>
|
|
||||||
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 const&> (p1), static_cast <P2 const&> (p2), static_cast <P3 const&> (p3),
|
|
||||||
static_cast <P4 const&> (p4), static_cast <P5 const&> (p5)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() const
|
|
||||||
{ handler (p1, p2, p3, p4, p5); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3, class P4, class P5>
|
|
||||||
BindHandler5 <Handler, P1, P2, P3, P4, P5> 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> (
|
|
||||||
handler, p1, p2, p3, p4, p5);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3, class P4, class P5, class P6>
|
|
||||||
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 const&> (p1), static_cast <P2 const&> (p2), static_cast <P3 const&> (p3),
|
|
||||||
static_cast <P4 const&> (p4), static_cast <P5 const&> (p5), static_cast <P6 const&> (p6)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() const
|
|
||||||
{ handler (p1, p2, p3, p4, p5, p6); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Handler, class P1, class P2, class P3, class P4, class P5, class P6>
|
|
||||||
BindHandler6 <Handler, P1, P2, P3, P4, P5, P6> 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> (
|
|
||||||
handler, p1, p2, p3, p4, p5, p6);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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_THREADS_DETAIL_DISPATCHEDHANDLER_H_INCLUDED
|
|
||||||
#define BEAST_THREADS_DETAIL_DISPATCHEDHANDLER_H_INCLUDED
|
|
||||||
|
|
||||||
#include <beast/threads/detail/BindHandler.h>
|
|
||||||
|
|
||||||
namespace beast {
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
/** A wrapper that packages function call arguments into a dispatch. */
|
|
||||||
template <typename Dispatcher, typename Handler>
|
|
||||||
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 <class P1>
|
|
||||||
void operator() (P1 const& p1)
|
|
||||||
{
|
|
||||||
m_dispatcher.dispatch (
|
|
||||||
detail::bindHandler (m_handler,
|
|
||||||
p1));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class P1>
|
|
||||||
void operator() (P1 const& p1) const
|
|
||||||
{
|
|
||||||
m_dispatcher.dispatch (
|
|
||||||
detail::bindHandler (m_handler,
|
|
||||||
p1));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class P1, class P2>
|
|
||||||
void operator() (P1 const& p1, P2 const& p2)
|
|
||||||
{
|
|
||||||
m_dispatcher.dispatch (
|
|
||||||
detail::bindHandler (m_handler,
|
|
||||||
p1, p2));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class P1, class P2>
|
|
||||||
void operator() (P1 const& p1, P2 const& p2) const
|
|
||||||
{
|
|
||||||
m_dispatcher.dispatch (
|
|
||||||
detail::bindHandler (m_handler,
|
|
||||||
p1, p2));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class P1, class P2, class P3>
|
|
||||||
void operator() (P1 const& p1, P2 const& p2, P3 const& p3)
|
|
||||||
{
|
|
||||||
m_dispatcher.dispatch (
|
|
||||||
detail::bindHandler (m_handler,
|
|
||||||
p1, p2, p3));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class P1, class P2, class P3>
|
|
||||||
void operator() (P1 const& p1, P2 const& p2, P3 const& p3) const
|
|
||||||
{
|
|
||||||
m_dispatcher.dispatch (
|
|
||||||
detail::bindHandler (m_handler,
|
|
||||||
p1, p2, p3));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class P1, class P2, class P3, class P4>
|
|
||||||
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 <class P1, class P2, class P3, class P4>
|
|
||||||
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 <class P1, class P2, class P3, class P4, class P5>
|
|
||||||
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 <class P1, class P2, class P3, class P4, class P5>
|
|
||||||
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 <class P1, class P2, class P3, class P4, class P5, class P6>
|
|
||||||
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 <class P1, class P2, class P3, class P4, class P5, class P6>
|
|
||||||
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
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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_UTILITY_ERROR_H_INCLUDED
|
|
||||||
#define BEAST_UTILITY_ERROR_H_INCLUDED
|
|
||||||
|
|
||||||
#include <beast/Config.h>
|
|
||||||
|
|
||||||
#include <beast/strings/String.h>
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -21,8 +21,6 @@
|
|||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <beast/utility/impl/Error.cpp>
|
|
||||||
|
|
||||||
#include <beast/utility/impl/Debug.cpp>
|
#include <beast/utility/impl/Debug.cpp>
|
||||||
#include <beast/utility/impl/Journal.cpp>
|
#include <beast/utility/impl/Journal.cpp>
|
||||||
#include <beast/utility/impl/PropertyStream.cpp>
|
#include <beast/utility/impl/PropertyStream.cpp>
|
||||||
|
|||||||
@@ -1,259 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <beast/utility/Error.h>
|
|
||||||
#include <beast/utility/Debug.h>
|
|
||||||
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
||||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.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_UTILITY_IS_CALL_POSSIBLE_H_INCLUDED
|
|
||||||
#define BEAST_UTILITY_IS_CALL_POSSIBLE_H_INCLUDED
|
|
||||||
|
|
||||||
#include <beast/cxx14/type_traits.h> // <type_traits>
|
|
||||||
|
|
||||||
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<typename Z>
|
|
||||||
struct add_reference
|
|
||||||
{
|
|
||||||
using type = Z&;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Z>
|
|
||||||
struct add_reference<Z&>
|
|
||||||
{
|
|
||||||
using type = Z&;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Z> class void_exp_result {};
|
|
||||||
|
|
||||||
template <typename Z, typename U>
|
|
||||||
U const& operator,(U const&, void_exp_result<Z>);
|
|
||||||
|
|
||||||
template <typename Z, typename U>
|
|
||||||
U& operator,(U&, void_exp_result<Z>);
|
|
||||||
|
|
||||||
template <typename src_type, typename dest_type>
|
|
||||||
struct clone_constness
|
|
||||||
{
|
|
||||||
using type = dest_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename src_type, typename dest_type>
|
|
||||||
struct clone_constness<const src_type, dest_type>
|
|
||||||
{
|
|
||||||
using type = const dest_type;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BEAST_DEFINE_HAS_MEMBER_FUNCTION(trait_name, member_function_name) \
|
|
||||||
template<typename Z, typename IsCallPossibleSignature> class trait_name; \
|
|
||||||
\
|
|
||||||
template<typename Z, typename Result> \
|
|
||||||
class trait_name<Z, Result(void)> \
|
|
||||||
{ \
|
|
||||||
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 <typename U, U t> class helper{}; \
|
|
||||||
template <typename U> \
|
|
||||||
static no deduce(U*, helper<Result (base_mixin::*)(), &U::member_function_name>* = 0); \
|
|
||||||
static yes deduce(...); \
|
|
||||||
public: \
|
|
||||||
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template<typename Z, typename Result, typename Arg> \
|
|
||||||
class trait_name<Z, Result(Arg)> \
|
|
||||||
{ \
|
|
||||||
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 <typename U, U t> class helper{}; \
|
|
||||||
template <typename U> \
|
|
||||||
static no deduce(U*, helper<Result (base_mixin::*)(Arg), &U::member_function_name>* = 0); \
|
|
||||||
static yes deduce(...); \
|
|
||||||
public: \
|
|
||||||
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template<typename Z, typename Result, typename Arg1, typename Arg2> \
|
|
||||||
class trait_name<Z, Result(Arg1,Arg2)> \
|
|
||||||
{ \
|
|
||||||
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 <typename U, U t> class helper{}; \
|
|
||||||
template <typename U> \
|
|
||||||
static no deduce(U*, helper<Result (base_mixin::*)(Arg1,Arg2), &U::member_function_name>* = 0); \
|
|
||||||
static yes deduce(...); \
|
|
||||||
public: \
|
|
||||||
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template<typename Z, typename Result, typename Arg1, typename Arg2, typename Arg3> \
|
|
||||||
class trait_name<Z, Result(Arg1,Arg2,Arg3)> \
|
|
||||||
{ \
|
|
||||||
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 <typename U, U t> class helper{}; \
|
|
||||||
template <typename U> \
|
|
||||||
static no deduce(U*, helper<Result (base_mixin::*)(Arg1,Arg2,Arg3), &U::member_function_name>* = 0); \
|
|
||||||
static yes deduce(...); \
|
|
||||||
public: \
|
|
||||||
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(0))); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template<typename Z, typename Result, typename Arg1, typename Arg2, typename Arg3, typename Arg4> \
|
|
||||||
class trait_name<Z, Result(Arg1,Arg2,Arg3,Arg4)> \
|
|
||||||
{ \
|
|
||||||
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 <typename U, U t> class helper{}; \
|
|
||||||
template <typename U> \
|
|
||||||
static no deduce(U*, helper<Result (base_mixin::*)(Arg1,Arg2,Arg3,Arg4), &U::member_function_name>* = 0); \
|
|
||||||
static yes deduce(...); \
|
|
||||||
public: \
|
|
||||||
static const bool value = sizeof(yes) == sizeof(deduce(static_cast<base*>(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 <typename DT, typename IsCallPossibleSignature> \
|
|
||||||
struct trait_name \
|
|
||||||
{ \
|
|
||||||
private: \
|
|
||||||
using Z = std::remove_reference_t <DT>; \
|
|
||||||
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<Z, derived>::type; \
|
|
||||||
\
|
|
||||||
template <typename U, typename Result> \
|
|
||||||
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<Z>); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <typename U> \
|
|
||||||
struct return_value_check<U, void> \
|
|
||||||
{ \
|
|
||||||
static yes deduce(...); \
|
|
||||||
static no deduce(no); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <bool has_the_member_of_interest, typename F> \
|
|
||||||
struct impl \
|
|
||||||
{ \
|
|
||||||
static const bool value = false; \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <typename Result> \
|
|
||||||
struct impl<true, Result(void)> \
|
|
||||||
{ \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<derived_type>::type test_me; \
|
|
||||||
\
|
|
||||||
static const bool value = \
|
|
||||||
sizeof( \
|
|
||||||
return_value_check<Z, Result>::deduce( \
|
|
||||||
(test_me.member_function_name(), beast::is_call_possible_detail::void_exp_result<Z>())) \
|
|
||||||
) == sizeof(yes); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <typename Result, typename Arg> \
|
|
||||||
struct impl<true, Result(Arg)> \
|
|
||||||
{ \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<derived_type>::type test_me; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg>::type arg; \
|
|
||||||
\
|
|
||||||
static const bool value = \
|
|
||||||
sizeof( \
|
|
||||||
return_value_check<Z, Result>::deduce( \
|
|
||||||
(test_me.member_function_name(arg), beast::is_call_possible_detail::void_exp_result<Z>()) \
|
|
||||||
) \
|
|
||||||
) == sizeof(yes); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <typename Result, typename Arg1, typename Arg2> \
|
|
||||||
struct impl<true, Result(Arg1,Arg2)> \
|
|
||||||
{ \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<derived_type>::type test_me; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg1>::type arg1; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg2>::type arg2; \
|
|
||||||
\
|
|
||||||
static const bool value = \
|
|
||||||
sizeof( \
|
|
||||||
return_value_check<Z, Result>::deduce( \
|
|
||||||
(test_me.member_function_name(arg1,arg2), beast::is_call_possible_detail::void_exp_result<Z>()) \
|
|
||||||
) \
|
|
||||||
) == sizeof(yes); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <typename Result, typename Arg1, typename Arg2, typename Arg3> \
|
|
||||||
struct impl<true, Result(Arg1,Arg2,Arg3)> \
|
|
||||||
{ \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<derived_type>::type test_me; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg1>::type arg1; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg2>::type arg2; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg3>::type arg3; \
|
|
||||||
\
|
|
||||||
static const bool value = \
|
|
||||||
sizeof( \
|
|
||||||
return_value_check<Z, Result>::deduce( \
|
|
||||||
(test_me.member_function_name(arg1,arg2,arg3), beast::is_call_possible_detail::void_exp_result<Z>()) \
|
|
||||||
) \
|
|
||||||
) == sizeof(yes); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
template <typename Result, typename Arg1, typename Arg2, typename Arg3, typename Arg4> \
|
|
||||||
struct impl<true, Result(Arg1,Arg2,Arg3,Arg4)> \
|
|
||||||
{ \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<derived_type>::type test_me; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg1>::type arg1; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg2>::type arg2; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg3>::type arg3; \
|
|
||||||
static typename beast::is_call_possible_detail::add_reference<Arg4>::type arg4; \
|
|
||||||
\
|
|
||||||
static const bool value = \
|
|
||||||
sizeof( \
|
|
||||||
return_value_check<Z, Result>::deduce( \
|
|
||||||
(test_me.member_function_name(arg1,arg2,arg3,arg4), \
|
|
||||||
beast::is_call_possible_detail::void_exp_result<Z>()) \
|
|
||||||
) \
|
|
||||||
) == sizeof(yes); \
|
|
||||||
}; \
|
|
||||||
\
|
|
||||||
public: \
|
|
||||||
static const bool value = impl<trait_name##_detail::template has_member<Z,IsCallPossibleSignature>::value, \
|
|
||||||
IsCallPossibleSignature>::value; \
|
|
||||||
}
|
|
||||||
|
|
||||||
} // beast
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user