Use namespaces instead of static-only classes

This commit is contained in:
Nik Bougalis
2014-09-21 15:02:21 -07:00
committed by Vinnie Falco
parent 60330da25c
commit 4640079f55
4 changed files with 57 additions and 76 deletions

View File

@@ -33,22 +33,21 @@ namespace beast
Contains some static helper functions for manipulating the MS Windows registry Contains some static helper functions for manipulating the MS Windows registry
(Only available on Windows, of course!) (Only available on Windows, of course!)
*/ */
class WindowsRegistry namespace WindowsRegistry
{ {
public:
//============================================================================== //==============================================================================
/** Returns a string from the registry. /** Returns a string from the registry.
The path is a string for the entire path of a value in the registry, The path is a string for the entire path of a value in the registry,
e.g. "HKEY_CURRENT_USER\Software\foo\bar" e.g. "HKEY_CURRENT_USER\Software\foo\bar"
*/ */
static String getValue (const String& regValuePath, String getValue (const String& regValuePath,
const String& defaultValue = String::empty); const String& defaultValue = String::empty);
/** Returns a string from the WOW64 registry. /** Returns a string from the WOW64 registry.
The path is a string for the entire path of a value in the registry, The path is a string for the entire path of a value in the registry,
e.g. "HKEY_CURRENT_USER\Software\foo\bar" e.g. "HKEY_CURRENT_USER\Software\foo\bar"
*/ */
static String getValueWow64 (const String& regValuePath, String getValueWow64 (const String& regValuePath,
const String& defaultValue = String::empty); const String& defaultValue = String::empty);
/** Reads a binary block from the registry. /** Reads a binary block from the registry.
@@ -56,39 +55,39 @@ public:
e.g. "HKEY_CURRENT_USER\Software\foo\bar" e.g. "HKEY_CURRENT_USER\Software\foo\bar"
@returns a DWORD indicating the type of the key. @returns a DWORD indicating the type of the key.
*/ */
static std::uint32_t getBinaryValue (const String& regValuePath, MemoryBlock& resultData); std::uint32_t getBinaryValue (const String& regValuePath, MemoryBlock& resultData);
/** Sets a registry value as a string. /** Sets a registry value as a string.
This will take care of creating any groups needed to get to the given registry value. This will take care of creating any groups needed to get to the given registry value.
*/ */
static bool setValue (const String& regValuePath, const String& value); bool setValue (const String& regValuePath, const String& value);
/** Sets a registry value as a DWORD. /** Sets a registry value as a DWORD.
This will take care of creating any groups needed to get to the given registry value. This will take care of creating any groups needed to get to the given registry value.
*/ */
static bool setValue (const String& regValuePath, std::uint32_t value); bool setValue (const String& regValuePath, std::uint32_t value);
/** Sets a registry value as a QWORD. /** Sets a registry value as a QWORD.
This will take care of creating any groups needed to get to the given registry value. This will take care of creating any groups needed to get to the given registry value.
*/ */
static bool setValue (const String& regValuePath, std::uint64_t value); bool setValue (const String& regValuePath, std::uint64_t value);
/** Sets a registry value as a binary block. /** Sets a registry value as a binary block.
This will take care of creating any groups needed to get to the given registry value. This will take care of creating any groups needed to get to the given registry value.
*/ */
static bool setValue (const String& regValuePath, const MemoryBlock& value); bool setValue (const String& regValuePath, const MemoryBlock& value);
/** Returns true if the given value exists in the registry. */ /** Returns true if the given value exists in the registry. */
static bool valueExists (const String& regValuePath); bool valueExists (const String& regValuePath);
/** Returns true if the given value exists in the registry. */ /** Returns true if the given value exists in the registry. */
static bool valueExistsWow64 (const String& regValuePath); bool valueExistsWow64 (const String& regValuePath);
/** Deletes a registry value. */ /** Deletes a registry value. */
static void deleteValue (const String& regValuePath); void deleteValue (const String& regValuePath);
/** Deletes a registry key (which is registry-talk for 'folder'). */ /** Deletes a registry key (which is registry-talk for 'folder'). */
static void deleteKey (const String& regKeyPath); void deleteKey (const String& regKeyPath);
/** Creates a file association in the registry. /** Creates a file association in the registry.
@@ -106,16 +105,12 @@ public:
unless running in an installer). If true, it will register the unless running in an installer). If true, it will register the
association in HKEY_CURRENT_USER. association in HKEY_CURRENT_USER.
*/ */
static bool registerFileAssociation (const String& fileExtension, bool registerFileAssociation (const String& fileExtension,
const String& symbolicDescription, const String& symbolicDescription,
const String& fullDescription, const String& fullDescription,
const File& targetExecutable, const File& targetExecutable,
int iconResourceNumber, int iconResourceNumber,
bool registerForCurrentUserOnly); bool registerForCurrentUserOnly);
WindowsRegistry() = delete;
WindowsRegistry(WindowsRegistry const&) = delete;
WindowsRegistry const& operator= (WindowsRegistry const&) = delete;
}; };
#endif #endif

View File

@@ -38,7 +38,7 @@ class MemoryBlock;
@see OutputStream, FileInputStream @see OutputStream, FileInputStream
*/ */
class InputStream class InputStream
, LeakChecked <InputStream> : LeakChecked <InputStream>
{ {
public: public:
/** Destructor. */ /** Destructor. */

View File

@@ -31,14 +31,13 @@ namespace beast
/** /**
Contains methods for finding out about the current hardware and OS configuration. Contains methods for finding out about the current hardware and OS configuration.
*/ */
class SystemStats namespace SystemStats
{ {
public:
//============================================================================== //==============================================================================
/** Returns the current version of BEAST, /** Returns the current version of BEAST,
See also the BEAST_VERSION, BEAST_MAJOR_VERSION and BEAST_MINOR_VERSION macros. See also the BEAST_VERSION, BEAST_MAJOR_VERSION and BEAST_MINOR_VERSION macros.
*/ */
static String getBeastVersion(); String getBeastVersion();
//============================================================================== //==============================================================================
/** The set of possible results of the getOperatingSystemType() method. */ /** The set of possible results of the getOperatingSystemType() method. */
@@ -73,95 +72,95 @@ public:
@returns one of the values from the OperatingSystemType enum. @returns one of the values from the OperatingSystemType enum.
@see getOperatingSystemName @see getOperatingSystemName
*/ */
static OperatingSystemType getOperatingSystemType(); OperatingSystemType getOperatingSystemType();
/** Returns the name of the type of operating system we're running on. /** Returns the name of the type of operating system we're running on.
@returns a string describing the OS type. @returns a string describing the OS type.
@see getOperatingSystemType @see getOperatingSystemType
*/ */
static String getOperatingSystemName(); String getOperatingSystemName();
/** Returns true if the OS is 64-bit, or false for a 32-bit OS. /** Returns true if the OS is 64-bit, or false for a 32-bit OS.
*/ */
static bool isOperatingSystem64Bit(); bool isOperatingSystem64Bit();
/** Returns an environment variable. /** Returns an environment variable.
If the named value isn't set, this will return the defaultValue string instead. If the named value isn't set, this will return the defaultValue string instead.
*/ */
static String getEnvironmentVariable (const String& name, const String& defaultValue); String getEnvironmentVariable (const String& name, const String& defaultValue);
//============================================================================== //==============================================================================
/** Returns the current user's name, if available. /** Returns the current user's name, if available.
@see getFullUserName() @see getFullUserName()
*/ */
static String getLogonName(); String getLogonName();
/** Returns the current user's full name, if available. /** Returns the current user's full name, if available.
On some OSes, this may just return the same value as getLogonName(). On some OSes, this may just return the same value as getLogonName().
@see getLogonName() @see getLogonName()
*/ */
static String getFullUserName(); String getFullUserName();
/** Returns the host-name of the computer. */ /** Returns the host-name of the computer. */
static String getComputerName(); String getComputerName();
/** Returns the language of the user's locale. /** Returns the language of the user's locale.
The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2) The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2)
*/ */
static String getUserLanguage(); String getUserLanguage();
/** Returns the region of the user's locale. /** Returns the region of the user's locale.
The return value is a 2 letter country code (ISO 3166-1 alpha-2). The return value is a 2 letter country code (ISO 3166-1 alpha-2).
*/ */
static String getUserRegion(); String getUserRegion();
/** Returns the user's display language. /** Returns the user's display language.
The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2) The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2)
*/ */
static String getDisplayLanguage(); String getDisplayLanguage();
//============================================================================== //==============================================================================
// CPU and memory information.. // CPU and memory information..
/** Returns the number of CPU cores. */ /** Returns the number of CPU cores. */
static int getNumCpus() noexcept; int getNumCpus() noexcept;
/** Returns the approximate CPU speed. /** Returns the approximate CPU speed.
@returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on @returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on
what year you're reading this...) what year you're reading this...)
*/ */
static int getCpuSpeedInMegaherz(); int getCpuSpeedInMegaherz();
/** Returns a string to indicate the CPU vendor. /** Returns a string to indicate the CPU vendor.
Might not be known on some systems. Might not be known on some systems.
*/ */
static String getCpuVendor(); String getCpuVendor();
static bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */ bool hasMMX() noexcept; /**< Returns true if Intel MMX instructions are available. */
static bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */ bool hasSSE() noexcept; /**< Returns true if Intel SSE instructions are available. */
static bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */ bool hasSSE2() noexcept; /**< Returns true if Intel SSE2 instructions are available. */
static bool hasSSE3() noexcept; /**< Returns true if Intel SSE2 instructions are available. */ bool hasSSE3() noexcept; /**< Returns true if Intel SSE2 instructions are available. */
static bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */ bool has3DNow() noexcept; /**< Returns true if AMD 3DNOW instructions are available. */
//============================================================================== //==============================================================================
/** Finds out how much RAM is in the machine. /** Finds out how much RAM is in the machine.
@returns the approximate number of megabytes of memory, or zero if @returns the approximate number of megabytes of memory, or zero if
something goes wrong when finding out. something goes wrong when finding out.
*/ */
static int getMemorySizeInMegabytes(); int getMemorySizeInMegabytes();
/** Returns the system page-size. /** Returns the system page-size.
This is only used by programmers with beards. This is only used by programmers with beards.
*/ */
static int getPageSize(); int getPageSize();
//============================================================================== //==============================================================================
/** Returns a backtrace of the current call-stack. /** Returns a backtrace of the current call-stack.
The usefulness of the result will depend on the level of debug symbols The usefulness of the result will depend on the level of debug symbols
that are available in the executable. that are available in the executable.
*/ */
static String getStackBacktrace(); String getStackBacktrace();
/** A void() function type, used by setApplicationCrashHandler(). */ /** A void() function type, used by setApplicationCrashHandler(). */
typedef void (*CrashHandlerFunction)(); typedef void (*CrashHandlerFunction)();
@@ -172,14 +171,7 @@ public:
You may want to call getStackBacktrace() in your handler function, to find out You may want to call getStackBacktrace() in your handler function, to find out
where the problem happened and log it, etc. where the problem happened and log it, etc.
*/ */
static void setApplicationCrashHandler (CrashHandlerFunction); void setApplicationCrashHandler (CrashHandlerFunction);
private:
//==============================================================================
SystemStats() = delete;
SystemStats (SystemStats const&) = delete;
SystemStats const& operator= (SystemStats const&) = delete;
}; };
} // beast } // beast

View File

@@ -34,9 +34,8 @@ namespace beast {
@see Thread, BEASTApplication @see Thread, BEASTApplication
*/ */
class Process namespace Process
{ {
public:
//============================================================================== //==============================================================================
enum ProcessPriority enum ProcessPriority
{ {
@@ -51,7 +50,7 @@ public:
@param priority the process priority, where @param priority the process priority, where
0=low, 1=normal, 2=high, 3=realtime 0=low, 1=normal, 2=high, 3=realtime
*/ */
static void setPriority (const ProcessPriority priority); void setPriority (const ProcessPriority priority);
/** Kills the current process immediately. /** Kills the current process immediately.
@@ -61,18 +60,18 @@ public:
@see BEASTApplication::quit @see BEASTApplication::quit
*/ */
static void terminate(); void terminate();
//============================================================================== //==============================================================================
/** Returns true if this application process is the one that the user is /** Returns true if this application process is the one that the user is
currently using. currently using.
*/ */
static bool isForegroundProcess(); bool isForegroundProcess();
/** Attempts to make the current process the active one. /** Attempts to make the current process the active one.
(This is not possible on some platforms). (This is not possible on some platforms).
*/ */
static void makeForegroundProcess(); void makeForegroundProcess();
//============================================================================== //==============================================================================
/** Raises the current process's privilege level. /** Raises the current process's privilege level.
@@ -80,21 +79,21 @@ public:
Does nothing if this isn't supported by the current OS, or if process Does nothing if this isn't supported by the current OS, or if process
privilege level is fixed. privilege level is fixed.
*/ */
static void raisePrivilege(); void raisePrivilege();
/** Lowers the current process's privilege level. /** Lowers the current process's privilege level.
Does nothing if this isn't supported by the current OS, or if process Does nothing if this isn't supported by the current OS, or if process
privilege level is fixed. privilege level is fixed.
*/ */
static void lowerPrivilege(); void lowerPrivilege();
/** Returns true if this process is being hosted by a debugger. */ /** Returns true if this process is being hosted by a debugger. */
static bool isRunningUnderDebugger(); bool isRunningUnderDebugger();
//============================================================================== //==============================================================================
/** Tries to launch the OS's default reader application for a given file or URL. */ /** Tries to launch the OS's default reader application for a given file or URL. */
static bool openDocument (const String& documentURL, const String& parameters); bool openDocument (const String& documentURL, const String& parameters);
#if BEAST_WINDOWS || DOXYGEN #if BEAST_WINDOWS || DOXYGEN
//============================================================================== //==============================================================================
@@ -111,7 +110,7 @@ public:
to provide the correct module handle in your DllMain() function, because to provide the correct module handle in your DllMain() function, because
the system relies on the correct instance handle when opening windows. the system relies on the correct instance handle when opening windows.
*/ */
static void* getCurrentModuleInstanceHandle() noexcept; void* getCurrentModuleInstanceHandle() noexcept;
/** WINDOWS ONLY - Sets a new module handle to be used by the library. /** WINDOWS ONLY - Sets a new module handle to be used by the library.
@@ -120,19 +119,14 @@ public:
@see getCurrentModuleInstanceHandle() @see getCurrentModuleInstanceHandle()
*/ */
static void setCurrentModuleInstanceHandle (void* newHandle) noexcept; void setCurrentModuleInstanceHandle (void* newHandle) noexcept;
#endif #endif
#if BEAST_MAC || DOXYGEN #if BEAST_MAC || DOXYGEN
//============================================================================== //==============================================================================
/** OSX ONLY - Shows or hides the OSX dock icon for this app. */ /** OSX ONLY - Shows or hides the OSX dock icon for this app. */
static void setDockIconVisible (bool isVisible); void setDockIconVisible (bool isVisible);
#endif #endif
private:
Process() = delete;
Process (Process const&) = delete;
Process const& operator= (Process const&) = delete;
}; };
} // beast } // beast