2015-09-30 02:56:11 +02:00
|
|
|
#ifndef _BASE_SHARED_HPP_
|
|
|
|
#define _BASE_SHARED_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
#include "SqBase.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
#include <cmath>
|
2016-03-26 17:14:47 +01:00
|
|
|
#include <limits>
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <vcmp.h>
|
|
|
|
#include <sqrat.h>
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
extern const SQChar * g_EmptyStr;
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2015-11-01 09:55:47 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Proxies to communicate with the server.
|
2015-11-01 09:55:47 +01:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
extern PluginFuncs* _Func;
|
|
|
|
extern PluginCallbacks* _Clbk;
|
|
|
|
extern PluginInfo* _Info;
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Implements RAII to restore the VM stack to it's initial size on function exit.
|
|
|
|
*/
|
|
|
|
struct StackGuard
|
|
|
|
{
|
2016-03-12 07:47:50 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
StackGuard()
|
2016-04-02 11:32:39 +02:00
|
|
|
: m_VM(DefaultVM::Get()), m_Top(sq_gettop(m_VM))
|
2016-03-12 07:47:50 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
|
|
|
StackGuard(HSQUIRRELVM vm)
|
2016-04-02 11:32:39 +02:00
|
|
|
: m_VM(vm), m_Top(sq_gettop(vm))
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
StackGuard(const StackGuard &) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor. (disabled)
|
|
|
|
*/
|
|
|
|
StackGuard(StackGuard &&) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~StackGuard()
|
|
|
|
{
|
|
|
|
sq_pop(m_VM, sq_gettop(m_VM) - m_Top);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator. (disabled)
|
|
|
|
*/
|
|
|
|
StackGuard & operator = (const StackGuard &) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator. (disabled)
|
|
|
|
*/
|
|
|
|
StackGuard & operator = (StackGuard &&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-04-02 11:32:39 +02:00
|
|
|
HSQUIRRELVM m_VM; // The VM where the stack should be restored.
|
|
|
|
Int32 m_Top; // The top of the stack when this instance was created.
|
2016-03-10 04:57:13 +01:00
|
|
|
};
|
|
|
|
|
2016-03-24 23:25:03 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Helper structure for retrieving a value from the stack as a string or a formatted string.
|
|
|
|
*/
|
|
|
|
struct StackStrF
|
|
|
|
{
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
CSStr mPtr; // Pointer to the C string that was retrieved.
|
|
|
|
SQInteger mLen; // The string length if it could be retrieved.
|
|
|
|
SQRESULT mRes; // The result of the retrieval attempts.
|
|
|
|
HSQOBJECT mObj; // Strong reference to the string object.
|
|
|
|
HSQUIRRELVM mVM; // The associated virtual machine.
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
|
|
|
StackStrF(HSQUIRRELVM vm, SQInteger idx, bool fmt = true);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
StackStrF(const StackStrF & o) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
StackStrF(StackStrF && o) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~StackStrF();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
StackStrF & operator = (const StackStrF & o) = delete;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
|
|
|
StackStrF & operator = (StackStrF && o) = delete;
|
|
|
|
};
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Perform an equality comparison between two values taking into account floating point issues.
|
|
|
|
*/
|
2015-11-01 04:48:01 +01:00
|
|
|
template< typename T > inline bool EpsEq(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return abs(a - b) <= 0;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
template <> inline bool EpsEq(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return fabs(a - b) <= 0.000001f;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
template <> inline bool EpsEq(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return fabs(a - b) <= 0.000000001d;
|
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Perform a less than comparison between two values taking into account floating point issues.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template< typename T > inline bool EpsLt(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a < b);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLt(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) < 0.000001f;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLt(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) < 0.000000001d;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Perform a greater than comparison between two values taking into account floating point issues.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template< typename T > inline bool EpsGt(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a > b);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGt(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) > 0.000001f;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGt(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) && (a - b) > 0.000000001d;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Perform a less than or equal comparison between two values taking into account
|
|
|
|
* floating point issues.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template< typename T > inline bool EpsLtEq(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a < b);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLtEq(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) < 0.000001f;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsLtEq(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) < 0.000000001d;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Perform a greater than or equal comparison between two values taking into account
|
|
|
|
* floating point issues.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template< typename T > inline bool EpsGtEq(const T a, const T b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a > b);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGtEq(const Float32 a, const Float32 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) > 0.000001f;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
template <> inline bool EpsGtEq(const Float64 a, const Float64 b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return !EpsEq(a, b) || (a - b) > 0.000000001d;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Force a value to be within a certain range.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template< typename T > inline T Clamp(T val, T min, T max)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return val < min ? min : (val > max ? max : val);
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-26 17:14:47 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Force a value to be the boundaries of the specified type.
|
|
|
|
*/
|
|
|
|
template< typename T, typename U > inline U ClampL(T val)
|
|
|
|
{
|
|
|
|
// Is the specified value bellow the minimum?
|
|
|
|
if (val < std::numeric_limits< U >::min())
|
|
|
|
{
|
|
|
|
return std::numeric_limits< U >::min();
|
|
|
|
}
|
|
|
|
// Is the specified value above the maximum?
|
|
|
|
else if (val > std::numeric_limits< U >::max())
|
|
|
|
{
|
|
|
|
return std::numeric_limits< U >::max();
|
|
|
|
}
|
|
|
|
// Return the value as is
|
|
|
|
return static_cast< U >(val);
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Compute the next power of two for the specified number.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
inline Uint32 NextPow2(Uint32 num)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
--num;
|
|
|
|
num |= num >> 1;
|
|
|
|
num |= num >> 2;
|
|
|
|
num |= num >> 4;
|
|
|
|
num |= num >> 8;
|
|
|
|
num |= num >> 16;
|
|
|
|
return ++num;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-02-27 10:57:10 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Output a message only if the _DEBUG was defined.
|
|
|
|
*/
|
|
|
|
void OutputDebug(const char * msg, ...);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Output a formatted user message to the console.
|
|
|
|
*/
|
|
|
|
void OutputMessage(const char * msg, ...);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Output a formatted error message to the console.
|
|
|
|
*/
|
|
|
|
void OutputError(const char * msg, ...);
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve a reference to a null script object.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Object & NullObject();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve a reference to a null/empty script array.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Array & NullArray();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve a reference to a null script function.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Function & NullFunction();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-11 03:23:59 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Create a script string object from a buffer.
|
|
|
|
*/
|
|
|
|
Object BufferToStrObj(const Buffer & b);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Create a script string object from a portion of a buffer.
|
|
|
|
*/
|
|
|
|
Object BufferToStrObj(const Buffer & b, Uint32 size);
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Create a script object from the specified value on the default VM.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template < typename T > Object MakeObject(const T & v)
|
|
|
|
{
|
2016-03-24 23:25:03 +01:00
|
|
|
// Remember the current stack size
|
|
|
|
const StackGuard sg;
|
2016-03-21 21:37:58 +01:00
|
|
|
// Transform the specified value into a script object
|
2016-02-20 23:25:00 +01:00
|
|
|
PushVar< T >(DefaultVM::Get(), v);
|
2016-03-24 23:25:03 +01:00
|
|
|
// Get the object from the stack and return it
|
|
|
|
return Var< Object >(DefaultVM::Get(), -1).value;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Create a script object from the specified value on the specified VM.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
template < typename T > Object MakeObject(HSQUIRRELVM vm, const T & v)
|
|
|
|
{
|
2016-03-24 23:25:03 +01:00
|
|
|
// Remember the current stack size
|
|
|
|
const StackGuard sg;
|
2016-03-21 21:37:58 +01:00
|
|
|
// Transform the specified value into a script object
|
2016-02-20 23:25:00 +01:00
|
|
|
PushVar< T >(vm, v);
|
2016-03-24 23:25:03 +01:00
|
|
|
// Get the object from the stack and return it
|
|
|
|
return Var< Object >(vm, -1).value;
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
* Simple function to check whether the specified string can be considered as a boolean value
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
bool SToB(CSStr str);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Generate a formatted string and throw it as a sqrat exception.
|
|
|
|
*/
|
|
|
|
void SqThrowF(CCStr fmt, ...);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Quickly generate a formatted string on a small static buffer without any memory allocations.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr ToStrF(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Generate a formatted string on a temporary buffer and return the string but not the buffer.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr ToStringF(CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Obtain a randomly chosen color from a list of known colors.
|
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
const Color3 & GetRandomColor();
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-03-10 04:57:13 +01:00
|
|
|
* Attempt to identify the color in the specified name and return it.
|
2015-09-30 02:56:11 +02:00
|
|
|
*/
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3 GetColor(CSStr name);
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
2016-03-21 21:37:58 +01:00
|
|
|
* Primary logging functions.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
|
|
|
void LogDbg(CCStr fmt, ...);
|
|
|
|
void LogUsr(CCStr fmt, ...);
|
|
|
|
void LogScs(CCStr fmt, ...);
|
|
|
|
void LogInf(CCStr fmt, ...);
|
|
|
|
void LogWrn(CCStr fmt, ...);
|
|
|
|
void LogErr(CCStr fmt, ...);
|
|
|
|
void LogFtl(CCStr fmt, ...);
|
|
|
|
|
2016-03-21 21:37:58 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
|
|
|
* Secondary logging functions.
|
|
|
|
*/
|
2016-03-10 04:57:13 +01:00
|
|
|
void LogSDbg(CCStr fmt, ...);
|
|
|
|
void LogSUsr(CCStr fmt, ...);
|
|
|
|
void LogSScs(CCStr fmt, ...);
|
|
|
|
void LogSInf(CCStr fmt, ...);
|
|
|
|
void LogSWrn(CCStr fmt, ...);
|
|
|
|
void LogSErr(CCStr fmt, ...);
|
|
|
|
void LogSFtl(CCStr fmt, ...);
|
|
|
|
|
2016-03-21 21:37:58 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
|
|
|
* Primary conditional logging functions.
|
|
|
|
*/
|
2016-03-10 04:57:13 +01:00
|
|
|
bool cLogDbg(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogUsr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogScs(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogInf(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogWrn(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogErr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogFtl(bool cond, CCStr fmt, ...);
|
|
|
|
|
2016-03-21 21:37:58 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Forward declarations of the logging functions to avoid including the logger everywhere.
|
|
|
|
* Secondary conditional logging functions.
|
|
|
|
*/
|
2016-03-10 04:57:13 +01:00
|
|
|
bool cLogSDbg(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSUsr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSScs(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSInf(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSWrn(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSErr(bool cond, CCStr fmt, ...);
|
|
|
|
bool cLogSFtl(bool cond, CCStr fmt, ...);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2016-03-29 04:39:17 +02:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Helper class allows the use of functions with ctype style as predicate for algorithms.
|
|
|
|
*/
|
|
|
|
struct IsCType
|
|
|
|
{
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
typedef int (*CTypeFn)(int); // The signature of a ctype function.
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CTypeFn m_Fn; // Pointer to the actual function that does the comparison.
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
|
|
|
IsCType(CTypeFn fn)
|
|
|
|
: m_Fn(fn)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Function call operator.
|
|
|
|
*/
|
|
|
|
template < typename T > bool operator () (T c)
|
|
|
|
{
|
|
|
|
return (m_Fn(static_cast< int >(c)) != 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Helper class allows the use of functions with ctype style as predicate for algorithms.
|
|
|
|
*/
|
|
|
|
struct IsNotCType
|
|
|
|
{
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
typedef int (*CTypeFn)(int); // The signature of a ctype function.
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
CTypeFn m_Fn; // Pointer to the actual function that does the comparison.
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
|
|
|
IsNotCType(CTypeFn fn)
|
|
|
|
: m_Fn(fn)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Function call operator.
|
|
|
|
*/
|
|
|
|
template < typename T > bool operator () (T c)
|
|
|
|
{
|
|
|
|
return (m_Fn(static_cast< int >(c)) == 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _BASE_SHARED_HPP_
|