nux-4.0.8+16.04.20160209/ 0000755 0000156 0000165 00000000000 12656240224 014704 5 ustar pbuser pbgroup 0000000 0000000 nux-4.0.8+16.04.20160209/NuxCore/ 0000755 0000156 0000165 00000000000 12656240224 016267 5 ustar pbuser pbgroup 0000000 0000000 nux-4.0.8+16.04.20160209/NuxCore/OutputDevice.h 0000644 0000156 0000165 00000010412 12656236757 021076 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NOUTPUTDEVICE_H
#define NOUTPUTDEVICE_H
namespace nux
{
class NSerializer;
class LogOutputDevice
{
public:
LogOutputDevice ();
virtual ~LogOutputDevice ();
BOOL m_terminated;
virtual void Serialize (const TCHAR *log_data, const TCHAR *log_prefix, int severity) = 0;
virtual void Flush ();
virtual void Shutdown ();
VARARG_DECL (void/*FuncRet*/, void/*StaticFuncRet*/, {}/*Return*/, LogFunction/*FuncName*/, VARARG_NONE/*Pure*/, const TCHAR*/*FmtType*/, VARARG_EXTRA (int severity) /*ExtraDecl*/, VARARG_EXTRA (severity) /*ExtraParam*/ );
void Enable ();
void Disable ();
protected:
bool _object_destroyed;
bool _enabled;
};
//! Output to null device.
class NullOutput : public LogOutputDevice
{
NUX_DECLARE_GLOBAL_OBJECT (NullOutput, GlobalSingletonInitializer);
public:
void Serialize ( const TCHAR * /* V */, const TCHAR * /* LogPrefix */, int /* severity */) {}
};
//! Output to log file.
class LogFileOutput : public LogOutputDevice
{
NUX_DECLARE_GLOBAL_OBJECT (LogFileOutput, GlobalSingletonInitializer);
//LogFileOutput( const TCHAR* InFilename);
public:
/*!
Closes output device and cleans up.
*/
void Shutdown();
/*!
Flush the write cache so the output to the file isn't truncated.
*/
void Flush();
/*!
Write a stream to the log file.
@param log_data Stream characters to write.
@param LogPrefix A string to write before the input stream of characters.
*/
void Serialize (const TCHAR *log_data, const TCHAR *LogPrefix, int severity);
private:
NSerializer *m_LogSerializer;
std::string m_Filename;
bool m_Opened;
bool m_Closed;
/*!
Serialize data directly to the log file without any type of conversion or preprocessing.
@param log_data String of char to write to the output file.
*/
void SerializeRaw (const TCHAR *log_data);
};
//! Output to microsoft visual console.
class VisualOutputConsole : public LogOutputDevice
{
NUX_DECLARE_GLOBAL_OBJECT (VisualOutputConsole, GlobalSingletonInitializer);
public:
//! Write data to visual studio output debug console.
/*!
@param text Text to log.
@param log_prefix Prefix for the text.
@param severity Importance of the message.
*/
void Serialize (const TCHAR *text, const TCHAR *log_prefix, int severity);
};
//! Standard printf output console.
class PrintfOutputConsole : public LogOutputDevice
{
NUX_DECLARE_GLOBAL_OBJECT (PrintfOutputConsole, GlobalSingletonInitializer);
public:
//! Write text to the standard printf output debug console.
/*!
@param text Text to log.
@param log_prefix Prefix for the text.
@param severity Importance of the message.
*/
void Serialize (const TCHAR *text, const TCHAR *log_prefix, int severity);
};
class LogOutputRedirector : public LogOutputDevice
{
NUX_DECLARE_GLOBAL_OBJECT (LogOutputRedirector, GlobalSingletonInitializer);
public:
virtual void AddOutputDevice (LogOutputDevice *OutputDevice);
virtual void RemoveOutputDevice (LogOutputDevice *OutputDevice);
virtual bool IsRedirectingTo (LogOutputDevice *OutputDevice);
void Serialize (const TCHAR *log_data, const TCHAR *log_prefix, int severity);
void Flush();
void Shutdown();
private:
std::vector OutputDevices;
};
}
#endif // NOUTPUTDEVICE_H
nux-4.0.8+16.04.20160209/NuxCore/SystemWindows.h 0000644 0000156 0000165 00000030233 12656236757 021320 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef SYSTEMWIN32_H
#define SYSTEMWIN32_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
// If NUX_LOG_FILE_ANSI is set to 1, log files will be written in ASCII characters even when in UNICODE.
#define NUX_LOG_FILE_ANSI 1
// // Undo any Windows defines.
// #undef BYTE
// #undef WORD
// #undef DWORD
// #undef INT
// #undef FLOAT
// #undef MAXBYTE
// #undef MAXWORD
// #undef MAXDWORD
// #undef MAXINT
// #undef CDECL
// #undef BOOL
// #undef TCHAR
//
// // Undef Windows min and max. Conflict with std::min, std::max.
// #undef min
// #undef max
//
#define NUX_VARARGS __cdecl // Functions with variable arguments
// Calling Convention
// This is the default calling convention for C and C++ programs.
// Because the stack is cleaned up by the caller, it can do vararg functions.
// Argument-passing order: Right to left
#define NUX_CDECL __cdecl
// The __stdcall calling convention is used to call Win32 API functions.
// The callee cleans the stack, so the compiler makes vararg functions __cdecl.
// Argument-passing order: Right to left
#define NUX_STDCALL __stdcall
// The __fastcall calling convention specifies that arguments to functions are to be passed in registers, when possible.
#define NUX_FASTCALL __fastcall
// This is the default calling convention used by C++ member functions that do not use variable arguments.
// Under thiscall, the callee cleans the stack, which is impossible for vararg functions.
#define NUX_THISCALL thiscall //
#define NUX_INLINE inline // Force inline code
#define NUX_FORCEINLINE __forceinline // Force inline code
#define NUX_FORCENOINLINE __declspec(noinline) // Force code to NOT be inline
// Unsigned base types.
typedef unsigned char BYTE; // 8-bit unsigned.
typedef unsigned short WORD; // 16-bit unsigned.
typedef unsigned int UINT; // 32-bit unsigned.
typedef unsigned long DWORD; // 32-bit unsigned.
typedef unsigned __int64 QWORD; // 64-bit unsigned.
// Signed base types.
typedef signed char SBYTE; // 8-bit signed.
typedef signed short SWORD; // 16-bit signed.
typedef signed int INT; // 32-bit signed.
typedef signed __int64 SQWORD; // 64-bit signed.
// Character types.
typedef char ANSICHAR; // An ANSI character.
typedef unsigned char ANSIUCHAR; // An ANSI character.
typedef wchar_t UNICHAR; // A unicode character. L"Hello" is of type wchar_t and should not be confuse with type unsigned short on windows.
// Other base types.
typedef float FLOAT; // 32-bit IEEE floating point.
typedef double DOUBLE; // 64-bit IEEE double.
///////////////////////////////////////////////
// UNICODE //
///////////////////////////////////////////////
#ifdef _UNICODE
#ifndef _TCHAR_DEFINED
typedef wchar_t TCHAR;
#endif
#ifndef _TEXT_DEFINED
#undef TEXT
#define TEXT(s) L##s
#endif
#else
#ifndef _TCHAR_DEFINED
typedef ANSICHAR TCHAR;
#endif
#undef TEXT
#define TEXT(s) s
#endif
// #ifdef WIN32_SECURE
// #define STRNCPY_S(strDest, numberOfElements, strSource, count) strncpy_s(strDest, numberOfElements, strSource, count)
// #define WCSNCPY_S(strDest, numberOfElements, strSource, count) wcsncpy_s(strDest, numberOfElements, strSource, count)
// #define MBSNCPY_S(strDest, numberOfElements, strSource, count) _mbsncpy_s(strDest, numberOfElements, strSource, count)
// #define _TCSNCPY_S(strDest, numberOfElements, strSource, count) _tcsncpy_s(strDest, numberOfElements, strSource, count)
//
// #define STRCPY_S(strDest, numberOfElements, strSource) strcpy_s(strDest, numberOfElements, strSource)
// #define WCSCPY_S(strDest, numberOfElements, strSource) wcscpy_s(strDest, numberOfElements, strSource)
// #define MBSCPY_S(strDest, numberOfElements, strSource) _mbscpy_s(strDest, numberOfElements, strSource)
// #define _TCSCPY_S(strDest, numberOfElements, strSource) _tcscpy_s(strDest, numberOfElements, strSource)
//
// #define STRCAT_S(strDest, numberOfElements, strSource) strcat_s(strDest, numberOfElements, strSource)
// #define WCSCAT_S(strDest, numberOfElements, strSource) wcscat_s(strDest, numberOfElements, strSource)
// #define MBSCAT_S(strDest, numberOfElements, strSource) _mbscat_s(strDest, numberOfElements, strSource)
//
// #define _VSNPRINTF_S(strDest, numberOfElements, Count, Format, VA_Arg_List) _vsnprintf_s(strDest, numberOfElements, Count, Format, VA_Arg_List)
// #define _VSNTPRINTF_S(strDest, numberOfElements, Count, Format, VA_Arg_List) _vsntprintf_s(strDest, numberOfElements, Count, Format, VA_Arg_List)
// #define SPRINTF_S(strDest, numberOfElements, Format, ...) sprintf_s(strDest, numberOfElements, Format, ##__VA_ARGS__)
// #define _SNPRINTF_S(strDest, numberOfElements, Count, Format, ...) _snprintf_s(strDest, numberOfElements, Count, Format, ##__VA_ARGS__)
//
// #define STRDATE_S(strDest, numberOfElements) _strdate_s(strDest, numberOfElements)
// #define _TSTRDATE_S(strDest, numberOfElements) _tstrdate_s(strDest, numberOfElements)
// #define _STRTIME_S(strDest, numberOfElements) _strtime_s(strDest, numberOfElements)
// #define _TSTRTIME_S(strDest, numberOfElements) _tstrtime_s(strDest, numberOfElements)
//
// #define FOPEN_S(file, filename, mode) fopen_s(file, filename, mode)
//
// #define _TCSNLEN(str, numberOfElements) _tcsnlen(str)
//
// #define _TSPLITPATH(path, Drive, DriveNumElements, Dir, DirNumElements, Filename, FileNumElements, Extension, ExtNumElements) _tsplitpath_s(path, Drive, DriveNumElements, Dir, DirNumElements, Filename, FileNumElements, Extension, ExtNumElements)
// #define _TMAKEPATH_S(path, numberOfElements, Drive, Dir, Filename, Extension) _tmakepath_s(path, numberOfElements, Drive, Dir, Filename, Extension)
//
// #define SSCANF_S(buffer, Format, ...) sscanf_s(buffer, Format, ##__VA_ARGS__)
// #define SWSCANF_S(buffer, Format, ...) swscanf_s(buffer, Format, ##__VA_ARGS__)
//
// #else
// #define STRNCPY_S(strDest, numberOfElements, strSource, count) strncpy(strDest, strSource, count)
// #define WCSNCPY_S(strDest, numberOfElements, strSource, count) wcsncpy(strDest, strSource, count)
// #define MBSNCPY_S(strDest, numberOfElements, strSource, count) _mbsncpy(strDest, strSource, count)
// #define _TCSNCPY_S(strDest, numberOfElements, strSource, count) _tcsncpy(strDest, strSource, count)
//
// #define STRCPY_S(strDest, numberOfElements, strSource) strcpy(strDest, strSource)
// #define WCSCPY_S(strDest, numberOfElements, strSource) wcscpy(strDest, strSource)
// #define MBSCPY_S(strDest, numberOfElements, strSource) _mbscpy(strDest, strSource)
// #define _TCSCPY_S(strDest, numberOfElements, strSource) _tcscpy(strDest, strSource)
//
// #define STRCAT_S(strDest, numberOfElements, strSource) strcat(strDest, strSource)
// #define WCSCAT_S(strDest, numberOfElements, strSource) wcscat(strDest, strSource)
// #define MBSCAT_S(strDest, numberOfElements, strSource) _mbscat(strDest, strSource)
//
// #define _VSNPRINTF_S(strDest, numberOfElements, Count, Format, VA_Arg_List) _vsnprintf(strDest, Count, Format, VA_Arg_List)
// #define _VSNTPRINTF_S(strDest, numberOfElements, Count, Format, VA_Arg_List) _vsntprintf(strDest, Count, Format, VA_Arg_List)
// #define SPRINTF_S(strDest, numberOfElements, Format, a,b,c,d,e,f,g,h,i,j,k,l) sprintf(strDest, Format, VARG(a),VARG(b),VARG(c),VARG(d),VARG(e),VARG(f),VARG(g),VARG(h),VARG(i),VARG(j),VARG(k),VARG(l))
// #define _SNPRINTF_S(strDest, numberOfElements, Count, Format, a,b,c,d,e,f,g,h,i,j,k,l) _snprintf(strDest, Count, Format, VARG(a),VARG(b),VARG(c),VARG(d),VARG(e),VARG(f),VARG(g),VARG(h),VARG(i),VARG(j),VARG(k),VARG(l))
//
// #define STRDATE_S(strDest, numberOfElements) _strdate(strDest)
// #define _TSTRDATE_S(strDest, numberOfElements) _tstrdate(strDest)
// #define _STRTIME_S(strDest, numberOfElements) _strtime(strDest)
// #define _TSTRTIME_S(strDest, numberOfElements) _tstrtime(strDest)
//
// #define FOPEN_S(file, filename, mode) (file=fopen(filename, mode))
//
// #define _TCSNLEN(str, numberOfElements) _tcsclen(str)
//
// #define _TSPLITPATH(path, Drive, DriveNumElements, Dir, DirNumElements, Filename, FileNumElements, Extension, ExtNumElements) _tsplitpath(path, Drive, Dir, Filename, Extension)
// #define _TMAKEPATH_S(path, numberOfElements, Drive, Dir, Filename, Extension) _makepath(path, Drive, Dir, Filename, Extension)
//
// #define SSCANF_S(buffer, Format, VA_Arg_List) sscanf(buffer, Format, VA_Arg_List)
// #define SWSCANF_S(buffer, Format, VA_Arg_List) swscanf(buffer, Format, VA_Arg_List)
// #endif
///////////////////////////////////////////////
// Variable argument functions //
///////////////////////////////////////////////
//@note: Currently xutility breaks with this enabled 2005 fixes it
#pragma warning(disable : 4619) // #pragma warning : there is no warning number 'number'
//#pragma warning(disable : 4267) // #pragma warning : conversion from 'size_t' to 'int', possible loss of data
// Unwanted VC++ level 4 warnings to disable.
#pragma warning(disable : 4100) // unreferenced formal parameter
#pragma warning(disable : 4127) // Conditional expression is constant
#pragma warning(disable : 4200) // Zero-length array item at end of structure, a VC-specific extension
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#pragma warning(disable : 4244) // conversion to float, possible loss of data
#pragma warning(disable : 4245) // conversion from 'enum ' to 'unsigned long', signed/unsigned mismatch
#pragma warning(disable : 4251) // needs to have dll-interface to be used by clients of class 'ULinker'
#pragma warning(disable : 4275) // non dll-interface class used as base for dll-interface class
#pragma warning(disable : 4291) // typedef-name '' used as synonym for class-name ''
#pragma warning(disable : 4324) // structure was padded due to __declspec(align())
#pragma warning(disable : 4355) // this used in base initializer list
#pragma warning(disable : 4389) // signed/unsigned mismatch
#pragma warning(disable : 4511) // copy constructor could not be generated
#pragma warning(disable : 4512) // assignment operator could not be generated
#pragma warning(disable : 4514) // unreferenced inline function has been removed
#pragma warning(disable : 4699) // creating precompiled header
#pragma warning(disable : 4702) // unreachable code in inline expanded function
#pragma warning(disable : 4710) // inline function not expanded
#pragma warning(disable : 4711) // function selected for autmatic inlining
#pragma warning(disable : 4714) // __forceinline function not expanded
namespace nux
{
void *GetDllHandle ( const TCHAR *DllName );
void FreeDllHandle ( void *DllHandle );
void *GetDllExport ( void *DllHandle, const TCHAR *ExportName );
}
#endif // SYSTEMWIN32_H
nux-4.0.8+16.04.20160209/NuxCore/Colors.cpp 0000644 0000156 0000165 00000017543 12656236757 020266 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "Colors.h"
namespace nux
{
namespace color
{
// Definition of Luma coefficients as per ITU-R Recommendation BT.601
// http://en.wikipedia.org/wiki/Rec._601
const float LumaRed = 0.299f;
const float LumaGreen = 0.587f;
const float LumaBlue = 0.114f;
// // Definition of Luma coefficients as per ITU-R Recommendation BT.709
// // http://en.wikipedia.org/wiki/Rec._709
// float LumaRed = 0.2126f;
// float LumaGreen = 0.7152f;
// float LumaBlue = 0.0722f;
const Color Transparent(0, 0, 0, 0);
//Red colors
const Color IndianRed(0xCD, 0x5C, 0x5C);
const Color LightCoral(0xF0, 0x80, 0x80);
const Color Salmon(0xFA, 0x80, 0x72);
const Color DarkSalmon(0xE9, 0x96, 0x7A);
const Color LightSalmon(0xFF, 0xA0, 0x7A);
const Color Crimson(0xDC, 0x14, 0x3C);
const Color Red(0xFF, 0x00, 0x00);
const Color FireBrick(0xB2, 0x22, 0x22);
const Color DarkRed(0x8B, 0x00, 0x00);
//Pink colors
const Color Pink(0xFF, 0xC0, 0xCB);
const Color LightPink(0xFF, 0xB6, 0xC1);
const Color HotPink(0xFF, 0x69, 0xB4);
const Color DeepPink(0xFF, 0x14, 0x93);
const Color MediumVioletRed(0xC7, 0x15, 0x85);
const Color PaleVioletRed(0xDB, 0x70, 0x93);
//Orange colors
//const Color LightSalmon = Color (0xFF/255.0f, 0xA0/255.0f, 0x7A/255.0f);// 255 160 122
const Color Coral(0xFF, 0x7F, 0x50);
const Color Tomato(0xFF, 0x63, 0x47);
const Color OrangeRed(0xFF, 0x45, 0x00);
const Color DarkOrange(0xFF, 0x8C, 0x00);
const Color Orange(0xFF, 0xA5, 0x00);
//Yellow colors
const Color Gold(0xFF, 0xD7, 0x00);
const Color Yellow(0xFF, 0xFF, 0x00);
const Color LightYellow(0xFF, 0xFF, 0xE0);
const Color LemonChiffon(0xFF, 0xFA, 0xCD);
const Color LightGoldenrodYellow(0xFA, 0xFA, 0xD2);
const Color PapayaWhip(0xFF, 0xEF, 0xD5);
const Color Moccasin(0xFF, 0xE4, 0xB5);
const Color PeachPuff(0xFF, 0xDA, 0xB9);
const Color PaleGoldenrod(0xEE, 0xE8, 0xAA);
const Color Khaki(0xF0, 0xE6, 0x8C);
const Color DarkKhaki(0xBD, 0xB7, 0x6B);
//Purple colors
const Color Lavender(0xE6, 0xE6, 0xFA);
const Color Thistle(0xD8, 0xBF, 0xD8);
const Color Plum(0xDD, 0xA0, 0xDD);
const Color Violet(0xEE, 0x82, 0xEE);
const Color Orchid(0xDA, 0x70, 0xD6);
const Color Fuchsia(0xFF, 0x00, 0xFF);
const Color Magenta(0xFF, 0x00, 0xFF);
const Color MediumOrchid(0xBA, 0x55, 0xD3);
const Color MediumPurple(0x93, 0x70, 0xDB);
const Color BlueViolet(0x8A, 0x2B, 0xE2);
const Color DarkViolet(0x94, 0x00, 0xD3);
const Color DarkOrchid(0x99, 0x32, 0xCC);
const Color DarkMagenta(0x8B, 0x00, 0x8B);
const Color Purple(0x80, 0x00, 0x80);
const Color Indigo(0x4B, 0x00, 0x82);
const Color SlateBlue(0x6A, 0x5A, 0xCD);
const Color DarkSlateBlue(0x48, 0x3D, 0x8B);
//Green colors
const Color GreenYellow(0xAD, 0xFF, 0x2F);
const Color Chartreuse(0x7F, 0xFF, 0x00);
const Color LawnGreen(0x7C, 0xFC, 0x00);
const Color Lime(0x00, 0xFF, 0x00);
const Color LimeGreen(0x32, 0xCD, 0x32);
const Color PaleGreen(0x98, 0xFB, 0x98);
const Color LightGreen(0x90, 0xEE, 0x90);
const Color MediumSpringGreen(0x00, 0xFA, 0x9A);
const Color SpringGreen(0x00, 0xFF, 0x7F);
const Color MediumSeaGreen(0x3C, 0xB3, 0x71);
const Color SeaGreen(0x2E, 0x8B, 0x57);
const Color ForestGreen(0x22, 0x8B, 0x22);
const Color Green(0x00, 0x80, 0x00);
const Color DarkGreen(0x00, 0x64, 0x00);
const Color YellowGreen(0x9A, 0xCD, 0x32);
const Color OliveDrab(0x6B, 0x8E, 0x23);
const Color Olive(0x80, 0x80, 0x00);
const Color DarkOliveGreen(0x55, 0x6B, 0x2F);
const Color MediumAquamarine(0x66, 0xCD, 0xAA);
const Color DarkSeaGreen(0x8F, 0xBC, 0x8F);
const Color LightSeaGreen(0x20, 0xB2, 0xAA);
const Color DarkCyan(0x00, 0x8B, 0x8B);
const Color Teal(0x00, 0x80, 0x80);
//Blue colors
const Color Aqua(0x00, 0xFF, 0xFF);
const Color Cyan(0x00, 0xFF, 0xFF);
const Color LightCyan(0xE0, 0xFF, 0xFF);
const Color PaleTurquoise(0xAF, 0xEE, 0xEE);
const Color Aquamarine(0x7F, 0xFF, 0xD4);
const Color Turquoise(0x40, 0xE0, 0xD0);
const Color MediumTurquoise(0x48, 0xD1, 0xCC);
const Color DarkTurquoise(0x00, 0xCE, 0xD1);
const Color CadetBlue(0x5F, 0x9E, 0xA0);
const Color SteelBlue(0x46, 0x82, 0xB4);
const Color LightSteelBlue(0xB0, 0xC4, 0xDE);
const Color PowderBlue(0xB0, 0xE0, 0xE6);
const Color LightBlue(0xAD, 0xD8, 0xE6);
const Color SkyBlue(0x87, 0xCE, 0xEB);
const Color LightSkyBlue(0x87, 0xCE, 0xFA);
const Color DeepSkyBlue(0x00, 0xBF, 0xFF);
const Color DodgerBlue(0x1E, 0x90, 0xFF);
const Color CornflowerBlue(0x64, 0x95, 0xED);
const Color MediumSlateBlue(0x7B, 0x68, 0xEE);
const Color RoyalBlue(0x41, 0x69, 0xE1);
const Color Blue(0x00, 0x00, 0xFF);
const Color MediumBlue(0x00, 0x00, 0xCD);
const Color DarkBlue(0x00, 0x00, 0x8B);
const Color Navy(0x00, 0x00, 0x80);
const Color MidnightBlue(0x19, 0x19, 0x70);
//Brown colors
const Color Cornsilk(0xFF, 0xF8, 0xDC);
const Color BlanchedAlmond(0xFF, 0xEB, 0xCD);
const Color Bisque(0xFF, 0xE4, 0xC4);
const Color NavajoWhite(0xFF, 0xDE, 0xAD);
const Color Wheat(0xF5, 0xDE, 0xB3);
const Color BurlyWood(0xDE, 0xB8, 0x87);
const Color Tan(0xD2, 0xB4, 0x8C);
const Color RosyBrown(0xBC, 0x8F, 0x8F);
const Color SandyBrown(0xF4, 0xA4, 0x60);
const Color Goldenrod(0xDA, 0xA5, 0x20);
const Color DarkGoldenrod(0xB8, 0x86, 0x0B);
const Color Peru(0xCD, 0x85, 0x3F);
const Color Chocolate(0xD2, 0x69, 0x1E);
const Color SaddleBrown(0x8B, 0x45, 0x13);
const Color Sienna(0xA0, 0x52, 0x2D);
const Color Brown(0xA5, 0x2A, 0x2A);
const Color Maroon(0x80, 0x00, 0x00);
//White colors
const Color White(0xFF, 0xFF, 0xFF);
const Color Snow(0xFF, 0xFA, 0xFA);
const Color Honeydew(0xF0, 0xFF, 0xF0);
const Color MintCream(0xF5, 0xFF, 0xFA);
const Color Azure(0xF0, 0xFF, 0xFF);
const Color AliceBlue(0xF0, 0xF8, 0xFF);
const Color GhostWhite(0xF8, 0xF8, 0xFF);
const Color WhiteSmoke(0xF5, 0xF5, 0xF5);
const Color Seashell(0xFF, 0xF5, 0xEE);
const Color Beige(0xF5, 0xF5, 0xDC);
const Color OldLace(0xFD, 0xF5, 0xE6);
const Color FloralWhite(0xFF, 0xFA, 0xF0);
const Color Ivory(0xFF, 0xFF, 0xF0);
const Color AntiqueWhite(0xFA, 0xEB, 0xD7);
const Color Linen(0xFA, 0xF0, 0xE6);
const Color LavenderBlush(0xFF, 0xF0, 0xF5);
const Color MistyRose(0xFF, 0xE4, 0xE1);
//Grey colors
const Color Gainsboro(0xDC, 0xDC, 0xDC);
const Color LightGrey(0xD3, 0xD3, 0xD3);
const Color Silver(0xC0, 0xC0, 0xC0);
const Color DarkGray(0xA9, 0xA9, 0xA9);
const Color Gray(0x80, 0x80, 0x80);
const Color DimGray(0x69, 0x69, 0x69);
const Color LightSlateGray(0x77, 0x88, 0x99);
const Color SlateGray(0x70, 0x80, 0x90);
const Color DarkSlateGray(0x2F, 0x4F, 0x4F);
const Color Black(0x00, 0x00, 0x00);
// More Colors
const Color Aubergine(0x2B, 0x0B, 0x30);
}
}
nux-4.0.8+16.04.20160209/NuxCore/Animation.h 0000644 0000156 0000165 00000005105 12656236757 020400 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2012 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUX_CORE_ANIMATION_H
#define NUX_CORE_ANIMATION_H
#include
#include
#include "EasingCurve.h"
namespace nux
{
namespace animation
{
class Animation : boost::noncopyable
{
public:
enum State
{
Stopped,
Paused,
Running,
};
Animation();
virtual ~Animation();
virtual int Duration() const = 0;
virtual int CurrentTimePosition() const = 0;
void Start();
void Stop();
void Pause();
void Resume();
State CurrentState() const;
sigc::signal finished;
// Move the animation on so many milliseconds.
virtual void Advance(int msec) = 0;
protected:
virtual void Restart() = 0;
private:
State state_;
};
template
class AnimateValue : public Animation
{
public:
AnimateValue();
AnimateValue(int msec_duration);
AnimateValue(VALUE_TYPE const& start,
VALUE_TYPE const& finish,
int msec_duration);
AnimateValue& SetStartValue(VALUE_TYPE const& start);
AnimateValue& SetFinishValue(VALUE_TYPE const& finish);
AnimateValue& SetDuration(int msecs);
AnimateValue& SetEasingCurve(EasingCurve const& curve);
void Reverse();
virtual int Duration() const;
virtual int CurrentTimePosition() const;
sigc::signal updated;
VALUE_TYPE const& GetStartValue() const;
VALUE_TYPE const& GetFinishValue() const;
VALUE_TYPE const& GetCurrentValue() const;
// Move the animation on so many milliseconds.
virtual void Advance(int msec);
protected:
virtual void Restart();
private:
int msec_current_;
int msec_duration_;
VALUE_TYPE start_value_;
VALUE_TYPE finish_value_;
VALUE_TYPE current_value_;
EasingCurve easing_curve_;
};
}}
#include "Animation-inl.h"
#endif
nux-4.0.8+16.04.20160209/NuxCore/AnimationController.h 0000644 0000156 0000165 00000004701 12656236757 022445 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2012 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUX_CORE_ANIMATION_CONTROLLER_H
#define NUX_CORE_ANIMATION_CONTROLLER_H
#include
namespace nux
{
namespace animation
{
class Animation;
class TickSource
{
public:
virtual ~TickSource();
// tick value is in microseconds
sigc::signal tick;
};
/**
* The Animation Controller is responsible for updating running animations.
*
* The controller is constructed with a tick source, and operates as a
* pseudo-singleton. A controller must be created somewhere, and once it is,
* it set as the default controller. It is expected that there is only one
* animation controller.
*/
class Controller
{
public:
static Controller* Instance();
Controller();
virtual ~Controller();
virtual void AddAnimation(Animation* animation) = 0;
virtual void RemoveAnimation(Animation* animation) = 0;
virtual bool HasRunningAnimations() const = 0;
private:
#if defined(NUX_OS_WINDOWS) && !defined(NUX_VISUAL_STUDIO_VC11)
Controller(Controller const&);
Controller& operator = (Controller const&);
#else
Controller(Controller const&) = delete;
Controller& operator = (Controller const&) = delete;
#endif
};
class AnimationController : public Controller, public sigc::trackable
{
public:
AnimationController(TickSource& tick_source);
virtual ~AnimationController();
// tick is expected to be ever increasing
virtual void OnTick(long long tick);
virtual void AddAnimation(Animation* animation);
virtual void RemoveAnimation(Animation* animation);
virtual bool HasRunningAnimations() const;
private:
struct Impl;
Impl* pimpl;
};
}} // close namespaces
#endif
nux-4.0.8+16.04.20160209/NuxCore/Character/ 0000755 0000156 0000165 00000000000 12656240224 020163 5 ustar pbuser pbgroup 0000000 0000000 nux-4.0.8+16.04.20160209/NuxCore/Character/NAscii.cpp 0000644 0000156 0000165 00000005645 12656236757 022067 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "NAscii.h"
namespace nux
{
// Windows-1252 code page
t_uchar GAscii[] =
{
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0xFF,
'', 0x81, '', '', '', '', '', '', '', '', '', '', '', 0x8d, '', 0x8f,
0x90, '', '', '', '', '', '', '', 0x98, '', '', '', '', 0x9d, '', '',
0xa0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''
};
}
nux-4.0.8+16.04.20160209/NuxCore/Character/NUnicodeGNU.h 0000644 0000156 0000165 00000024450 12656236757 022437 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUNICODEGNU_H
#define NUNICODEGNU_H
namespace nux
{
// UTF-16 is the primary encoding mechanism used by Microsoft Windows 2000, Windows 2000 Server, Windows XP and Windows 2003 Server.
// Unicode Byte Order Mark (BOM)
enum {UNICODE_UTF32_BE = 0x0000FEFF };
enum {UNICODE_UTF32_LE = 0xFFFE0000 };
enum {UNICODE_UTF16_BE = 0xFEFF };
enum {UNICODE_UTF16_LE = 0xFFFE };
enum {UNICODE_UTF8 = 0xEFBBBF };
const BYTE UTF32_BE[] = {0x04 /*size*/, 0x00, 0x00, 0xFE, 0xFF };
const BYTE UTF32_LE[] = {0x04 /*size*/, 0xFF, 0xFE, 0x00, 0x00 };
const BYTE UTF16_BE[] = {0x02 /*size*/, 0xFE, 0xFF };
const BYTE UTF16_LE[] = {0x02 /*size*/, 0xFF, 0xFE };
const BYTE UTF8[] = {0x03 /*size*/, 0xEF, 0xBB, 0xBF };
enum {UNICODE_BOM = 0xfeff};
// UTF-16 is the default encoding form of the Unicode Standard
// On Linux and Mac OS X, wchar_t is 4 bytes!
// On windows wchar_t is 2 bytes!
#ifdef UNICODE
inline TCHAR ConvertAnsiCharToTCHAR (ANSICHAR In)
{
TCHAR output;
const t_UTF8 *source_start = &In;
const t_UTF8 *source_end = source_start + 1;
t_UTF16 *target_start = reinterpret_cast (&output);
t_UTF16 *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline ANSICHAR ConvertTCHARToAnsiChar (TCHAR In)
{
ANSICHAR output;
const t_UTF16 *source_start = &In;
const t_UTF16 *source_end = source_start + 1;
t_UTF8 *target_start = reinterpret_cast (&output);
t_UTF8 *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline TCHAR ConvertUnicodeCharToTCHAR (UNICHAR In)
{
return In;
}
inline UNICHAR ConvertTCHARToUnicodeChar (TCHAR In)
{
return In;
}
#else
inline TCHAR ConvertUnicodeCharToTCHAR (UNICHAR In)
{
TCHAR output;
const t_UTF16 *source_start = &In;
const t_UTF16 *source_end = source_start + 1;
t_UTF8 *target_start = reinterpret_cast (&output);
t_UTF8 *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline UNICHAR ConvertTCHARToUnicodeChar (TCHAR In)
{
UNICHAR output;
const t_UTF8 *source_start = reinterpret_cast (&In);
const t_UTF8 *source_end = source_start + 1;
t_UTF16 *target_start = reinterpret_cast (&output);
t_UTF16 *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline TCHAR ConvertAnsiCharToTCHAR (ANSICHAR In)
{
return In;
}
inline ANSICHAR ConvertTCHARToAnsiChar (TCHAR In)
{
return In;
}
#endif
/*!
Convert a single UNICHAR to ANSICHAR.
*/
inline ANSICHAR ConvertUnicodeCharToAnsiChar (UNICHAR In)
{
TCHAR output;
const t_UTF16 *source_start = &In;
const t_UTF16 *source_end = source_start + 1;
t_UTF8 *target_start = reinterpret_cast (&output);
t_UTF8 *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
/*!
Convert a single ANSICHAR to UNICHAR.
*/
inline UNICHAR ConvertAnsiCharToUnicodeChar (ANSICHAR In)
{
TCHAR output;
const t_UTF8 *source_start = reinterpret_cast (&In);
const t_UTF8 *source_end = source_start + 1;
t_UTF16 *target_start = reinterpret_cast (&output);
t_UTF16 *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
class UnicharToAnsicharConvertion
{
public:
// Default to ANSI code page
UnicharToAnsicharConvertion() {}
/*!
Convert from UNICHAR to ANSICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
ANSICHAR *Convert (const UNICHAR *Source)
{
std::wstring utf16string (Source);
size_t utf16size = utf16string.length();
size_t utf8size = 6 * utf16size + 1;
ANSICHAR *utf8string = new ANSICHAR[utf8size];
const t_UTF16 *source_start = utf16string.c_str();
const t_UTF16 *source_end = source_start + utf16size;
t_UTF8 *target_start = reinterpret_cast (&utf8string);
t_UTF8 *target_end = target_start + utf8size;
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
delete [] utf8string;
utf8string = 0;
}
// mark end of string
*target_start = 0;
return utf8string;
}
};
//! ANSICHAR to UNICHAR conversion
class AnsicharToUnicharConvertion
{
public:
NUX_INLINE AnsicharToUnicharConvertion() {}
/*!
Convert from ANSICHAR to UNICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
NUX_INLINE UNICHAR *Convert (const ANSICHAR *Source)
{
std::string utf8string (Source);
size_t utf8size = utf8string.length();
size_t utf16size = utf8size + 1;
UNICHAR *utf16string = new UNICHAR[utf16size];
const t_UTF8 *source_start = reinterpret_cast (utf8string.c_str() );
const t_UTF8 *source_end = source_start + utf8size;
t_UTF16 *target_start = reinterpret_cast (&utf16string);
t_UTF16 *target_end = target_start + utf16size;
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
delete [] utf16string;
utf16string = 0;
}
// mark end of string
*target_start = 0;
return utf16string;
}
};
//! TCHAR to ANSI conversion
// TCHAR can be ansi or unicode depending if UNICODE is defined or not.
class TCharToAnsiConvertion
{
public:
NUX_INLINE TCharToAnsiConvertion() {}
/*!
Convert from TCHAR to ANSICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
NUX_INLINE ANSICHAR *Convert (const TCHAR *Source)
{
// Determine whether we need to allocate memory or not
#ifdef UNICODE
UnicharToAnsicharConvertion convert;
return convert.Convert (Source);
#else
int length = strlen (Source) + 1;
int size = length * sizeof (ANSICHAR);
ANSICHAR *Dest = new ANSICHAR[size];
STRNCPY_S (Dest, size, Source, length);
return Dest;
#endif
}
};
//! ANSI to TCHAR conversion
// TCHAR can be ansi or unicode depending if UNICODE is defined or not.
class AnsiToTCharConversion
{
public:
NUX_INLINE AnsiToTCharConversion() {}
/*!
Convert from ANSICHAR to TCHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
NUX_INLINE TCHAR *Convert (const ANSICHAR *Source)
{
#ifdef UNICODE
AnsicharToUnicharConvertion convert;
return convert.Convert (Source);
#else
unsigned int length = strlen (Source) + 1;
unsigned int size = length;
TCHAR *Dest = new TCHAR[size];
STRNCPY_S (Dest, size, Source, length);
return Dest;
#endif
}
};
/*!
Convert from one string format to another.
*/
template < typename CONVERT_TO, typename CONVERT_FROM, typename BASE_CONVERTER, DWORD DefaultConversionSize = 128 >
class NCharacterConversion: public BASE_CONVERTER
{
CONVERT_TO *ConvertedString;
// Hide the default constructor
NCharacterConversion();
public:
/*!
Converts the data by using the Convert() method on the base class
*/
explicit inline NCharacterConversion (const CONVERT_FROM *Source)
{
if (Source != NULL)
{
// Use base class' convert method
ConvertedString = BASE_CONVERTER::Convert (Source);
}
else
{
ConvertedString = NULL;
}
}
/*!
If memory was allocated, then it is freed below
*/
inline ~NCharacterConversion()
{
if (ConvertedString != NULL)
{
delete [] ConvertedString;
}
}
// Operator to get access to the converted string
inline operator CONVERT_TO* (void) const
{
return ConvertedString;
}
};
// Conversion typedefs
typedef NCharacterConversion ANSI_To_TCHAR_Conversion;
typedef NCharacterConversion TCHAR_To_ANSI_Conversion;
typedef NCharacterConversion UNICHAR_To_ANSICHAR_Conversion;
typedef NCharacterConversion ANSICHAR_To_UNICHAR_Conversion;
}
#endif // NUNICODEGNU_H
nux-4.0.8+16.04.20160209/NuxCore/Character/NUnicodeGNU.cpp 0000644 0000156 0000165 00000001537 12656236757 022773 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "NUnicodeGNU.h"
namespace nux
{
}
nux-4.0.8+16.04.20160209/NuxCore/Character/NTChar.h 0000644 0000156 0000165 00000004237 12656236757 021501 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NTCHAR_H
#define NTCHAR_H
namespace nux
{
inline TCHAR ToUpperCase ( TCHAR c )
{
return (c < TEXT ('a') || c > TEXT ('z') ) ? (c) : (c + TEXT ('A') - TEXT ('a') );
}
inline TCHAR ToLowerCase ( TCHAR c )
{
return (c < TEXT ('A') || c > TEXT ('Z') ) ? (c) : (c + TEXT ('a') - TEXT ('A') );
}
inline bool IsUpperCase ( TCHAR c )
{
return (c >= TEXT ('A') && c <= TEXT ('Z') );
}
inline bool IsLowerCase ( TCHAR c )
{
return (c >= TEXT ('a') && c <= TEXT ('z') );
}
inline bool IsAlphaChar ( TCHAR c )
{
return (c >= TEXT ('a') && c <= TEXT ('z') ) || (c >= TEXT ('A') && c <= TEXT ('Z') );
}
inline bool IsDigitChar ( TCHAR c )
{
return c >= TEXT ('0') && c <= TEXT ('9');
}
inline bool IsAlphanumericChar ( TCHAR c )
{
return (c >= TEXT ('a') && c <= TEXT ('z') ) || (c >= TEXT ('A') && c <= TEXT ('Z') ) || (c >= TEXT ('0') && c <= TEXT ('9') );
}
inline bool IsWhitespaceChar ( TCHAR c )
{
return c == TEXT (' ') || c == TEXT ('\t');
}
inline bool IsLinebreakChar ( TCHAR c )
{
//@todo - support for language-specific line break characters
return c == TEXT ('\n');
}
/** Returns nonzero if character is a space character. */
inline bool IsSpaceChar ( TCHAR c )
{
#ifdef NUX_UNICODE
return ( std::iswspace (c) != 0 );
#else
return ( std::isspace (c) != 0 );
#endif
}
}
#endif // NTCHAR_H
nux-4.0.8+16.04.20160209/NuxCore/Character/NUTF.h 0000644 0000156 0000165 00000007332 12656236757 021135 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUTF_H
#define NUTF_H
// http://en.wikipedia.org/wiki/UTF-16
// In computing, UTF-16 (16-bit Unicode Transformation Format) is a variable-length character encoding
// for Unicode, capable of encoding the entire Unicode repertoire. The encoding form maps code points
// (characters) into a sequence of 16-bit words, called code units. For characters in the Basic
// Multilingual Plane (BMP) the resulting encoding is a single 16-bit word. For characters in the other
// planes, the encoding will result in a pair of 16-bit words, together called a surrogate pair. All possible
// code points from U+0000 through U+10FFFF, except for the surrogate code points U+D800U+DFFF
// (which are not characters), are uniquely mapped by UTF-16 regardless of the code point's current or
// future character assignment or use.
//
// As many uses in computing require units of bytes (octets) there are three related encoding schemes
// which map to octet sequences instead of words: namely UTF-16, UTF-16BE, and UTF-16LE. They
// differ only in the byte order chosen to represent each 16-bit unit and whether they make use of a
// Byte Order Mark. All of the schemes will result in either a 2 or 4-byte sequence for any given character.
//
// UTF-16 is officially defined in Annex Q of the international standard ISO/IEC 10646-1. It is also
// described in The Unicode Standard version 3.0 and higher, as well as in the IETF's RFC 2781.
//
// UCS-2 (2-byte Universal Character Set) is an obsolete character encoding which is a predecessor
// to UTF-16. The UCS-2 encoding form is nearly identical to that of UTF-16, except that it does not
// support surrogate pairs and therefore can only encode characters in the BMP range U+0000 through
// U+FFFF. As a consequence it is a fixed-length encoding that always encodes characters into a
// single 16-bit value. As with UTF-16, there are three related encoding schemes (UCS-2, UCS-2BE, UCS-2LE)
// that map characters to a specific byte sequence.
//
// Because of the technical similarities and upwards compatibility from UCS-2 to UTF-16, the two
// encodings are often erroneously conflated and used as if interchangeable, so that strings encoded
// in UTF-16 are sometimes misidentified as being encoded in UCS-2.
namespace nux
{
//! Convert UTF-16 to UTF-8
class NUTF8
{
// UTF-8 encoded characters may theoretically be up to six bytes long, however 16-bit BMP characters are only up to three bytes long.
public:
explicit NUTF8 (const UNICHAR *Source);
explicit NUTF8 (const std::wstring &Source);
~NUTF8();
operator const char* ();
private:
void Convert (const UNICHAR *);
//void Convert(const t_UTF32*);
char *utf8;
};
//! Convert UTF-8 to UTF-16
class NUTF16
{
public:
explicit NUTF16 (const char *Source);
explicit NUTF16 (const std::string &Source);
~NUTF16();
operator const UNICHAR* ();
private:
void Convert (const char *);
UNICHAR *unicode;
};
}
#endif // NUTF_H
nux-4.0.8+16.04.20160209/NuxCore/Character/NAscii.h 0000644 0000156 0000165 00000001646 12656236757 021531 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NTASCII_H
#define NTASCII_H
namespace nux
{
extern t_uchar GAscii[];
extern t_uchar GAsciiCP437[];
}
#endif // NTASCII_H
nux-4.0.8+16.04.20160209/NuxCore/Character/NUni.h 0000644 0000156 0000165 00000016020 12656236757 021224 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUNI_H
#define NUNI_H
/*
* Copyright 2001-2004 Unicode, Inc.
*
* Disclaimer
*
* This source code is provided as is by Unicode, Inc. No claims are
* made as to fitness for any particular purpose. No warranties of any
* kind are expressed or implied. The recipient agrees to determine
* applicability of information provided. If this file has been
* purchased on magnetic or optical media from Unicode, Inc., the
* sole remedy for any claim will be exchange of defective media
* within 90 days of receipt.
*
* Limitations on Rights to Redistribute This Code
*
* Unicode, Inc. hereby grants the right to freely use the information
* supplied in this file in the creation of products supporting the
* Unicode Standard, and to make copies of this file in any form
* for internal or external distribution as long as this notice
* remains attached.
*/
/* ---------------------------------------------------------------------
Conversions between UTF32, UTF-16, and UTF-8. Header file.
Several funtions are included here, forming a complete set of
conversions between the three formats. UTF-7 is not included
here, but is handled in a separate source file.
Each of these routines takes pointers to input buffers and output
buffers. The input buffers are const.
Each routine converts the text between *sourceStart and sourceEnd,
putting the result into the buffer between *targetStart and
targetEnd. Note: the end pointers are *after* the last item: e.g.
*(sourceEnd - 1) is the last item.
The return result indicates whether the conversion was successful,
and if not, whether the problem was in the source or target buffers.
(Only the first encountered problem is indicated.)
After the conversion, *sourceStart and *targetStart are both
updated to point to the end of last text successfully converted in
the respective buffers.
Input parameters:
sourceStart - pointer to a pointer to the source buffer.
The contents of this are modified on return so that
it points at the next thing to be converted.
targetStart - similarly, pointer to pointer to the target buffer.
sourceEnd, targetEnd - respectively pointers to the ends of the
two buffers, for overflow checking only.
These conversion functions take a ConversionFlags argument. When this
flag is set to strict, both irregular sequences and isolated surrogates
will cause an error. When the flag is set to lenient, both irregular
sequences and isolated surrogates are converted.
Whether the flag is strict or lenient, all illegal sequences will cause
an error return. This includes sequences such as: , ,
or in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
must check for illegal sequences.
When the flag is set to lenient, characters over 0x10FFFF are converted
to the replacement character; otherwise (when the flag is set to strict)
they constitute an error.
Output parameters:
The value "sourceIllegal" is returned from some routines if the input
sequence is malformed. When "sourceIllegal" is returned, the source
value will point to the illegal value that caused the problem. E.g.,
in UTF-8 when a sequence is malformed, it points to the start of the
malformed sequence.
Author: Mark E. Davis, 1994.
Rev History: Rick McGowan, fixes & updates May 2001.
Fixes & updates, Sept 2001.
------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------
The following 4 definitions are compiler-specific.
The C standard does not guarantee that wchar_t has at least
16 bits, so wchar_t is no less portable than unsigned short!
All should be unsigned values to avoid sign extension during
bit mask & shift operations.
------------------------------------------------------------------------ */
//typedef unsigned long unsigned int; /* at least 32 bits */
//typedef unsigned short wchar_t; /* at least 16 bits */
//typedef unsigned char unsigned char; /* typically 8 bits */
//typedef unsigned char Boolean; /* 0 or 1 */
namespace nux
{
/* Some fundamental constants */
#define UNI_REPLACEMENT_CHAR (unsigned int)0x0000FFFD
#define UNI_MAX_BMP (unsigned int)0x0000FFFF
#define UNI_MAX_UTF16 (unsigned int)0x0010FFFF
#define UNI_MAX_UTF32 (unsigned int)0x7FFFFFFF
#define UNI_MAX_LEGAL_UTF32 (unsigned int)0x0010FFFF
typedef enum
{
conversionOK = 0, /* conversion successful */
sourceExhausted, /* partial character in source, but hit end */
targetExhausted, /* insuff. room in target for conversion */
sourceIllegal /* source sequence is illegal/malformed */
} ConversionResult;
typedef enum
{
strictConversion = 0,
lenientConversion
} ConversionFlags;
ConversionResult ConvertUTF8toUTF16 (
const unsigned char **sourceStart, const unsigned char *sourceEnd,
wchar_t **targetStart, wchar_t *targetEnd, ConversionFlags flags);
ConversionResult ConvertUTF16toUTF8 (
const wchar_t **sourceStart, const wchar_t *sourceEnd,
unsigned char **targetStart, unsigned char *targetEnd, ConversionFlags flags);
ConversionResult ConvertUTF8toUTF32 (
const unsigned char **sourceStart, const unsigned char *sourceEnd,
unsigned int **targetStart, unsigned int *targetEnd, ConversionFlags flags);
ConversionResult ConvertUTF32toUTF8 (
const unsigned int **sourceStart, const unsigned int *sourceEnd,
unsigned char **targetStart, unsigned char *targetEnd, ConversionFlags flags);
ConversionResult ConvertUTF16toUTF32 (
const wchar_t **sourceStart, const wchar_t *sourceEnd,
unsigned int **targetStart, unsigned int *targetEnd, ConversionFlags flags);
ConversionResult ConvertUTF32toUTF16 (
const unsigned int **sourceStart, const unsigned int *sourceEnd,
wchar_t **targetStart, wchar_t *targetEnd, ConversionFlags flags);
bool isLegalUTF8Sequence (const unsigned char *source, const unsigned char *sourceEnd);
/* intended to work the same as g_utf8_validate */
bool tr_utf8_validate ( const char *str, int max_len, const char **end );
}
#endif /* NUNI_H */
nux-4.0.8+16.04.20160209/NuxCore/Character/NUni.cpp 0000644 0000156 0000165 00000061160 12656236757 021564 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
/*
* Copyright 2001-2004 Unicode, Inc.
*
* Disclaimer
*
* This source code is provided as is by Unicode, Inc. No claims are
* made as to fitness for any particular purpose. No warranties of any
* kind are expressed or implied. The recipient agrees to determine
* applicability of information provided. If this file has been
* purchased on magnetic or optical media from Unicode, Inc., the
* sole remedy for any claim will be exchange of defective media
* within 90 days of receipt.
*
* Limitations on Rights to Redistribute This Code
*
* Unicode, Inc. hereby grants the right to freely use the information
* supplied in this file in the creation of products supporting the
* Unicode Standard, and to make copies of this file in any form
* for internal or external distribution as long as this notice
* remains attached.
*/
/* ---------------------------------------------------------------------
Conversions between UTF32, UTF-16, and UTF-8. Source code file.
Author: Mark E. Davis, 1994.
Rev History: Rick McGowan, fixes & updates May 2001.
Sept 2001: fixed const & error conditions per
mods suggested by S. Parent & A. Lillich.
June 2002: Tim Dodd added detection and handling of incomplete
source sequences, enhanced error detection, added casts
to eliminate compiler warnings.
July 2003: slight mods to back out aggressive FFFE detection.
Jan 2004: updated switches in from-UTF8 conversions.
Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.
May 2006: updated isLegalUTF8Sequence.
See the header file "ConvertUTF.h" for complete documentation.
------------------------------------------------------------------------ */
#include "NuxCore.h"
//#include "NUni.h"
namespace nux
{
static const int halfShift = 10; /* used for shifting by 10 bits */
static const unsigned int halfBase = 0x0010000UL;
static const unsigned int halfMask = 0x3FFUL;
#define UNI_SUR_HIGH_START (unsigned int)0xD800
#define UNI_SUR_HIGH_END (unsigned int)0xDBFF
#define UNI_SUR_LOW_START (unsigned int)0xDC00
#define UNI_SUR_LOW_END (unsigned int)0xDFFF
ConversionResult ConvertUTF32toUTF16 (const unsigned int **sourceStart, const unsigned int *sourceEnd, wchar_t **targetStart, wchar_t *targetEnd, ConversionFlags flags)
{
ConversionResult result = conversionOK;
const unsigned int *source = *sourceStart;
wchar_t *target = *targetStart;
while (source < sourceEnd)
{
unsigned int ch;
if (target >= targetEnd)
{
result = targetExhausted;
break;
}
ch = *source++;
if (ch <= UNI_MAX_BMP) /* Target is a character <= 0xFFFF */
{
/* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END)
{
if (flags == strictConversion)
{
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
else
{
*target++ = UNI_REPLACEMENT_CHAR;
}
}
else
{
*target++ = (wchar_t) ch; /* normal case */
}
}
else if (ch > UNI_MAX_LEGAL_UTF32)
{
if (flags == strictConversion)
{
result = sourceIllegal;
}
else
{
*target++ = UNI_REPLACEMENT_CHAR;
}
}
else
{
/* target is a character in range 0xFFFF - 0x10FFFF. */
if (target + 1 >= targetEnd)
{
--source; /* Back up source pointer! */
result = targetExhausted;
break;
}
ch -= halfBase;
*target++ = (wchar_t) ( (ch >> halfShift) + UNI_SUR_HIGH_START);
*target++ = (wchar_t) ( (ch & halfMask) + UNI_SUR_LOW_START);
}
}
*sourceStart = source;
*targetStart = target;
return result;
}
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF16toUTF32 (const wchar_t **sourceStart, const wchar_t *sourceEnd, unsigned int **targetStart, unsigned int *targetEnd, ConversionFlags flags)
{
ConversionResult result = conversionOK;
const wchar_t *source = *sourceStart;
unsigned int *target = *targetStart;
unsigned int ch, ch2;
while (source < sourceEnd)
{
const wchar_t *oldSource = source; /* In case we have to back up because of target overflow. */
ch = *source++;
/* If we have a surrogate pair, convert to UTF32 first. */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
/* If the 16 bits following the high surrogate are in the source buffer... */
if (source < sourceEnd)
{
ch2 = *source;
/* If it's a low surrogate, convert to UTF32. */
if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
ch = ( (ch - UNI_SUR_HIGH_START) << halfShift)
+ (ch2 - UNI_SUR_LOW_START) + halfBase;
++source;
}
else if (flags == strictConversion) /* it's an unpaired high surrogate */
{
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
else /* We don't have the 16 bits following the high surrogate. */
{
--source; /* return to the high surrogate */
result = sourceExhausted;
break;
}
}
else if (flags == strictConversion)
{
/* UTF-16 surrogate values are illegal in UTF-32 */
if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
{
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
if (target >= targetEnd)
{
source = oldSource; /* Back up source pointer! */
result = targetExhausted;
break;
}
*target++ = ch;
}
*sourceStart = source;
*targetStart = target;
#ifdef CVTUTF_DEBUG
if (result == sourceIllegal)
{
fprintf (stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
fflush (stderr);
}
#endif
return result;
}
/* --------------------------------------------------------------------- */
/*
* Index into the table below with the first byte of a UTF-8 sequence to
* get the number of trailing bytes that are supposed to follow it.
* Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
* left as-is for anyone who may want to do such conversion, which was
* allowed in earlier algorithms.
*/
static const char trailingBytesForUTF8[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
};
/*
* Magic values subtracted from a buffer value during UTF8 conversion.
* This table contains as many values as there might be trailing bytes
* in a UTF-8 sequence.
*/
static const unsigned int offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
0x03C82080UL, 0xFA082080UL, 0x82082080UL
};
/*
* Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
* into the first byte, depending on how many bytes follow. There are
* as many entries in this table as there are UTF-8 sequence types.
* (I.e., one byte sequence, two byte... etc.). Remember that sequencs
* for *legal* UTF-8 will be 4 or fewer bytes total.
*/
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
/* --------------------------------------------------------------------- */
/* The interface converts a whole buffer to avoid function-call overhead.
* Constants have been gathered. Loops & conditionals have been removed as
* much as possible for efficiency, in favor of drop-through switches.
* (See "Note A" at the bottom of the file for equivalent code.)
* If your compiler supports it, the "isLegalUTF8" call can be turned
* into an inline function.
*/
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF16toUTF8 (const wchar_t **sourceStart, const wchar_t *sourceEnd, unsigned char **targetStart, unsigned char *targetEnd, ConversionFlags flags)
{
ConversionResult result = conversionOK;
const wchar_t *source = *sourceStart;
unsigned char *target = *targetStart;
while (source < sourceEnd)
{
unsigned int ch;
unsigned short bytesToWrite = 0;
const unsigned int byteMask = 0xBF;
const unsigned int byteMark = 0x80;
const wchar_t *oldSource = source; /* In case we have to back up because of target overflow. */
ch = *source++;
/* If we have a surrogate pair, convert to UTF32 first. */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END)
{
/* If the 16 bits following the high surrogate are in the source buffer... */
if (source < sourceEnd)
{
unsigned int ch2 = *source;
/* If it's a low surrogate, convert to UTF32. */
if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END)
{
ch = ( (ch - UNI_SUR_HIGH_START) << halfShift)
+ (ch2 - UNI_SUR_LOW_START) + halfBase;
++source;
}
else if (flags == strictConversion) /* it's an unpaired high surrogate */
{
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
else /* We don't have the 16 bits following the high surrogate. */
{
--source; /* return to the high surrogate */
result = sourceExhausted;
break;
}
}
else if (flags == strictConversion)
{
/* UTF-16 surrogate values are illegal in UTF-32 */
if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END)
{
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
/* Figure out how many bytes the result will require */
if (ch < (unsigned int) 0x80)
{
bytesToWrite = 1;
}
else if (ch < (unsigned int) 0x800)
{
bytesToWrite = 2;
}
else if (ch < (unsigned int) 0x10000)
{
bytesToWrite = 3;
}
else if (ch < (unsigned int) 0x110000)
{
bytesToWrite = 4;
}
else
{
bytesToWrite = 3;
ch = UNI_REPLACEMENT_CHAR;
}
target += bytesToWrite;
if (target > targetEnd)
{
source = oldSource; /* Back up source pointer! */
target -= bytesToWrite;
result = targetExhausted;
break;
}
switch (bytesToWrite) /* note: everything falls through. */
{
case 4:
*--target = (unsigned char) ( (ch | byteMark) & byteMask);
ch >>= 6;
case 3:
*--target = (unsigned char) ( (ch | byteMark) & byteMask);
ch >>= 6;
case 2:
*--target = (unsigned char) ( (ch | byteMark) & byteMask);
ch >>= 6;
case 1:
*--target = (unsigned char) (ch | firstByteMark[bytesToWrite]);
}
target += bytesToWrite;
}
*sourceStart = source;
*targetStart = target;
return result;
}
/* --------------------------------------------------------------------- */
/*
* Utility routine to tell whether a sequence of bytes is legal UTF-8.
* This must be called with the length pre-determined by the first byte.
* If not calling this from ConvertUTF8to*, then the length can be set by:
* length = trailingBytesForUTF8[*source]+1;
* and the sequence is illegal right away if there aren't that many bytes
* available.
* If presented with a length > 4, this returns false. The Unicode
* definition of UTF-8 goes up to 4-byte sequences.
*/
static bool isLegalUTF8 (const unsigned char *source, int length)
{
unsigned char a;
const unsigned char *srcptr = source + length;
switch (length)
{
default:
return false;
/* Everything else falls through when "true"... */
case 4:
if ( (a = (*--srcptr) ) < 0x80 || a > 0xBF) return false;
case 3:
if ( (a = (*--srcptr) ) < 0x80 || a > 0xBF) return false;
case 2:
if ( (a = (*--srcptr) ) > 0xBF) return false;
switch (*source)
{
/* no fall-through in this inner switch */
case 0xE0:
if (a < 0xA0) return false;
break;
case 0xED:
if ( (a < 0x80) || (a > 0x9F) ) return false;
break;
case 0xF0:
if (a < 0x90) return false;
break;
case 0xF4:
if (a > 0x8F) return false;
break;
default:
if (a < 0x80) return false;
}
case 1:
if (*source >= 0x80 && *source < 0xC2) return false;
}
if (*source > 0xF4) return false;
return true;
}
/* --------------------------------------------------------------------- */
/*
* Exported function to return whether a UTF-8 sequence is legal or not.
* This is not used here; it's just exported.
*/
bool isLegalUTF8Sequence (const unsigned char *source, const unsigned char *sourceEnd)
{
int length;
if (source == sourceEnd)
{
return true;
}
while (true)
{
length = trailingBytesForUTF8[*source] + 1;
if (source + length > sourceEnd)
{
return false;
}
if (!isLegalUTF8 (source, length) )
{
return false;
}
source += length;
if (source >= sourceEnd)
{
return true;
}
}
return true;
}
/**
* This is a variation of isLegalUTF8Sequence() that behaves like g_utf8_validate().
* In addition to knowing if the sequence is legal, it also tells you the last good character.
*/
bool
tr_utf8_validate ( const char *str, int max_len, const char **end )
{
const unsigned char *source = (const unsigned char *) str;
const unsigned char *sourceEnd;
if ( max_len == 0 )
return true;
if ( str == NULL )
return false;
sourceEnd = source + ( (max_len < 0) ? strlen (str) : (size_t) max_len);
if ( source == sourceEnd )
{
if ( end != NULL )
*end = (const char *) source;
return true;
}
for ( ;; )
{
const int length = trailingBytesForUTF8[*source] + 1;
if (source + length > sourceEnd)
{
if ( end != NULL )
*end = (const char *) source;
return false;
}
if (!isLegalUTF8 (source, length) )
{
if ( end != NULL )
*end = (const char *) source;
return false;
}
source += length;
if (source >= sourceEnd)
{
if ( end != NULL )
*end = (const char *) source;
return true;
}
}
return true;
}
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF8toUTF16 (const unsigned char **sourceStart, const unsigned char *sourceEnd, wchar_t **targetStart, wchar_t *targetEnd, ConversionFlags flags)
{
ConversionResult result = conversionOK;
const unsigned char *source = *sourceStart;
wchar_t *target = *targetStart;
while (source < sourceEnd)
{
unsigned int ch = 0;
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
if (source + extraBytesToRead >= sourceEnd)
{
result = sourceExhausted;
break;
}
/* Do this check whether lenient or strict */
if (! isLegalUTF8 (source, extraBytesToRead + 1) )
{
result = sourceIllegal;
break;
}
/*
* The cases all fall through. See "Note A" below.
*/
switch (extraBytesToRead)
{
case 5:
ch += *source++;
ch <<= 6; /* remember, illegal UTF-8 */
case 4:
ch += *source++;
ch <<= 6; /* remember, illegal UTF-8 */
case 3:
ch += *source++;
ch <<= 6;
case 2:
ch += *source++;
ch <<= 6;
case 1:
ch += *source++;
ch <<= 6;
case 0:
ch += *source++;
}
ch -= offsetsFromUTF8[extraBytesToRead];
if (target >= targetEnd)
{
source -= (extraBytesToRead + 1); /* Back up source pointer! */
result = targetExhausted;
break;
}
if (ch <= UNI_MAX_BMP) /* Target is a character <= 0xFFFF */
{
/* UTF-16 surrogate values are illegal in UTF-32 */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END)
{
if (flags == strictConversion)
{
source -= (extraBytesToRead + 1); /* return to the illegal value itself */
result = sourceIllegal;
break;
}
else
{
*target++ = UNI_REPLACEMENT_CHAR;
}
}
else
{
*target++ = (wchar_t) ch; /* normal case */
}
}
else if (ch > UNI_MAX_UTF16)
{
if (flags == strictConversion)
{
result = sourceIllegal;
source -= (extraBytesToRead + 1); /* return to the start */
break; /* Bail out; shouldn't continue */
}
else
{
*target++ = UNI_REPLACEMENT_CHAR;
}
}
else
{
/* target is a character in range 0xFFFF - 0x10FFFF. */
if (target + 1 >= targetEnd)
{
source -= (extraBytesToRead + 1); /* Back up source pointer! */
result = targetExhausted;
break;
}
ch -= halfBase;
*target++ = (wchar_t) ( (ch >> halfShift) + UNI_SUR_HIGH_START);
*target++ = (wchar_t) ( (ch & halfMask) + UNI_SUR_LOW_START);
}
}
*sourceStart = source;
*targetStart = target;
return result;
}
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF32toUTF8 (
const unsigned int **sourceStart, const unsigned int *sourceEnd,
unsigned char **targetStart, unsigned char *targetEnd, ConversionFlags flags)
{
ConversionResult result = conversionOK;
const unsigned int *source = *sourceStart;
unsigned char *target = *targetStart;
while (source < sourceEnd)
{
unsigned int ch;
unsigned short bytesToWrite = 0;
const unsigned int byteMask = 0xBF;
const unsigned int byteMark = 0x80;
ch = *source++;
if (flags == strictConversion )
{
/* UTF-16 surrogate values are illegal in UTF-32 */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END)
{
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
/*
* Figure out how many bytes the result will require. Turn any
* illegally large UTF32 things (> Plane 17) into replacement chars.
*/
if (ch < (unsigned int) 0x80)
{
bytesToWrite = 1;
}
else if (ch < (unsigned int) 0x800)
{
bytesToWrite = 2;
}
else if (ch < (unsigned int) 0x10000)
{
bytesToWrite = 3;
}
else if (ch <= UNI_MAX_LEGAL_UTF32)
{
bytesToWrite = 4;
}
else
{
bytesToWrite = 3;
ch = UNI_REPLACEMENT_CHAR;
result = sourceIllegal;
}
target += bytesToWrite;
if (target > targetEnd)
{
--source; /* Back up source pointer! */
target -= bytesToWrite;
result = targetExhausted;
break;
}
switch (bytesToWrite) /* note: everything falls through. */
{
case 4:
*--target = (unsigned char) ( (ch | byteMark) & byteMask);
ch >>= 6;
case 3:
*--target = (unsigned char) ( (ch | byteMark) & byteMask);
ch >>= 6;
case 2:
*--target = (unsigned char) ( (ch | byteMark) & byteMask);
ch >>= 6;
case 1:
*--target = (unsigned char) (ch | firstByteMark[bytesToWrite]);
}
target += bytesToWrite;
}
*sourceStart = source;
*targetStart = target;
return result;
}
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF8toUTF32 (
const unsigned char **sourceStart, const unsigned char *sourceEnd,
unsigned int **targetStart, unsigned int *targetEnd, ConversionFlags flags)
{
ConversionResult result = conversionOK;
const unsigned char *source = *sourceStart;
unsigned int *target = *targetStart;
while (source < sourceEnd)
{
unsigned int ch = 0;
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
if (source + extraBytesToRead >= sourceEnd)
{
result = sourceExhausted;
break;
}
/* Do this check whether lenient or strict */
if (! isLegalUTF8 (source, extraBytesToRead + 1) )
{
result = sourceIllegal;
break;
}
/*
* The cases all fall through. See "Note A" below.
*/
switch (extraBytesToRead)
{
case 5:
ch += *source++;
ch <<= 6;
case 4:
ch += *source++;
ch <<= 6;
case 3:
ch += *source++;
ch <<= 6;
case 2:
ch += *source++;
ch <<= 6;
case 1:
ch += *source++;
ch <<= 6;
case 0:
ch += *source++;
}
ch -= offsetsFromUTF8[extraBytesToRead];
if (target >= targetEnd)
{
source -= (extraBytesToRead + 1); /* Back up the source pointer! */
result = targetExhausted;
break;
}
if (ch <= UNI_MAX_LEGAL_UTF32)
{
/*
* UTF-16 surrogate values are illegal in UTF-32, and anything
* over Plane 17 (> 0x10FFFF) is illegal.
*/
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END)
{
if (flags == strictConversion)
{
source -= (extraBytesToRead + 1); /* return to the illegal value itself */
result = sourceIllegal;
break;
}
else
{
*target++ = UNI_REPLACEMENT_CHAR;
}
}
else
{
*target++ = ch;
}
}
else /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
{
result = sourceIllegal;
*target++ = UNI_REPLACEMENT_CHAR;
}
}
*sourceStart = source;
*targetStart = target;
return result;
}
/* ---------------------------------------------------------------------
Note A.
The fall-through switches in UTF-8 reading code save a
temp variable, some decrements & conditionals. The switches
are equivalent to the following loop:
{
int tmpBytesToRead = extraBytesToRead+1;
do {
ch += *source++;
--tmpBytesToRead;
if (tmpBytesToRead) ch <<= 6;
} while (tmpBytesToRead > 0);
}
In UTF-8 writing code, the switches on "bytesToWrite" are
similarly unrolled loops.
--------------------------------------------------------------------- */
}
nux-4.0.8+16.04.20160209/NuxCore/Character/NUnicode.cpp 0000644 0000156 0000165 00000004664 12656236757 022425 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "NUnicode.h"
namespace nux
{
ANSICHAR *UnicharToAnsicharConvertion::Convert (const UNICHAR *Source)
{
std::wstring utf16string (Source);
size_t utf16size = utf16string.length();
size_t utf8size = 6 * utf16size;
ANSICHAR *utf8string = new ANSICHAR[utf8size+1];
const wchar_t *source_start = utf16string.c_str();
const wchar_t *source_end = source_start + utf16size;
unsigned char *target_start = reinterpret_cast (utf8string);
unsigned char *target_end = target_start + utf8size;
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
delete [] utf8string;
utf8string = 0;
}
// mark end of string
*target_start = 0;
return utf8string;
}
UNICHAR *AnsicharToUnicharConvertion::Convert (const ANSICHAR *Source)
{
std::string utf8string (Source);
size_t utf8size = utf8string.length();
size_t utf16size = utf8size;
UNICHAR *utf16string = new UNICHAR[utf16size+1];
const unsigned char *source_start = reinterpret_cast (utf8string.c_str() );
const unsigned char *source_end = source_start + utf8size;
wchar_t *target_start = reinterpret_cast (utf16string);
wchar_t *target_end = target_start + utf16size;
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
delete[] utf16string;
utf16string = 0;
}
// mark end of string
*target_start = 0;
return utf16string;
}
}
nux-4.0.8+16.04.20160209/NuxCore/Character/NUnicode.h 0000644 0000156 0000165 00000024746 12656236757 022075 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUNICODE_H
#define NUNICODE_H
namespace nux
{
// UTF-16 is the primary encoding mechanism used by Microsoft Windows 2000, Windows 2000 Server, Windows XP and Windows 2003 Server.
// Unicode Byte Order Mark (BOM)
enum {UNICODE_UTF32_BE = 0x0000FEFF };
enum {UNICODE_UTF32_LE = 0xFFFE0000 };
enum {UNICODE_UTF16_BE = 0xFEFF };
enum {UNICODE_UTF16_LE = 0xFFFE };
enum {UNICODE_UTF8 = 0xEFBBBF };
const BYTE UTF32_BE[] = {0x04 /*size*/, 0x00, 0x00, 0xFE, 0xFF };
const BYTE UTF32_LE[] = {0x04 /*size*/, 0xFF, 0xFE, 0x00, 0x00 };
const BYTE UTF16_BE[] = {0x02 /*size*/, 0xFE, 0xFF };
const BYTE UTF16_LE[] = {0x02 /*size*/, 0xFF, 0xFE };
const BYTE UTF8[] = {0x03 /*size*/, 0xEF, 0xBB, 0xBF };
enum {UNICODE_BOM = 0xfeff};
// UTF-16 is the default encoding form of the Unicode Standard
// On Linux and Mac OS X, wchar_t is 4 bytes!
// On windows wchar_t is 2 bytes!
#ifdef UNICODE
inline TCHAR ConvertAnsiCharToTCHAR (ANSICHAR In)
{
TCHAR output;
const unsigned char *source_start = &In;
const unsigned char *source_end = source_start + 1;
wchar_t *target_start = reinterpret_cast (&output);
wchar_t *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline ANSICHAR ConvertTCHARToAnsiChar (TCHAR In)
{
ANSICHAR output;
const wchar_t *source_start = &In;
const wchar_t *source_end = source_start + 1;
unsigned char *target_start = reinterpret_cast (&output);
unsigned char *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline TCHAR ConvertUnicodeCharToTCHAR (UNICHAR In)
{
return In;
}
inline UNICHAR ConvertTCHARToUnicodeChar (TCHAR In)
{
return In;
}
#else
inline TCHAR ConvertUnicodeCharToTCHAR (UNICHAR In)
{
TCHAR output;
const wchar_t *source_start = &In;
const wchar_t *source_end = source_start + 1;
unsigned char *target_start = reinterpret_cast (&output);
unsigned char *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline UNICHAR ConvertTCHARToUnicodeChar (TCHAR In)
{
UNICHAR output;
const unsigned char *source_start = reinterpret_cast (&In);
const unsigned char *source_end = source_start + 1;
wchar_t *target_start = reinterpret_cast (&output);
wchar_t *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
inline TCHAR ConvertAnsiCharToTCHAR (ANSICHAR In)
{
return In;
}
inline ANSICHAR ConvertTCHARToAnsiChar (TCHAR In)
{
return In;
}
#endif
/*!
Convert a single UNICHAR to ANSICHAR.
*/
inline ANSICHAR ConvertUnicodeCharToAnsiChar (UNICHAR In)
{
TCHAR output;
const wchar_t *source_start = &In;
const wchar_t *source_end = source_start + 1;
unsigned char *target_start = reinterpret_cast (&output);
unsigned char *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF16toUTF8 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
/*!
Convert a single ANSICHAR to UNICHAR.
*/
inline UNICHAR ConvertAnsiCharToUnicodeChar (ANSICHAR In)
{
UNICHAR output;
const unsigned char *source_start = reinterpret_cast (&In);
const unsigned char *source_end = source_start + 1;
wchar_t *target_start = reinterpret_cast (&output);
wchar_t *target_end = target_start + sizeof (wchar_t);
ConversionResult res = ConvertUTF8toUTF16 (&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
output = 0;
}
return output;
}
class UnicharToAnsicharConvertion
{
public:
// Default to ANSI code page
UnicharToAnsicharConvertion() {}
/*!
Convert from UNICHAR to ANSICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
ANSICHAR *Convert (const UNICHAR *Source);
/*{
std::wstring utf16string(Source);
size_t utf16size = utf16string.length();
size_t utf8size = 6 * utf16size;
ANSICHAR *utf8string = new ANSICHAR[utf8size+1];
const wchar_t *source_start = utf16string.c_str();
const wchar_t *source_end = source_start + utf16size;
unsigned char* target_start = reinterpret_cast(utf8string);
unsigned char* target_end = target_start + utf8size;
ConversionResult res = ConvertUTF16toUTF8(&source_start, source_end, &target_start, target_end, lenientConversion);
if (res != conversionOK)
{
delete utf8string;
utf8string = 0;
}
// mark end of string
*target_start = 0;
return utf8string;
}*/
};
//! ANSICHAR to UNICHAR conversion
class AnsicharToUnicharConvertion
{
public:
AnsicharToUnicharConvertion() {}
/*!
Convert from ANSICHAR to UNICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
UNICHAR *Convert (const ANSICHAR *Source);
};
//! TCHAR to ANSI conversion
// TCHAR can be ansi or unicode depending if UNICODE is defined or not.
class TCharToAnsiConvertion
{
public:
NUX_INLINE TCharToAnsiConvertion() {}
/*!
Convert from TCHAR to ANSICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
NUX_INLINE ANSICHAR *Convert (const TCHAR *Source)
{
// Determine whether we need to allocate memory or not
#ifdef UNICODE
UnicharToAnsicharConvertion convert;
return convert.Convert (Source);
#else
size_t length = strlen (Source) + 1;
size_t size = length * sizeof (ANSICHAR);
ANSICHAR *Dest = new ANSICHAR[size];
STRNCPY_S (Dest, size, Source, length);
return Dest;
#endif
}
};
//! TCHAR to Unichar conversion
// TCHAR can be ansi or unicode depending if UNICODE is defined or not.
class TCharToUnicharConvertion
{
public:
NUX_INLINE TCharToUnicharConvertion() {}
/*!
Convert from TCHAR to ANSICHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
NUX_INLINE UNICHAR *Convert (const TCHAR *Source)
{
// Determine whether we need to allocate memory or not
#ifdef UNICODE
size_t length = strlen (Source) + 1;
size_t size = length * sizeof (UNICHAR);
UNICHAR *Dest = new UNICHAR[size];
STRNCPY_S (Dest, size, Source, length);
return Dest;
#else
AnsicharToUnicharConvertion convert;
return convert.Convert (Source);
#endif
}
};
//! ANSI to TCHAR conversion
// TCHAR can be ansi or unicode depending if UNICODE is defined or not.
class AnsiToTCharConversion
{
public:
NUX_INLINE AnsiToTCharConversion() {}
/*!
Convert from ANSICHAR to TCHAR
@param Source String to convert. Null terminated.
@return Return a pointer to the new string. Null terminated.
*/
NUX_INLINE TCHAR *Convert (const ANSICHAR *Source)
{
#ifdef UNICODE
AnsicharToUnicharConvertion convert;
return convert.Convert (Source);
#else
size_t length = strlen (Source) + 1;
size_t size = length;
TCHAR *Dest = new TCHAR[size];
STRNCPY_S (Dest, size, Source, length);
return Dest;
#endif
}
};
/*!
Convert from one string format to another.
*/
template < typename CONVERT_TO, typename CONVERT_FROM, typename BASE_CONVERTER, DWORD DefaultConversionSize = 128 >
class NCharacterConversion: public BASE_CONVERTER
{
CONVERT_TO *ConvertedString;
// Hide the default constructor
NCharacterConversion();
public:
/*!
Converts the data by using the Convert() method on the base class
*/
explicit inline NCharacterConversion (const CONVERT_FROM *Source)
{
if (Source != NULL)
{
// Use base class' convert method
ConvertedString = BASE_CONVERTER::Convert (Source);
}
else
{
ConvertedString = NULL;
}
}
/*!
If memory was allocated, then it is freed below
*/
inline ~NCharacterConversion()
{
if (ConvertedString != NULL)
{
delete [] ConvertedString;
}
}
// Operator to get access to the converted string
inline operator CONVERT_TO* (void) const
{
return ConvertedString;
}
};
// Conversion typedefs
// typedef NCharacterConversion ANSI_To_TCHAR_Conversion;
// typedef NCharacterConversion TCHAR_To_ANSI_Conversion;
// typedef NCharacterConversion UNICHAR_To_ANSICHAR_Conversion;
// typedef NCharacterConversion ANSICHAR_To_UNICHAR_Conversion;
}
#endif // NUNICODE_H
nux-4.0.8+16.04.20160209/NuxCore/Character/NUTF.cpp 0000644 0000156 0000165 00000023603 12656236757 021467 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "NUTF.h"
namespace nux
{
NUTF8::NUTF8 (const UNICHAR *Source)
{
Convert (Source);
}
NUTF8::NUTF8 (const std::wstring &Source)
{
Convert (NUX_REINTERPRET_CAST (UNICHAR *, NUX_CONST_CAST (wchar_t *, Source.c_str() ) ) );
}
void NUTF8::Convert (const UNICHAR *Source)
{
int NumBytes = 0;
// *6 each UTF16 char can translate to up to 6 bytes in UTF8
// +1 for NULL char
size_t Size = wcslen ( (wchar_t *) Source) * 6 + 1;
utf8 = new char[Size];
memset (utf8, 0, Size);
unsigned char TwoBytes[2];
TwoBytes[0] = '\0';
TwoBytes[1] = '\0';
utf8[0] = '\0';
// U-00000000 U-0000007F: 0xxxxxxx
// U-00000080 U-000007FF: 110xxxxx 10xxxxxx
// U-00000800 U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
// U-00010000 U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// U-00200000 U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// U-04000000 U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// The original specification of UTF-8 allowed for sequences of up to six bytes covering numbers up to 31 bits
// (the original limit of the universal character set). However, UTF-8 was restricted by RFC 3629 to use only
// the area covered by the formal Unicode definition, U+0000 to U+10FFFF, in November 2003. So UTF-8 code point is at most 4 bytes.
for (size_t n = 0; Source[n] != 0; n++)
{
if (Source[n] <= 0x7F)
{
TwoBytes[0] = (char) Source[n];
STRCAT_S (utf8, Size, (const char *) &TwoBytes[0]);
}
else
{
// 11 valid bits 2 bytes
if (Source[n] <= 0x7FF)
{
// Extract the 5 highest bits
TwoBytes[0] = (char) (0xC0 + (Source[n] >> 6) );
NumBytes = 2;
}
// 16 valid bits 3 bytes
else if (Source[n] <= 0xFFFF)
{
// Extract the highest 4 bits
TwoBytes[0] = (char) (0xE0 + (Source[n] >> 12) );
NumBytes = 3;
}
// Unichar is only 16 bits. Do no continue because (Source[n] >> 18) does not make sense.
// 21 valid bits 4 bytes
else if (Source[n] <= 0x1FFFFF)
{
// Extract the highest 3 bits
TwoBytes[0] = (char) (0xF0 + (Source[n] >> 18) );
NumBytes = 4;
}
// Split a 26 bit character into 5 bytes
else if (Source[n] <= 0x3FFFFFF)
{
// Extract the highest 2 bits
TwoBytes[0] = (char) (0xF8 + (Source[n] >> 24) );
NumBytes = 5;
}
// Split a 31 bit character into 6 bytes
else if (Source[n] <= 0x7FFFFFFF)
{
// Extract the highest bit
TwoBytes[0] = (char) (0xFC + (Source[n] >> 30) );
NumBytes = 6;
}
STRCAT_S (utf8, Size, (const char *) &TwoBytes[0]);
// Extract the remaining bits - 6 bits at a time
for (int i = 1, shift = (NumBytes - 2) * 6; shift >= 0; i++, shift -= 6)
{
TwoBytes[0] = (char) (0x80 + ( (Source[n] >> shift) & 0x3F) );
STRCAT_S (utf8, Size, (const char *) &TwoBytes[0]);
}
}
}
}
// void NUTF8::Convert(const t_UTF32* Source)
// {
// int NumBytes = 0;
//
// int Size = 0;
// while(Source[Size] != 0)
// {
// ++Size;
// }
// // *6: each UTF16 char can translate to up to 6 bytes in UTF8
// // +1: for NULL char
// Size = Size * 6 + 1;
// utf8 = new char[Size*sizeof(t_UTF32)];
// memset(utf8, 0, Size*sizeof(t_UTF32));
//
// unsigned char TwoBytes[2];
// TwoBytes[0] = '\0'; TwoBytes[1] = '\0';
//
// utf8[0] = '\0';
//
// // U-00000000 U-0000007F: 0xxxxxxx
// // U-00000080 U-000007FF: 110xxxxx 10xxxxxx
// // U-00000800 U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
// // U-00010000 U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// // U-00200000 U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// // U-04000000 U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// // The original specification of UTF-8 allowed for sequences of up to six bytes covering numbers up to 31 bits
// // (the original limit of the universal character set). However, UTF-8 was restricted by RFC 3629 to use only
// // the area covered by the formal Unicode definition, U+0000 to U+10FFFF, in November 2003. So UTF-8 code point is at most 4 bytes.
//
// for(size_t n = 0; Source[n] != 0; n++)
// {
// if (Source[n] <= 0x7F)
// {
// TwoBytes[0] = (char)Source[n];
// STRCAT_S(utf8, Size, (const char*)&TwoBytes[0]);
// }
// else
// {
// // 11 valid bits 2 bytes
// if (Source[n] <= 0x7FF)
// {
// // Extract the 5 highest bits
// TwoBytes[0] = (char)(0xC0 + (Source[n] >> 6));
// NumBytes = 2;
// }
// // 16 valid bits 3 bytes
// else if (Source[n] <= 0xFFFF)
// {
// // Extract the highest 4 bits
// TwoBytes[0] = (char)(0xE0 + (Source[n] >> 12));
// NumBytes = 3;
// }
// // 21 valid bits 4 bytes
// else if (Source[n] <= 0x1FFFFF)
// {
// // Extract the highest 3 bits
// TwoBytes[0] = (char)(0xF0 + (Source[n] >> 18));
// NumBytes = 4;
// }
// // Split a 26 bit character into 5 bytes
// else if (Source[n] <= 0x3FFFFFF)
// {
// // Extract the highest 2 bits
// TwoBytes[0] = (char)(0xF8 + (Source[n] >> 24));
// NumBytes = 5;
// }
// // Split a 31 bit character into 6 bytes
// else if (Source[n] <= 0x7FFFFFFF)
// {
// // Extract the highest bit
// TwoBytes[0] = (char)(0xFC + (Source[n] >> 30));
// NumBytes = 6;
// }
//
// STRCAT_S(utf8, Size, (const char*)&TwoBytes[0]);
//
// // Extract the remaining bits - 6 bits at a time
// for(int i = 1, shift = (NumBytes-2)*6; shift >= 0; i++, shift -= 6)
// {
// TwoBytes[0] = (char)(0x80 + ((Source[n] >> shift) & 0x3F));
// STRCAT_S(utf8, Size, (const char*)&TwoBytes[0]);
// }
// }
// }
// }
NUTF8::~NUTF8()
{
delete [] utf8;
}
NUTF8::operator const char* ()
{
return utf8;
}
///////////////////////////////////////////////////////////////////////////////
// Convert each unicode character in the source to UTF-8
NUTF16::NUTF16 (const char *Source)
{
Convert (Source);
}
NUTF16::NUTF16 (const std::string &Source)
{
Convert (Source.c_str() );
}
void NUTF16::Convert (const char *Source)
{
// U-00000000 U-0000007F: 0xxxxxxx
// U-00000080 U-000007FF: 110xxxxx 10xxxxxx
// U-00000800 U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
// U-00010000 U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// U-00200000 U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// U-04000000 U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
unsigned char MSB;
int temp = 0;
int numbytes = 0; // Number of bytes used to represent the unicode char
int pos = 0;
size_t len = strlen (Source) + 1; // +1 for NULL char
unicode = new UNICHAR[len*6];
// Loop through the characters in the string and decode them
for (size_t n = 0; n < len; ++n)
{
// Find the hexadecimal number following the equals sign
MSB = Source[n];
if (MSB <= 0x7F)
{
unicode[pos++] = (UNICHAR) MSB;
}
else
{
// 2 bytes
if (MSB >= 0xC0 && MSB <= 0xDF)
{
temp = (MSB - 0xC0) << 6;
numbytes = 2;
}
// 3 bytes
else if (MSB >= 0xE0 && MSB <= 0xEF)
{
temp = (MSB - 0xE0) << 12;
numbytes = 3;
}
// 4 bytes
else if (MSB >= 0xF0 && MSB <= 0xF7)
{
temp = (MSB - 0xF0) << 18;
numbytes = 4;
}
// 5 bytes
else if (MSB >= 0xF8 && MSB <= 0xFB)
{
temp = (MSB - 0xF8) << 24;
numbytes = 5;
}
// 6 bytes
else if (MSB >= 0xFC && MSB <= 0xFD)
{
temp = (MSB - 0xFC) << 30;
numbytes = 6;
}
// Loop through the remaining hexadecimal numbers representing the next unicode character
for (int i = 0, shift = (numbytes - 2) * 6; shift >= 0; i++, shift -= 6)
{
int nVal = ( ( (unsigned char) Source[n+1+i]) - 0x80 ) << shift;
temp += nVal;
}
// Add the unicode character to the final string
unicode[pos++] = (UNICHAR) temp;
// Move the character index in the source to the next unicode character
n += (numbytes - 1);
}
}
}
NUTF16::~NUTF16()
{
delete [] unicode;
}
NUTF16::operator const UNICHAR* ()
{
return unicode;
}
}
nux-4.0.8+16.04.20160209/NuxCore/LoggingWriter.h 0000644 0000156 0000165 00000003637 12656236757 021254 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUX_CORE_LOGGING_WRITER_H
#define NUX_CORE_LOGGING_WRITER_H
#include
#include
#include
#include "Logger.h"
/**
* The Writer singleton is responsible for controlling where the
* logging message go. For testing purposes it is able to define the logging
* stream, normally a std::stringstream.
*
* The default behaviour is to output to std::cout.
*
* As far as logging the timestamp goes, we only go to second precision in the
* logging format itself. If a high performance timer is needed it should be
* managed by the caller.
*/
namespace nux {
namespace logging {
class Writer : boost::noncopyable
{
public:
static Writer& Instance();
~Writer();
void WriteMessage(Level severity,
std::string const& module,
std::string const& filename,
int line_number,
std::time_t timestamp,
std::string const& message);
void SetOutputStream(std::ostream& out);
private:
Writer();
private:
class Impl;
Impl* pimpl;
};
}
}
#endif
nux-4.0.8+16.04.20160209/NuxCore/OutputDevice.cpp 0000644 0000156 0000165 00000031053 12656236757 021435 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "Parsing.h"
#include
#include
namespace nux
{
#if defined(NUX_DEBUG)
//! Create a backup copy of a file if it exist. The copy feature a timestamp in the filename.
/*!
@param Filename The name of the file to check.
*/
static void CreateBackupCopy (const TCHAR *Filename)
{
if (GFileManager.FileSize (Filename) > 0)
{
// Create string with system time to create a unique filename.
unsigned int Year, Month, Day, Hour, Min, Sec, MSec;
GetLocalTime (Year, Month, Day, Hour, Min, Sec, MSec);
std::string Name, Extension;
std::string file = Filename;
size_t pos = file.rfind('.');
if (pos != std::string::npos)
{
Name = file.substr(0, pos);
Extension = file.substr(pos + 1);
}
else
{
Name = file;
}
std::ostringstream s;
s << std::setfill('0')
<< Name << "-backup-" << Year << "."
<< std::setw(2) << Month << "."
<< std::setw(2) << Day << "."
<< std::setw(2) << Hour << "."
<< std::setw(2) << Min << "."
<< std::setw(2) << Sec;
if (Extension.size() )
{
s << "." << Extension;
}
std::string BackupFilename = s.str();
GFileManager.Copy (BackupFilename.c_str(), Filename, true, true, NULL);
}
}
#endif
NUX_IMPLEMENT_GLOBAL_OBJECT (NullOutput);
NUX_IMPLEMENT_GLOBAL_OBJECT (LogOutputRedirector);
NUX_IMPLEMENT_GLOBAL_OBJECT (LogFileOutput);
NUX_IMPLEMENT_GLOBAL_OBJECT (VisualOutputConsole)
NUX_IMPLEMENT_GLOBAL_OBJECT (PrintfOutputConsole)
LogOutputDevice::LogOutputDevice()
: _object_destroyed (false)
{
_enabled = true;
}
LogOutputDevice::~LogOutputDevice()
{
_object_destroyed = true;
}
void LogOutputDevice::Shutdown()
{
_object_destroyed = true;
}
void LogOutputDevice::Flush()
{
}
void LogOutputDevice::Enable ()
{
_enabled = true;
}
void LogOutputDevice::Disable ()
{
_enabled = false;
}
VARARG_BODY ( void /*FuncRet*/, LogOutputDevice::LogFunction/*FuncName*/, const TCHAR* /*FmtType*/, VARARG_EXTRA (int severity) /*ExtraDecl*/)
{
if (_object_destroyed)
return;
int BufferSize = 1024;
int NewBufferSize = 0;
TCHAR *Buffer = NULL;
int Result = -1;
while (Result == -1)
{
if (NewBufferSize)
{
TCHAR *temp = new TCHAR[NewBufferSize];
Memcpy (temp, Buffer, BufferSize);
NUX_SAFE_DELETE_ARRAY (Buffer);
Buffer = temp;
BufferSize = NewBufferSize;
}
else
{
Buffer = new TCHAR[BufferSize];
}
GET_VARARGS_RESULT (Buffer, BufferSize, BufferSize - 1, Fmt, Result);
if (Result == -1)
NewBufferSize = 2 * BufferSize;
};
Buffer[Result] = 0;
Serialize (Buffer, TEXT ("Nux"), severity);
NUX_SAFE_DELETE_ARRAY (Buffer);
}
void LogFileOutput::Constructor()
{
m_LogSerializer = NULL;
m_Opened = false;
m_Closed = false;
#if defined(NUX_DEBUG)
// The Editor requires a fully qualified directory to not end up putting the log in various directories.
m_Filename = GetProgramDirectory();
if ( (m_Filename[m_Filename.size()-1] != NUX_SLASH_CHAR) || (m_Filename[m_Filename.size()-1] != NUX_BACKSLASH_CHAR) )
m_Filename += (const TCHAR *) NUX_PATH_SEPARATOR_STRING;
m_Filename += GetLogDirectory();
// Create the directory tree where the Logs file will be stored.
GFileManager.MakeDirectory (m_Filename.c_str(), 1);
m_Filename += (const TCHAR *) NUX_PATH_SEPARATOR_STRING;
m_Filename += TEXT ("nux");
m_Filename += TEXT (".log");
// if the file already exists, create a backup as we are going to overwrite it
if (!m_Opened)
{
CreateBackupCopy (m_Filename.c_str() );
}
// Open log file.
m_LogSerializer = GFileManager.CreateFileWriter (m_Filename.c_str(), NSerializer::Read | NSerializer::Write | NSerializer::OverWriteReadOnly | (m_Opened ? NSerializer::Append : 0) );
if (m_LogSerializer)
{
m_Opened = true;
#if UNICODE && !NUX_LOG_FILE_ANSI
m_LogSerializer->Serialize ( (void *) &NUX_UTF16_BE[1], NUX_UTF16_BE[0] /*size*/ );
#endif
LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("Log file open, %s"), GetFormattedLocalTime().c_str());
}
else
{
m_Closed = true;
}
#endif
}
void LogFileOutput::Destructor()
{
Shutdown();
}
/*!
Closes output device and cleans up. This can't happen in the destructor
as we have to call "delete" which cannot be done for static/ global objects.
*/
void LogFileOutput::Shutdown()
{
if (m_LogSerializer)
{
LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("Log file closed, %s"), GetFormattedLocalTime().c_str());
Flush();
delete m_LogSerializer;
m_LogSerializer = NULL;
}
m_Closed = true;
}
void LogFileOutput::Flush()
{
if (m_LogSerializer)
{
m_LogSerializer->Flush();
}
}
//! Write data to the output log file.
/*!
@param log_data Text to log.
@param log_prefix Prefix for the text
*/
void LogFileOutput::Serialize (const TCHAR *log_data, const TCHAR *log_prefix, int /* severity */)
{
if (!_enabled)
return;
if (_object_destroyed)
return;
if (m_LogSerializer)
{
#if UNICODE && NUX_LOG_FILE_ANSI
ANSICHAR ACh[1024];
INT DataOffset = 0;
INT i;
while (log_data[DataOffset])
{
for (i = 0; i < NUX_ARRAY_COUNT (ACh) && log_data[DataOffset]; i++, DataOffset++)
{
ACh[i] = ConvertTCHARToAnsiChar (log_data[DataOffset]);
}
// serialize chunks of 1024 characters
m_LogSerializer->Serialize (ACh, i);
};
for (i = 0; NUX_LINE_TERMINATOR[i]; i++)
{
ACh[i] = NUX_LINE_TERMINATOR[i];
}
m_LogSerializer->Serialize (ACh, i);
#else
std::string Raw = std::string (log_prefix) + std::string (TEXT (": ") ) + std::string (log_data) + std::string (NUX_LINE_TERMINATOR);
SerializeRaw (Raw.c_str() );
#endif
}
}
void LogFileOutput::SerializeRaw (const TCHAR *log_data)
{
unsigned int s = (unsigned int) StringLength (log_data) * sizeof (TCHAR);
m_LogSerializer->Serialize (NUX_CONST_CAST (TCHAR *, log_data), s);
}
void LogOutputRedirector::Constructor()
{
}
void LogOutputRedirector::Destructor()
{
Shutdown();
}
void LogOutputRedirector::AddOutputDevice (LogOutputDevice *OutputDevice)
{
if ( OutputDevice )
{
if (std::find (OutputDevices.begin(), OutputDevices.end(), OutputDevice) != OutputDevices.end() )
return;
OutputDevices.push_back (OutputDevice);
}
}
void LogOutputRedirector::RemoveOutputDevice (LogOutputDevice *OutputDevice)
{
std::vector::iterator it = std::find (OutputDevices.begin(), OutputDevices.end(), OutputDevice);
OutputDevices.erase (it);
}
bool LogOutputRedirector::IsRedirectingTo (LogOutputDevice *OutputDevice)
{
if (std::find (OutputDevices.begin(), OutputDevices.end(), OutputDevice) != OutputDevices.end() )
return true;
return false;
}
void LogOutputRedirector::Serialize (const TCHAR *log_data, const TCHAR *log_prefix, int severity)
{
if (!_enabled)
return;
for (unsigned int OutputDeviceIndex = 0; OutputDeviceIndex < OutputDevices.size(); OutputDeviceIndex++)
{
OutputDevices[OutputDeviceIndex]->Serialize (log_data, log_prefix, severity);
}
}
void LogOutputRedirector::Flush()
{
for (unsigned int OutputDeviceIndex = 0; OutputDeviceIndex < OutputDevices.size(); OutputDeviceIndex++)
{
OutputDevices[OutputDeviceIndex]->Flush();
}
}
void LogOutputRedirector::Shutdown()
{
for (unsigned int OutputDeviceIndex = 0; OutputDeviceIndex < OutputDevices.size(); OutputDeviceIndex++)
{
OutputDevices[OutputDeviceIndex]->Shutdown();
// do not delete the output device. This is the responsibility of the owwners.
}
OutputDevices.clear();
}
void VisualOutputConsole::Constructor() {}
void VisualOutputConsole::Destructor() {}
//! Write data to visual studio output debug console.
/*!
@param log_data Text to log.
@param log_prefix Prefix for the text
*/
#if defined(NUX_OS_WINDOWS)
void VisualOutputConsole::Serialize(const TCHAR* text, const TCHAR* log_prefix, int severity)
{
if (!_enabled)
return;
TCHAR Temp[4096];
Snprintf (Temp, 4096, 4096 - 1, TEXT ("%s: %s%s"), log_prefix, text, NUX_LINE_TERMINATOR);
OutputDebugString (Temp);
}
#else
void VisualOutputConsole::Serialize(const TCHAR * /* text */, const TCHAR * /* log_prefix */, int /* severity */)
{
}
#endif
void PrintfOutputConsole::Constructor() {}
void PrintfOutputConsole::Destructor() {}
//! Write data to visual studio output debug console.
/*!
@param log_data Text to log.
@param log_prefix Prefix for the text
*/
void PrintfOutputConsole::Serialize (const TCHAR *text, const TCHAR *log_prefix, int severity)
{
if (!_enabled)
return;
TCHAR Temp[4096];
#if defined (NUX_OS_WINDOWS)
Snprintf (Temp, 4096, 4096 - 1, TEXT ("%s: %s%s"), log_prefix, text, NUX_LINE_TERMINATOR);
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (severity == NUX_MSG_SEVERITY_CRITICAL)
{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_INTENSITY|BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_INTENSITY);
}
else if (severity == NUX_MSG_SEVERITY_ALERT)
{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_INTENSITY);
}
else if (severity == NUX_MSG_SEVERITY_WARNING)
{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
}
else if (severity == NUX_MSG_SEVERITY_INFO)
{
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|FOREGROUND_INTENSITY);
}
else if (severity == NUX_MSG_SEVERITY_NONE)
{
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
}
printf ("%s", &Temp[0]);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#elif defined (NUX_OS_LINUX)
// {attr} is one of following
//
// 0 Reset All Attributes (return to normal mode)
// 1 Bright (Usually turns on BOLD)
// 2 Dim
// 3 Underline
// 5 Blink
// 7 Reverse
// 8 Hidden
//
// {fg} is one of the following
//
// 30 Black
// 31 Red
// 32 Green
// 33 Yellow
// 34 Blue
// 35 Magenta
// 36 Cyan
// 37 White (greyish)
// 38 White
//
// {bg} is one of the following
//
// 40 Black
// 41 Red
// 42 Green
// 43 Yellow
// 44 Blue
// 45 Magenta
// 46 Cyan
// 47 White (greyish)
// 48 White
int Foreground = 38;
int Background = 48;
int Bold = 0;
if (severity == NUX_MSG_SEVERITY_CRITICAL)
{
Foreground = 31;
Background = 44;
Bold = 1;
}
else if (severity == NUX_MSG_SEVERITY_ALERT)
{
Foreground = 31;
Bold = 1;
}
else if (severity == NUX_MSG_SEVERITY_WARNING)
{
Foreground = 33;
Bold = 1;
}
else if (severity == NUX_MSG_SEVERITY_INFO)
{
Foreground = 32;
Bold = 1;
}
else if (severity == NUX_MSG_SEVERITY_NONE)
{
Foreground = 38;
Bold = 0;
}
Snprintf (Temp, 4096, 4096 - 1, TEXT ("%c[%d;%d;%dm%s: %s%c[%d;%d;%dm%s"), 0x1B, Bold, Foreground, Background, log_prefix, text, 0x1B, 0, 38, 48, NUX_LINE_TERMINATOR);
printf ("%s", &Temp[0]);
#else
Snprintf (Temp, 4096, 4096 - 1, TEXT ("%s: %s%s"), log_prefix, text, NUX_LINE_TERMINATOR);
printf ("%s", &Temp[0]);
#endif
}
void NullOutput::Constructor() {}
void NullOutput::Destructor() {}
}
nux-4.0.8+16.04.20160209/NuxCore/Object.h 0000644 0000156 0000165 00000020112 12656236757 017662 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2010-2011 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUXCORE_OBJECT_H
#define NUXCORE_OBJECT_H
#include
#include
#include
#include
#include "ObjectType.h"
#include "Property.h"
#include "PropertyTraits.h"
#define NUX_FILE_LINE_PROTO const char* __Nux_FileName__=__FILE__, int __Nux_LineNumber__ = __LINE__
#define NUX_FILE_LINE_DECL const char* __Nux_FileName__, int __Nux_LineNumber__
#define NUX_FILE_LINE_PARAM __Nux_FileName__, __Nux_LineNumber__
#define NUX_TRACKER_LOCATION __FILE__, __LINE__
#define OnDestroyed object_destroyed
namespace nux
{
template
class ObjectPtr;
template
class ObjectWeakPtr;
class ObjectStats
{
NUX_DECLARE_GLOBAL_OBJECT (ObjectStats, GlobalSingletonInitializer);
public:
typedef std::list AllocationList;
AllocationList _allocation_list;
int _total_allocated_size; //! Total allocated memory size in bytes.
int _number_of_objects; //! Number of allocated objects;
};
#define GObjectStats NUX_GLOBAL_OBJECT_INSTANCE(nux::ObjectStats)
//! Base class of heap allocated objects.
/*!
Trackable does not implement reference counting. It only defines the API. It is up
to the class that inherit from Trackable to implement the reference counting.
*/
class Trackable: public nux::Introspectable, public sigc::trackable, public boost::noncopyable
{
public:
NUX_DECLARE_ROOT_OBJECT_TYPE (Trackable);
//! Test if object reference is owned.
/*
@return True if the object reference is owned.
*/
bool OwnsTheReference();
//! Test if object was allocated dynamically.
/*
@return True if the object was allocated dynamically.
*/
bool IsHeapAllocated();
//! Test if object was allocated dynamically.
/*
@return True if the object was allocated dynamically.
*/
bool IsDynamic() const;
//! Increase the reference count.
/*
Widget are typically created and added to containers. It is decided that when widgets are created, they should have a floating reference
and their reference count is set to 1.
{
Button* button = new Button(); // button ref_cout = 1, floating = true;
container->AddButton(button); // button has a floating reference; when container call button->ref() the ref count
// of button remains at 1 but the floating reference is set to false. From now on,
// calling button->ref will always increase the ref count (since button no longer has a floating reference).
}
It is best to pair calls to ref() with unref() when it comes to widgets. So if a widget was not added to a container and so it still has a
floating reference, then call Dispose(). Dispose does some sanity check; it verifies that:
ref_count == 1
floating == true
If these conditions are verified, dispose will cause the object to be destroyed.
Calling unref() on an object that has a floating reference will trigger a warning/error in order to invite the
developer. The developer can either ref the object first before calling unref or simply not create the widget since it
does not appear to have been used.
During development it often happen that one forget to dispose an object with a floating reference.
Assuming that all functions that receive a reference counted object properly call ref on the object and that the compiler
can detect unused variables, then the developer should have a way to detect reference counted objects that are not owned.
It is up to the developer to properly handle these objects.
@return True if the object has been referenced.
*/
virtual bool Reference();
//! Decrease the reference count.
/*!
@return True if the object has been destroyed
*/
virtual bool UnReference();
//! Mark the object as owned.
/*!
If this object is not owned, calling SinkReference() as the same
effect as calling Reference().
@return True if the object was not owned previously
*/
virtual bool SinkReference();
//! Destroy and object that has a floating reference.
/*!
@return True if the object has been destroyed
*/
virtual bool Dispose();
//! Return the size of allocated for this object.
/*!
@return The size allocated for this object.
*/
virtual int GetObjectSize ();
static std::new_handler set_new_handler (std::new_handler handler);
static void *operator new (size_t size);
#if (__GNUC__ < 4 && __GNUC_MINOR__ < 4)
static void *operator new (size_t size, void *ptr);
#endif
static void operator delete (void *ptr);
protected:
Trackable();
virtual ~Trackable() = 0;
void SetOwnedReference (bool b);
int _heap_allocated;
private:
static std::new_handler _new_current_handler;
bool _owns_the_reference;
int _size_of_this_object;
};
//! The base class of Nux objects.
class Object: public Trackable
{
public:
NUX_DECLARE_OBJECT_TYPE (BaseObject, Trackable);
//! Constructor
Object (bool OwnTheReference = true, NUX_FILE_LINE_PROTO);
//! Increase reference count.
/*!
@return True if the object has successfully referenced.
*/
bool Reference();
//! Decrease reference count.
/*!
@return True if the object reference count has reached 0 and the
object has been destroyed.
*/
bool UnReference();
//! Mark the object as owned.
/*!
If this object is not owned, calling SinkReference() as the same
effect as calling Reference().
@return True if the object was not owned previously
*/
virtual bool SinkReference();
//! Destroy and object that has a floating reference.
/*!
@return True is the object has been destroyed
*/
virtual bool Dispose();
//! Get the reference count of this object.
/*!
@return The reference count of this object.
*/
int GetReferenceCount() const;
//! Get the number of ObjectPtr holding this object.
/*!
@return The number of ObjectPtr holding this object.
*/
int ObjectPtrCount() const;
//! Signal emitted immediately before the object is destroyed.
sigc::signal object_destroyed;
std::string GetAllocationLocation() const;
std::string GetTypeName() const;
protected:
//! Private destructor.
/*
Private destructor. Ensure that Object cannot be created on the stack
(only on the heap), but objects that inherits from Object can stil be
created on the stack or on the heap. (MEC++ item27)
*/
virtual ~Object();
private:
//! Destroy the object.
void Destroy();
Object (const Object &);
Object &operator = (const Object &);
NThreadSafeCounter* reference_count_;
//!< Number of ObjectPtr hosting the object.
NThreadSafeCounter* objectptr_count_;
std::string allocation_location_;
std::string allocation_stacktrace_;
template
friend class ObjectPtr;
template
friend class ObjectWeakPtr;
friend class ObjectStats;
};
}
#endif // NUXOBJECT_H
nux-4.0.8+16.04.20160209/NuxCore/FilePath.cpp 0000644 0000156 0000165 00000010262 12656236757 020510 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "FilePath.h"
namespace nux
{
FilePath::FilePath()
{
if (std::find (m_SearchPath.begin(), m_SearchPath.end(), TEXT ("") ) != m_SearchPath.end() )
return;
m_SearchPath.push_back (TEXT ("") ); // for fully qualified path
}
FilePath::~FilePath()
{
}
void FilePath::AddSearchPath (const std::string &searchpath)
{
if (std::find (m_SearchPath.begin(), m_SearchPath.end(), searchpath) != m_SearchPath.end() )
return;
m_SearchPath.push_back (searchpath);
}
void FilePath::AddSearchPath (const std::vector& searchpath)
{
for (unsigned int i = 0; i < searchpath.size(); i++)
{
if (std::find (m_SearchPath.begin(), m_SearchPath.end(), searchpath[i]) == m_SearchPath.end() )
m_SearchPath.push_back (searchpath[i]);
}
}
std::string FilePath::GetPathToFile (const TCHAR *filename) const
{
std::string FileName = GetFile (filename);
size_t loc = FileName.rfind(TEXT('\\'), 0);
if (loc == std::string::npos)
{
loc = FileName.rfind(TEXT('/'), 0);
}
if (loc != std::string::npos)
FileName = FileName.substr(0, loc);
else
FileName = std::string(TEXT ("."));
return FileName;
}
std::string FilePath::GetFile (const TCHAR *filename) const
{
NUX_RETURN_VALUE_IF_NULL (filename, std::string (TEXT ("") ) );
if (std::string (filename) == std::string (TEXT ("") ) )
return std::string (TEXT ("") );
std::string FileName = filename;
if (GFileManager.FileExist(FileName.c_str() ) )
return FileName;
for (unsigned int i = 0; i < m_SearchPath.size(); i++)
{
if (m_SearchPath[i].size() == 0)
continue;
std::string FilePath;
char last = m_SearchPath[i][m_SearchPath[i].size() - 1];
if (last == TEXT('/') || last == TEXT('\\'))
FilePath = m_SearchPath[i] + filename;
else
FilePath = m_SearchPath[i] + NUX_PATH_SEPARATOR_STRING + filename;
if (GFileManager.FileExist (FilePath.c_str() ) )
return FilePath;
}
// Still not found. Then peel off the root of the filename and append our custom search path.
// filename = "MediaProg/UI3DGraphics/MyFile.txt"
// search for:
// CustomPath0/UI3DGraphics/MyFile.txt
// CustomPath1/UI3DGraphics/MyFile.txt
// CustomPath2/UI3DGraphics/MyFile.txt
// CustomPath3/UI3DGraphics/MyFile.txt
// CustomPath0/MyFile.txt
// CustomPath1/MyFile.txt
// CustomPath2/MyFile.txt
// CustomPath3/MyFile.txt
//
FileName = filename;
for (size_t i = 0; i < m_SearchPath.size(); i++)
{
size_t pos;
std::string PathName;
while (FileName.find_first_of(TEXT ("\\/")) != std::string::npos)
{
pos = FileName.find_first_of(TEXT ("\\/")) + 1;
FileName = FileName.substr(pos, FileName.length() - pos);
char last = m_SearchPath[i][m_SearchPath[i].size() - 1];
if (last == TEXT('/') || last == TEXT('\\'))
PathName = m_SearchPath[i] + FileName;
else
PathName = m_SearchPath[i] + NUX_PATH_SEPARATOR_STRING + FileName;
if (GFileManager.FileExist (PathName.c_str() ) )
return PathName;
}
}
nuxDebugMsg (TEXT ("[FilePath::GetFile] Cannot find file: %s"), filename);
return std::string (TEXT ("") );
}
}
nux-4.0.8+16.04.20160209/NuxCore/Size.h 0000644 0000156 0000165 00000002123 12656236757 017370 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUX_CORE_SIZE_H
#define NUX_CORE_SIZE_H
namespace nux
{
class Size
{
public:
Size();
Size(int w, int h);
int width;
int height;
};
bool operator == (const Size& lhs, const Size& rhs);
bool operator != (const Size& lhs, const Size& rhs);
}
#include "Size-inl.h"
#endif // SIZE_H
nux-4.0.8+16.04.20160209/NuxCore/PropertyTraits.h 0000644 0000156 0000165 00000014261 12656236757 021477 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#if defined(NUX_OS_WINDOWS)
#pragma warning(disable : 4355) // warning C4355: 'this' : used in base member initializer list
#endif
#ifndef NUXCORE_PROPERTY_TRAITS_H
#define NUXCORE_PROPERTY_TRAITS_H
#include
#include
#include
#include "Color.h"
namespace nux {
namespace type {
/**
* Here we want to have only explict type support, to avoid someone using the
* system with something we haven't though of and getting upset when if it
* doesn't work properly.
*/
template ::value>
struct PropertyTrait
{
/**
* Expected content:
*
* typedef T ValueType;
* - used to make sure that there is a definition of the PropertyTrait
* for the particular value of T.
*
* static std::string to_string(T const& value)
* - used to convert the type to a string
*
* static std::pair from_string(std::string const& serialized_form)
* - If the serialized form is convertable to T, then we get:
* (value, true)
* - If it is not convertable we get:
* (T(), false)
*/
};
/**
* The serializable_impl template has different signatures than the standard
* Serializable traits class to avoid the generalised template being used as a
* traits type when we really don't want it being used in that way, but we do
* want a generalized implementation for the types we do care about.
*/
template
struct serializable_impl
{
typedef std::pair ResultType;
static std::string to_string_impl(T const& value)
{
return boost::lexical_cast(value);
}
static ResultType from_string_impl(std::string const& serialized_form)
{
try {
return ResultType(boost::lexical_cast(serialized_form), true);
}
catch (const boost::bad_lexical_cast& ) {
return std::make_pair(T(), false);
}
}
};
template
struct PropertyTrait
{
typedef ENUM ValueType;
typedef serializable_impl Serialiser;
typedef std::pair ResultType;
static std::string to_string(ENUM value)
{
return Serialiser::to_string_impl(value);
}
static std::pair from_string(std::string const& serialized_form)
{
Serialiser::ResultType result = Serialiser::from_string_impl(serialized_form);
return ResultType(static_cast(result.first), result.second);
}
};
template <>
struct PropertyTrait
{
typedef int ValueType;
static std::string to_string(int value)
{
return serializable_impl::to_string_impl(value);
}
static std::pair from_string(std::string const& serialized_form)
{
return serializable_impl::from_string_impl(serialized_form);
}
};
template <>
struct PropertyTrait
{
typedef unsigned ValueType;
static std::string to_string(unsigned value)
{
return serializable_impl::to_string_impl(value);
}
static std::pair from_string(std::string const& serialized_form)
{
return serializable_impl::from_string_impl(serialized_form);
}
};
template <>
struct PropertyTrait
{
typedef float ValueType;
static std::string to_string(float value)
{
return serializable_impl::to_string_impl(value);
}
static std::pair from_string(std::string const& serialized_form)
{
return serializable_impl::from_string_impl(serialized_form);
}
};
template <>
struct PropertyTrait
{
typedef double ValueType;
static std::string to_string(double value)
{
return serializable_impl::to_string_impl(value);
}
static std::pair from_string(std::string const& serialized_form)
{
return serializable_impl::from_string_impl(serialized_form);
}
};
template <>
struct PropertyTrait
{
typedef bool ValueType;
static std::string to_string(bool value)
{
return value ? "true" : "false";
}
static std::pair from_string(std::string const& serialized_form)
{
if (serialized_form == "true") {
return std::make_pair(true, true);
} else if (serialized_form == "false") {
return std::make_pair(false, true);
} else {
return std::make_pair(false, false);
}
}
};
template <>
struct PropertyTrait
{
typedef std::string ValueType;
static std::string to_string(std::string const& value)
{
return value;
}
static std::pair from_string(std::string const& serialized_form)
{
return std::make_pair(serialized_form, true);
}
};
// template <>
// struct PropertyTrait
// {
// typedef Color ValueType;
// static std::string to_string(Color value)
// {
// std::string str = std::string("[") +
// serializable_impl::to_string_impl(value.red) + std::string(" ") +
// serializable_impl::to_string_impl(value.green) + std::string(" ") +
// serializable_impl::to_string_impl(value.blue) + std::string(" ") +
// serializable_impl::to_string_impl(value.alpha) + std::string(" ") +
// std::string("]");
// return str;
// }
// static std::pair from_string(std::string const& serialized_form)
// {
// // todo
// return std::make_pair(color::Red, true);
// }
// };
}
}
#endif
nux-4.0.8+16.04.20160209/NuxCore/EasingCurve.h 0000644 0000156 0000165 00000003334 12656236757 020676 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2012 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUX_CORE_EASING_CURVE_H
#define NUX_CORE_EASING_CURVE_H
namespace nux
{
namespace animation
{
class EasingCurve
{
public:
#if defined(NUX_OS_WINDOWS) && !defined(NUX_VISUAL_STUDIO_VC11)
enum Type
#else
enum class Type
#endif
{
Linear,
InQuad,
OutQuad,
InOutQuad,
BackEaseIn,
BackEaseOut,
BackEaseInOut,
BounceIn,
BounceOut,
BounceInOut,
ExpoEaseIn,
ExpoEaseOut
};
typedef double (*EasingFunction)(double);
explicit EasingCurve(Type type = Type::Linear);
// progress is expected to be between zero and one inclusive.
//
// Values less than zero will return zero will return zero, and
// greater than one will return one.
//
// The returned value may be greater than one, or less than zero for some
// special curves.
double ValueForProgress(double progress);
private:
EasingFunction func_;
};
}}
#endif
nux-4.0.8+16.04.20160209/NuxCore/AsyncFileWriter.h 0000644 0000156 0000165 00000003220 12656236757 021527 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUXCORE_ASYNC_FILE_WRITER_H
#define NUXCORE_ASYNC_FILE_WRITER_H
#include
#include
namespace nux
{
/**
* Write to a file asynchronously.
*
* This uses the GIO async functions, and as such depend on the gobject main
* loop.
*/
class AsyncFileWriter
{
public:
AsyncFileWriter(std::string const& filename);
// Destructor kills any pending async requests, and close the file
// synchronously if it is open.
~AsyncFileWriter();
// Queue the data for writing. It'll happen some time.
void Write(std::string const& data);
// Close the file asynchronously. When the file is closed, the closed
// signal is emitted.
void Close();
bool IsClosing() const;
sigc::signal opened;
sigc::signal closed;
private:
class Impl;
Impl* pimpl;
};
}
#endif
nux-4.0.8+16.04.20160209/NuxCore/ThreadWin.cpp 0000644 0000156 0000165 00000026533 12656236757 020711 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
#include "TextString.h"
#include "ThreadWin.h"
namespace nux
{
#define NUX_ATOMOP_ITERLOCKED_INCREMENT InterlockedIncrement
#define NUX_ATOMOP_ITERLOCKED_DECREMENT InterlockedDecrement
#define NUX_ATOMOP_ITERLOCKED_EXCHANGED InterlockedExchange
#define NUX_ATOMOP_ITERLOCKED_VALUE
long NThreadSafeCounter::Increment()
{
return NUX_ATOMOP_ITERLOCKED_INCREMENT ( &m_Counter );
}
long NThreadSafeCounter::Decrement()
{
return NUX_ATOMOP_ITERLOCKED_DECREMENT ( &m_Counter );
}
long NThreadSafeCounter::Set (long i)
{
return NUX_ATOMOP_ITERLOCKED_EXCHANGED ( &m_Counter, i );
}
long NThreadSafeCounter::GetValue() const
{
return m_Counter;
}
long NThreadSafeCounter::operator ++ ()
{
return Increment();
}
long NThreadSafeCounter::operator -- ()
{
return Decrement();
}
bool NThreadSafeCounter::operator == (long i)
{
return (m_Counter == i);
}
unsigned int NThreadLocalStorage::m_TLSIndex[NThreadLocalStorage::NbTLS];
BOOL NThreadLocalStorage::m_TLSUsed[NThreadLocalStorage::NbTLS];
NThreadLocalStorage::TLS_ShutdownCallback NThreadLocalStorage::m_TLSCallbacks[NThreadLocalStorage::NbTLS];
// http://msdn2.microsoft.com/en-us/library/xcb2z8hs(VS.80).aspx
//
// Usage: SetWin32ThreadName (-1, "MainThread");
//
#define MS_VC_EXCEPTION 0x406D1388
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
void SetWin32ThreadName (DWORD dwThreadID, LPCSTR szThreadName)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try
{
RaiseException ( MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (DWORD), (ULONG_PTR *) &info );
}
__except (EXCEPTION_CONTINUE_EXECUTION)
{
}
}
BOOL NThreadLocalStorage::RegisterTLS(unsigned int index, NThreadLocalStorage::TLS_ShutdownCallback shutdownCallback)
{
if (m_TLSUsed[index])
{
nuxDebugMsg("[NThreadLocalStorage::RegisterTLS] TLS has already been registered.");
return TRUE;
}
if (!m_TLSUsed[index])
{
m_TLSIndex[index] = TlsAlloc();
if (m_TLSIndex[index] == TLS_OUT_OF_INDEXES)
{
nuxAssertMsg (0, TEXT ("[NThreadLocalStorage::RegisterTLS] Out of TLS index.") );
}
m_TLSUsed[index] = TRUE;
m_TLSCallbacks[index] = shutdownCallback;
return TRUE;
}
else
{
return FALSE;
}
}
void NThreadLocalStorage::Initialize()
{
for (unsigned int i = 0; i < NThreadLocalStorage::NbTLS; i++)
{
m_TLSUsed[i] = FALSE;
// Fill the array with invalid values
m_TLSIndex[i] = NThreadLocalStorage::InvalidTLS; // invalid index
}
}
void NThreadLocalStorage::Shutdown()
{
ThreadShutdown();
}
void NThreadLocalStorage::ThreadInit()
{
}
void NThreadLocalStorage::ThreadShutdown()
{
TLS_ShutdownCallback *callback = m_TLSCallbacks;
for (unsigned int i = 0; i < NThreadLocalStorage::NbTLS; ++i, ++callback)
{
if (*callback)
{
(**callback) ();
}
}
}
NUX_IMPLEMENT_ROOT_OBJECT_TYPE (NThread);
NThread::NThread()
: m_ThreadState (THREADINIT)
{
m_pThreadFunc = NThread::EntryPoint; // Can call Detach() also.
}
NThread::NThread (LPTHREAD_START_ROUTINE lpExternalRoutine)
{
Attach (lpExternalRoutine);
}
NThread::~NThread()
{
CloseHandle (m_ThreadCtx.m_hThread);
}
ThreadState NThread::Start ( void *arg )
{
if ( m_ThreadCtx.m_hThread == 0)
{
m_ThreadCtx.m_pUserData = arg;
m_ThreadCtx.m_hThread = CreateThread (NULL,
0,
m_pThreadFunc,
this,
0 /*CREATE_SUSPENDED*/,
(LPDWORD) &m_ThreadCtx.m_dwTID);
if (m_ThreadCtx.m_hThread != 0)
{
//ResumeStart();
m_ThreadState = THREADINIT;
m_ThreadCtx.m_dwExitCode = (unsigned int) - 1;
return m_ThreadState;
}
else
{
nuxDebugMsg (TEXT ("[NThread::Start] Cannot start thread: %s"), inlGetSystemErrorMessage() );
m_ThreadState = THREAD_START_ERROR;
return m_ThreadState;
}
}
return m_ThreadState;
}
ThreadState NThread::Stop(bool bForceKill)
{
// From MSDN
// TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating.
// TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:
// If the target thread owns a critical section, the critical section will not be released.
// If the target thread is allocating memory from the heap, the heap lock will not be released.
// If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
// If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
// Attention: Calling Stop from another thread is not going to free the stack of this thread.
// the stack is freed only if the thread exits by itself.
if (m_ThreadCtx.m_hThread)
{
BOOL success = GetExitCodeThread(m_ThreadCtx.m_hThread, (LPDWORD) &m_ThreadCtx.m_dwExitCode);
if ((m_ThreadCtx.m_dwExitCode == STILL_ACTIVE) && bForceKill)
{
// This will forcibly kill the thread! Read the doc on TerminateThread to find out about the consequences.
TerminateThread(m_ThreadCtx.m_hThread, unsigned int (-1));
CloseHandle(m_ThreadCtx.m_hThread);
}
m_ThreadCtx.m_hThread = NULL;
}
m_ThreadState = THREADSTOP;
return m_ThreadState;
}
ThreadState NThread::Suspend()
{
unsigned int ret = SuspendThread(m_ThreadCtx.m_hThread);
if (ret == 0xFFFFFFFF)
{
nuxDebugMsg(TEXT("[NThread::Suspend] Cannot suspend thread: %s"), inlGetSystemErrorMessage());
return THREAD_SUSPEND_ERROR;
}
m_ThreadState = THREADSUSPENDED;
return m_ThreadState;
}
ThreadState NThread::Resume()
{
unsigned int ret = ResumeThread(m_ThreadCtx.m_hThread);
if (ret == 0xFFFFFFFF)
{
nuxDebugMsg(TEXT("[NThread::Suspend] Cannot resume thread: %s"), inlGetSystemErrorMessage());
return THREAD_RESUME_ERROR;
}
if (ret == 1)
{
// If the return value is 1, the specified thread was suspended but was restarted.
m_ThreadState = THREADRUNNING;
}
if (ret > 1)
{
// If the return value is greater than 1, the specified thread is still suspended.
m_ThreadState = THREADSUSPENDED;
}
return m_ThreadState;
}
// go from suspended to thread start
ThreadState NThread::ResumeStart()
{
m_ThreadState = THREADINIT;
unsigned int ret = ResumeThread(m_ThreadCtx.m_hThread);
if (ret == 0xFFFFFFFF)
{
nuxDebugMsg(TEXT("[NThread::ResumeExit] Cannot resume thread: %s"), inlGetSystemErrorMessage());
return THREAD_RESUME_ERROR;
}
if (ret == 1)
{
// If the return value is 1, the specified thread was suspended but was restarted.
m_ThreadState = THREADINIT;
}
if (ret > 1)
{
nuxAssert(0); // should not happen
// If the return value is greater than 1, the specified thread is still suspended.
m_ThreadState = THREADINIT;
}
return m_ThreadState;
}
// go from suspended to thread exit
ThreadState NThread::ResumeExit()
{
m_ThreadState = THREADSTOP;
unsigned int ret = ResumeThread(m_ThreadCtx.m_hThread);
if (ret == 0xFFFFFFFF)
{
nuxDebugMsg(TEXT("[NThread::ResumeExit] Cannot resume thread: %s"), inlGetSystemErrorMessage());
return THREAD_RESUME_ERROR;
}
if (ret == 1)
{
// If the return value is 1, the specified thread was suspended but was restarted.
m_ThreadState = THREADSTOP;
}
if (ret > 1)
{
nuxAssert(0); // should not happen
// If the return value is greater than 1, the specified thread is still suspended.
m_ThreadState = THREADSTOP;
}
return m_ThreadState;
}
DWORD WINAPI NThread::EntryPoint(void *pArg)
{
NThread *pParent = reinterpret_cast (pArg);
if (pParent == 0)
{
nuxDebugMsg(TEXT("[NThread::EntryPoint] Invalid pointer. The thread will exit."));
return 0;
}
if (!pParent->ThreadCtor())
{
// return another message saying the thread could not execute due to error in ThreadCtor;
return 0;
}
pParent->Run(pParent->m_ThreadCtx.m_pUserData);
pParent->ThreadDtor();
return 0;
}
unsigned int NThread::GetExitCode() const
{
if ( m_ThreadCtx.m_hThread )
GetExitCodeThread (m_ThreadCtx.m_hThread, (LPDWORD) &m_ThreadCtx.m_dwExitCode);
return m_ThreadCtx.m_dwExitCode;
}
HANDLE NThread::GetThreadHandle()
{
return m_ThreadCtx.m_hThread;
}
unsigned int NThread::GetThreadId()
{
return (unsigned int)m_ThreadCtx.m_dwTID;
}
ThreadState NThread::GetThreadState() const
{
return m_ThreadState;
}
void NThread::SetThreadState(ThreadState state)
{
m_ThreadState = state;
}
void NThread::SetThreadName(const TCHAR *ThreadName)
{
SetWin32ThreadName (GetThreadId(), TCHAR_TO_ANSI (ThreadName) );
m_ThreadName = ThreadName;
}
const std::string& NThread::GetThreadName() const
{
return m_ThreadName;
}
ThreadWaitResult NThread::JoinThread(NThread *thread, unsigned int milliseconds)
{
if (thread == NULL)
{
return THREAD_WAIT_RESULT_FAILED;
}
unsigned int result = WaitForSingleObject(thread->GetThreadHandle(), milliseconds);
switch(result)
{
case WAIT_OBJECT_0:
return THREAD_WAIT_RESULT_COMPLETED;
case WAIT_ABANDONED:
return THREAD_WAIT_RESULT_ABANDONED;
case WAIT_TIMEOUT:
return THREAD_WAIT_RESULT_TIMEOUT;
case WAIT_FAILED:
default:
return THREAD_WAIT_RESULT_FAILED;
}
}
}
nux-4.0.8+16.04.20160209/NuxCore/Parsing.h 0000644 0000156 0000165 00000021643 12656236757 020071 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NPARSING_H
#define NPARSING_H
namespace nux
{
//! Parse a stream of characters and look for a string of TCHAR at the start of the stream.
/*!
If the string is found, Stream points to the next character after the string.
Space and tab characters at the beginning of the stream are ignored.
@param Stream Character stream to search.
@param Match Token to match.
@return TRUE if the character string is found at the start of the stream (excluding space and tab characters).
*/
bool ParseCommand (const TCHAR **Stream, const TCHAR *Match);
//! Parse a stream of characters and look for a t_32 value after the token string.
/*!
Parse a unsigned int after the named token.
@param stream Character stream to search.
@param token Token to match.
@return True if the character string is found at the start of the stream (excluding space and tab characters).
*/
bool Parse_u32 (const TCHAR *stream, const TCHAR *Match, DWORD &value);
//! Parses a string of N character from a character stream after a named token.
/*!
Parses a string from a character stream.
@param Stream Character stream to search.
@param Match Token to match.
@param Value Buffer containing the parsed value.
@param Size The size of the Value buffer, in characters.
@param MaxLen Max number of character to return.
@return TRUE if the token is found inside the stream.
*/
bool Parse_tchar (const TCHAR *stream, const TCHAR *Match, TCHAR *value, int size, int MaxLen);
//! Parse a BYTE after the named token.
/*!
Parse a BYTE after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value Buffer containing the parsed value.
@return TRUE if the token is found inside the stream.
*/
bool Parse_u8 (const TCHAR *Stream, const TCHAR *Match, BYTE &Value);
//! Parse a signed BYTE after the named token.
/*!
Parse a signed BYTE after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed signed BYTE
@return TRUE if the token is found inside the stream.
*/
bool Parse_s8 (const TCHAR *Stream, const TCHAR *Match, SBYTE &Value);
//! Parse a WORD after the named token.
/*!
Parse a WORD after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed WORD
@return TRUE if the token is found inside the stream.
*/
bool Parse_u16 (const TCHAR *Stream, const TCHAR *Match, WORD &Value);
//! Parse a signed WORD after the named token.
/*!
Parse a signed WORD after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed signed WORD
@return TRUE if the token is found inside the stream.
*/
bool Parse_s16 (const TCHAR *Stream, const TCHAR *Match, SWORD &Value);
//! Parse a floating point value after the named token.
/*!
Parse a floating point value after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed floating point value
@return TRUE if the token is found inside the stream.
*/
bool Parse_float (const TCHAR *Stream, const TCHAR *Match, float &Value);
//! Parse a double WORD after the named token.
/*!
Parse a double WORD after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed double WORD
@return TRUE if the token is found inside the stream.
*/
bool Parse_int (const TCHAR *Stream, const TCHAR *Match, int &Value);
//! Parse a std::string after the named token.
/*!
Parse a std::string after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed std::string
@return TRUE if the token is found inside the stream.
*/
bool Parse_string (const TCHAR *Stream, const TCHAR *Match, std::string &Value);
//! Parse a QUADWORD after the named token.
/*!
Parse a QUADWORD after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed QUADWORD
@return TRUE if the token is found inside the stream.
*/
bool Parse_u64 (const TCHAR *Stream, const TCHAR *Match, QWORD &Value);
//! Parse a SIGNED QUADWORD after the named token.
/*!
Parse a SIGNED QUADWORD after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed SIGNED QUADWORD
@return TRUE if the token is found inside the stream.
*/
bool Parse_s64 (const TCHAR *Stream, const TCHAR *Match, SQWORD &Value);
//! Parse a BOOLEAN after the named token.
/*!
Parse a BOOLEAN after the named token.
@param Stream Character stream to search.
@param Match Token to match.
@param Value parsed BOOLEAN value
@return TRUE if the token is found inside the stream.
*/
bool Parse_bool (const TCHAR *Stream, const TCHAR *Match, bool &OnOff);
//! Extract a line of Stream (everything up to, but not including, CR/LF).
/*!
@param Stream Character stream to search.
@param LineBuffer The first line in Stream.
@param BufferSize Size of LineBuffer.
@param GoToNextLine If true, advanced the pointer after the first CR/LF character at the end of the string.
If FALSE advanced the pointer past all the CR/LF character at the end of the string.
@return True i a line was copied to LineString;
*/
bool ParseLine (const TCHAR **Stream, TCHAR *LineBuffer, int BufferSize);
//! Extract a line of Stream (everything up to, but not including, CR/LF).
/*!
@param Stream Character stream to search.
@param LineString The first line in Stream.
@param GoToNextLine If true, advanced the pointer after the first CR/LF character at the end of the string.
If FALSE advanced the pointer past all the CR/LF character at the end of the string.
@return True i a line was copied to LineString;
*/
bool ParseLine (const TCHAR **Stream, std::string &LineString);
//! Parse the next space-delimited string from the input stream. If the next token starts with a quote, gets entire quoted string.
/*!
@param Str stream of characters to search.
@param TokenBuffer The parsed token string.
@param BufferSize Size of the TokenBuffer.
@return True if a token was found.
*/
bool ParseToken (const TCHAR *Str, TCHAR *TokenBuffer, int BufferSize);
//! Parse the next space-delimited string from the input stream. If the next token starts with a quote, gets entire quoted string.
/*!
@param Str stream of characters to search.
@param TokenBuffer The parsed token string.
@return True if a token was found.
*/
bool ParseToken (const TCHAR *Str, std::string &TokenString);
//! Parse the next space-delimited string from the input stream. If the next token starts with a quote, gets entire quoted string.
/*!
@param Str stream of characters to parse.
@return The next token in a std::string.
*/
std::string ParseToken (const TCHAR *Str);
//! Go to the next token in the stream.
/*!
Skip tabs, and space at the beginning of each line.
Skip everything on a line that follows the given comment char token
If there is a valid token in the input, Stream will point to it.
@param Stream stream of characters
@param CommentChar Character representing the beginning of a comment on a line. ie ';' '#".
*/
void ParseToNextLine (const TCHAR **Stream, TCHAR CommentChar);
//! Checks if a Token command-line parameter exists in the stream.
/*!
Checks if a Token command-line parameter exists in the stream
@param Stream stream of characters to search
@param token to match
@return True if found.
*/
bool ParseParam (const TCHAR *Stream, const TCHAR *Param);
}
#endif // NPARSING_H
nux-4.0.8+16.04.20160209/NuxCore/RollingFileAppender.h 0000644 0000156 0000165 00000002561 12656236757 022351 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUX_CORE_ROLLING_FILE_APPENDER_H
#define NUX_CORE_ROLLING_FILE_APPENDER_H
#include
#include
#include
namespace nux {
namespace logging {
class RollingFileAppender : public std::ostream
{
public:
RollingFileAppender(std::string const& filename);
RollingFileAppender(std::string const& filename,
unsigned number_of_backup_files,
unsigned long long max_log_size);
~RollingFileAppender();
sigc::signal files_rolled;
};
}
}
#endif
nux-4.0.8+16.04.20160209/NuxCore/Process.cpp 0000644 0000156 0000165 00000007437 12656236757 020444 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#include "NuxCore.h"
namespace nux
{
#ifdef _WIN32
//
// Launch a uniform resource locator (i.e. http://www.yahoo.com/finance).
// This is expected to return immediately as the URL is launched by another
// task.
//
void inlLaunchURL(const TCHAR *URL, const TCHAR *Parms, std::string Error)
{
nuxDebugMsg ( TEXT ("LaunchURL %s %s"), URL, Parms ? Parms : TEXT ("") );
HINSTANCE Code = CALL_OS_TCHAR_FUNCTION (ShellExecuteW (NULL, TEXT ("open"), URL, Parms ? Parms : TEXT (""), TEXT (""), SW_SHOWNORMAL), ShellExecuteA (NULL, "open", TCHAR_TO_ANSI (URL), Parms ? TCHAR_TO_ANSI (Parms) : "", "", SW_SHOWNORMAL) );
Error = (int) Code <= 32 ? TEXT ("UrlFailed") : TEXT ("");
}
//
// Creates a new process and its primary thread. The new process runs the
// specified executable file in the security context of the calling process.
//
void *inlCreateProc ( const TCHAR *URL, const TCHAR *Parms )
{
nuxDebugMsg ( TEXT ("CreateProc %s %s"), URL, Parms );
TCHAR CommandLine[1024];
Snprintf ( CommandLine, 1024, 1024 - 1, TEXT ("%s %s"), URL, Parms );
PROCESS_INFORMATION ProcInfo;
SECURITY_ATTRIBUTES Attr;
Attr.nLength = sizeof (SECURITY_ATTRIBUTES);
Attr.lpSecurityDescriptor = NULL;
Attr.bInheritHandle = TRUE;
STARTUPINFO StartupInfo = { sizeof (STARTUPINFO), NULL, NULL, NULL,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, NULL, NULL, SW_HIDE, NULL, NULL,
NULL, NULL, NULL
};
if ( !CreateProcess ( NULL, CommandLine, &Attr, &Attr, TRUE, DETACHED_PROCESS | REALTIME_PRIORITY_CLASS,
NULL, NULL, &StartupInfo, &ProcInfo ) )
return NULL;
return (void *) ProcInfo.hProcess;
}
//
// Retrieves the termination status of the specified process.
//
BOOL inlGetProcReturnCode ( void *ProcHandle, INT *ReturnCode )
{
return GetExitCodeProcess ( (HANDLE) ProcHandle, (DWORD *) ReturnCode ) && * ( (DWORD *) ReturnCode) != STILL_ACTIVE;
}
NUX_IMPLEMENT_GLOBAL_OBJECT (NProcess);
void NProcess::Constructor()
{
m_ProcessID = GetCurrentProcessId();
m_ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, m_ProcessID);
m_MainThreadID = GetCurrentThreadId();
m_MainThreadHandle = OpenThread (THREAD_ALL_ACCESS, FALSE, m_MainThreadID);
}
void NProcess::Destructor()
{
CloseHandle (m_MainThreadHandle);
CloseHandle (m_ProcessHandle);
}
HANDLE NProcess::GetProcessHandle()
{
return m_ProcessHandle;
}
DWORD NProcess::GetProcessID()
{
return m_ProcessID;
}
HANDLE NProcess::GetMainThreadHandle()
{
return m_MainThreadHandle;
}
DWORD NProcess::GetMainThreadID()
{
return m_MainThreadID;
}
HANDLE NProcess::GetCurrentThreadHandle()
{
DWORD ThreadID = GetCurrentThreadId();
return OpenThread (THREAD_ALL_ACCESS, FALSE, ThreadID);
}
DWORD NProcess::GetCurrentThreadID()
{
return GetCurrentThreadId();
}
#endif
}
nux-4.0.8+16.04.20160209/NuxCore/Property-inl.h 0000644 0000156 0000165 00000021310 12656236757 021061 0 ustar pbuser pbgroup 0000000 0000000 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright 2011 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Tim Penhey
*
*/
#ifndef NUXCORE_PROPERTY_INL_H
#define NUXCORE_PROPERTY_INL_H
namespace nux {
template
PropertyChangedSignal::PropertyChangedSignal()
: notify_(true)
{}
template
void PropertyChangedSignal::DisableNotifications()
{
notify_ = false;
}
template
void PropertyChangedSignal::EnableNotifications()
{
notify_ = true;
}
template
void PropertyChangedSignal::EmitChanged(VALUE_TYPE const& new_value)
{
if (notify_)
changed.emit(new_value);
}
template
Property::Property()
: value_(VALUE_TYPE())
, setter_function_(std::bind(&Property::DefaultSetter, this,
std::placeholders::_1, std::placeholders::_2))
{}
template
Property::Property(VALUE_TYPE const& initial)
: value_(initial)
, setter_function_(std::bind(&Property::DefaultSetter, this,
std::placeholders::_1, std::placeholders::_2))
{}
template
Property::Property(VALUE_TYPE const& initial,
SetterFunction setter_function)
: value_(initial)
, setter_function_(setter_function)
{}
template
VALUE_TYPE Property::operator=(VALUE_TYPE const& value)
{
return Set(value);
}
template
Property::operator VALUE_TYPE() const
{
return value_;
}
template
VALUE_TYPE Property::operator()() const
{
return value_;
}
template
VALUE_TYPE Property::operator()(VALUE_TYPE const& value)
{
return Set(value);
}
template
VALUE_TYPE Property::Get() const
{
return value_;
}
template
VALUE_TYPE Property::Set(VALUE_TYPE const& value)
{
if (setter_function_(value_, value))
SignalBase::EmitChanged(value_);
return value_;
}
template
bool Property::DefaultSetter(VALUE_TYPE& target,
VALUE_TYPE const& value)
{
bool changed = false;
if (target != value) {
target = value;
changed = true;
}
return changed;
}
template
void Property::SetSetterFunction(SetterFunction setter_function)
{
setter_function_ = setter_function;
}
template
ROProperty::ROProperty()
: getter_function_(std::bind(&ROProperty::DefaultGetter, this))
{}
template
ROProperty::ROProperty(GetterFunction getter_function)
: getter_function_(getter_function)
{}
template
ROProperty::operator VALUE_TYPE() const
{
return getter_function_();
}
template
VALUE_TYPE ROProperty::operator()() const
{
return getter_function_();
}
template
VALUE_TYPE ROProperty::Get() const
{
return getter_function_();
}
template
VALUE_TYPE ROProperty::DefaultGetter() const
{
return VALUE_TYPE();
}
template
void ROProperty::SetGetterFunction(GetterFunction getter_function)
{
getter_function_ = getter_function;
}
template
RWProperty::RWProperty()
: getter_function_(std::bind(&RWProperty::DefaultGetter, this))
, setter_function_(std::bind(&RWProperty::DefaultSetter, this,
std::placeholders::_1))
{}
template
RWProperty::RWProperty(GetterFunction getter_function,
SetterFunction setter_function)
: getter_function_(getter_function)
, setter_function_(setter_function)
{}
template
VALUE_TYPE RWProperty::operator=(VALUE_TYPE const& value)
{
return Set(value);
}
template
RWProperty::operator VALUE_TYPE() const
{
return getter_function_();
}
template
VALUE_TYPE RWProperty::operator()() const
{
return getter_function_();
}
template
VALUE_TYPE RWProperty::operator()(VALUE_TYPE const& value)
{
return Set(value);
}
template
VALUE_TYPE RWProperty::Get() const
{
return getter_function_();
}
template
VALUE_TYPE RWProperty::Set(VALUE_TYPE const& value)
{
if (setter_function_(value))
{
VALUE_TYPE new_value = getter_function_();
SignalBase::EmitChanged(new_value);
return new_value;
}
return getter_function_();
}
template
VALUE_TYPE RWProperty::DefaultGetter() const
{
return VALUE_TYPE();
}
template
bool RWProperty::DefaultSetter(VALUE_TYPE const& /* value */)
{
return false;
}
template
void RWProperty::SetSetterFunction(SetterFunction setter_function)
{
setter_function_ = setter_function;
}
template
void RWProperty::SetGetterFunction(GetterFunction getter_function)
{
getter_function_ = getter_function;
}
// We need to provide a default constructor since we hide the copy ctor.
inline Introspectable::Introspectable()
{}
inline void Introspectable::AddProperty(std::string const& name,
PropertyBase* property)
{
// check to see if it exists and if it does barf horribly as we can't
// have two properties with the same name;
properties_[name] = property;
}
inline bool Introspectable::SetProperty(std::string const& name,
const char* value)
{
PropertyContainer::iterator i = properties_.find(name);
if (i == properties_.end())
return false;
else
return i->second->SetValue(value);
}
template
bool Introspectable::SetProperty(std::string const& name, T const& value)
{
PropertyContainer::iterator i = properties_.find(name);
if (i == properties_.end())
return false;
else
{
return i->second->SetValue(type::PropertyTrait::to_string(value));
}
}
template
T Introspectable::GetProperty(std::string const& name, T* /* foo */)
{
PropertyContainer::iterator i = properties_.find(name);
if (i == properties_.end())
return T();
std::string s = i->second->GetSerializedValue();
std::pair result = type::PropertyTrait::from_string(s);
// If this is called with a template type that the property does not
// support nice conversion to, you'll get no error, but will get
// a default constructed T. We could use an exception here.
return result.first;
}
template
SerializableProperty::SerializableProperty(Introspectable* owner,
std::string const& name)
: Base()
, name_(name)
{
owner->AddProperty(name, this);
}
template
SerializableProperty::SerializableProperty(Introspectable* owner,
std::string const& name,
T const& initial)
: Base(initial)
, name_(name)
{
owner->AddProperty(name, this);
}
template
bool SerializableProperty::SetValue(std::string const& serialized_form)
{
std::pair result = TraitType::from_string(serialized_form);
if (result.second) {
Base::Set(result.first);
}
return result.second;
}
template
std::string SerializableProperty::GetSerializedValue() const
{
return TraitType::to_string(Base::Get());
}
template
T SerializableProperty::operator=(T const& value)
{
Base::Set(value);
// There are no arguments to ‘get’ that depend on a template parameter,
// so we explicitly specify Base.
return Base::Get();
}
}
#endif
nux-4.0.8+16.04.20160209/NuxCore/NumberConversion.h 0000644 0000156 0000165 00000003755 12656236757 021770 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NUMBERCONVERSION_H
#define NUMBERCONVERSION_H
namespace nux
{
//! Convert a TCHAR string to a double value.
/*!
@param digit A TCHAR string.
@return A double value translated from a TCHAR string.
*/
double CharToDouble (const TCHAR *digit);
//! Convert a double to an std::string.
/*!
@param d A double value.
@return An std::string.
*/
std::string DoubleToChar (double d);
//! Convert a TCHAR string to a 32 bits long value.
/*!
@param digit A TCHAR string.
@return A 32 bits long value translated from a TCHAR string.
*/
int CharToInteger (const TCHAR *digit);
//! Convert an integer to a tstring.
/*!
@param value An integer value.
@param base Base of the integer representation.
@return A string.
*/
std::string IntegerToChar (int value, int base = 10);
//! Convert an string to an integer.
/*!
@param digit A TCHAR string.
@return An integer value.
*/
int IntegerToChar (const TCHAR *digit);
//! Convert an Hex TCHAR string to an integer value.
/*!
@param value A TCHAR string.
@return An integer value.
*/
unsigned int HexCharToInteger (const TCHAR *s);
}
#endif // NUMBERCONVERSION_H
nux-4.0.8+16.04.20160209/NuxCore/Makefile.am 0000644 0000156 0000165 00000011236 12656236757 020346 0 ustar pbuser pbgroup 0000000 0000000 CLEANFILES =
DISTCLEANFILES =
EXTRA_DIST =
AM_CPPFLAGS = \
-I$(srcdir) \
-I$(top_srcdir) \
-DPREFIX=\""$(prefix)"\" \
-DLIBDIR=\""$(libdir)"\" \
-DDATADIR=\""$(datadir)"\" \
-DG_LOG_DOMAIN=\"NuxCore\"
lib_LTLIBRARIES = \
libnux-core-@NUX_API_VERSION@.la
libnux_core_@NUX_API_VERSION@_la_CPPFLAGS= \
$(GCC_FLAGS) \
$(NUX_CORE_CFLAGS) \
$(MAINTAINER_CFLAGS) \
$(COVERAGE_CFLAGS)
libnux_core_@NUX_API_VERSION@_la_LIBADD = \
$(NUX_CORE_LIBS) -lpthread
libnux_core_@NUX_API_VERSION@_la_LDFLAGS = \
$(NUX_LT_LDFLAGS) \
$(COVERAGE_LDFLAGS)
source_cpp = \
Animation.cpp \
AnimationController.cpp \
AsyncFileWriter.cpp \
EasingCurve.cpp \
TextString.cpp \
TimeFunctions.cpp \
Template.cpp \
FilePath.cpp \
FileManager/NSerializer.cpp \
FileManager/NFileManagerGeneric.cpp \
FileManager/NFileManagerGNU.cpp \
SystemGNU.cpp \
OutputDevice.cpp \
Exception.cpp \
Memory.cpp \
Character/NUTF.cpp \
Character/NUni.cpp \
Character/NUnicode.cpp \
Color.cpp \
ColorPrivate.cpp \
Colors.cpp \
FileName.cpp \
ThreadGNU.cpp \
Parsing.cpp \
Logger.cpp \
LoggingWriter.cpp \
NUniqueIndex.cpp \
GlobalInitializer.cpp \
ObjectType.cpp \
Platform.cpp \
Rect.cpp \
FileIO.cpp \
Process.cpp \
NumberConversion.cpp \
NuxCore.cpp \
Object.cpp \
Math/Algo.cpp \
Math/Constants.cpp \
Math/MathFunctions.cpp \
Math/Line2D.cpp \
Math/Bezier.cpp \
Math/Spline.cpp \
Math/Quaternion.cpp \
Math/Matrix2.cpp \
Math/Trigonometry.cpp \
Math/Tweening.cpp \
Math/Complex.cpp \
Math/Point3D.cpp \
Math/Matrix4.cpp \
Math/Matrix3.cpp \
Math/Line3D.cpp \
RollingFileAppender.cpp \
InitiallyUnownedObject.cpp
source_file_manager_h = \
FileManager/NFileManagerGNU.h \
FileManager/NFileManagerGeneric.h \
FileManager/NSerializer.h
source_character_h = \
Character/NUTF.h \
Character/NUni.h \
Character/NUnicode.h \
Character/NTChar.h
source_math_h = \
Math/Algo.h \
Math/Bezier.h \
Math/Constants.h \
Math/Point3D.h \
Math/Vector4.h \
Math/Matrix2.h \
Math/Spline.h \
Math/Vector3.h \
Math/MathFunctions.h \
Math/Quaternion.h \
Math/Trigonometry.h \
Math/Line3D.h \
Math/MathInc.h \
Math/Complex.h \
Math/Matrix3.h \
Math/Vector2.h \
Math/Line2D.h \
Math/Point2D.h \
Math/Point2D-inl.h \
Math/Tweening.h \
Math/Matrix4.h \
Math/MathUtility.h
source_h = \
Animation.h \
Animation-inl.h \
AnimationController.h \
AsyncFileWriter.h \
EasingCurve.h \
Point.h \
FilePath.h \
System.h \
Parsing.h \
StringConversion.h \
GlobalInitializer.h \
Rect.h \
Platform.h \
Inalogic.h \
Color.h \
Colors.h \
Logger.h \
LoggerPrivate.h \
LoggingWriter.h \
RollingFileAppender.h \
Memory.h \
Error.h \
SystemGNU.h \
NuxCore.h \
FileName.h \
OutputDevice.h \
Process.h \
ObjectType.h \
ObjectPtr.h \
NumberConversion.h \
Object.h \
Size.h \
Size-inl.h \
Exception.h \
TimeFunctions.h \
Macros.h \
ThreadGNU.h \
TextString.h \
Template.h \
NUniqueIndex.h \
FileIO.h \
InitiallyUnownedObject.h \
Property.h \
Property-inl.h \
PropertyAnimation.h \
PropertyOperators.h \
PropertyTraits.h \
Win32Dialogs/NWin32Clipboard.h
libnux_core_@NUX_API_VERSION@_la_SOURCES = \
$(source_cpp) \
$(source_h) \
$(source_character_h) \
$(source_file_manager_h) \
$(source_math_h) \
$(source_memory_h)
nux_coredir = $(includedir)/Nux-@NUX_API_VERSION@/NuxCore
nux_core_HEADERS = $(source_h)
nux_chardir = $(nux_coredir)/Character
nux_char_HEADERS = $(source_character_h)
nux_file_managerdir = $(nux_coredir)/FileManager
nux_file_manager_HEADERS = $(source_file_manager_h)
nux_mathdir = $(nux_coredir)/Math
nux_math_HEADERS = $(source_math_h)
nux_memorydir = $(nux_coredir)/Memory
nux_memory_HEADERS = $(source_memory_h)
# pkg-config file
nux-core-@NUX_API_VERSION@.pc: nux-core.pc
$(AM_V_GEN) cp -f nux-core.pc nux-core-@NUX_API_VERSION@.pc
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = nux-core-@NUX_API_VERSION@.pc
unused_src = \
Character/NAscii.cpp \
Character/NAscii.h \
Character/NUnicodeGNU.cpp \
Character/NUnicodeGNU.h \
CppReadme.txt \
FileManager/NFileManagerWindows.cpp \
FileManager/NFileManagerWindows.h \
Plugin/NPlugin.h \
Plugin/NPluginInterface.h \
Plugin/NPluginManager.cpp \
Plugin/NPluginManager.h \
Plugin/NPluging.cpp \
SystemWindows.cpp \
SystemWindows.h \
ThreadWin.cpp \
ThreadWin.h \
Win32Dialogs/NWin32Clipboard.cpp \
Win32Dialogs/NWin32CustomDialog.cpp \
Win32Dialogs/NWin32CustomDialog.h \
Win32Dialogs/NWin32MessageBox.cpp \
Win32Dialogs/NWin32MessageBox.h
CLEANFILES += nux-core-@NUX_API_VERSION@.pc
DISTCLEANFILES += nux-core.pc
EXTRA_DIST += nux-core.pc.in ${unused_src}
nux-4.0.8+16.04.20160209/NuxCore/GlobalInitializer.h 0000644 0000156 0000165 00000010202 12656236757 022057 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NGLOBALINITIALIZER_H
#define NGLOBALINITIALIZER_H
#include "Macros.h"
#include "System.h"
#ifdef _WIN32
#define NUX_GLOBAL_OBJECT_INIT_SEQUENCE() \
NUX_GLOBAL_OBJECT_VARIABLE(NGlobalData); \
NUX_GLOBAL_OBJECT_VARIABLE(NProcess); \
NUX_GLOBAL_OBJECT_VARIABLE(NullOutput); \
NUX_GLOBAL_OBJECT_VARIABLE(UniqueIndex); \
NUX_GLOBAL_OBJECT_VARIABLE(NFileManagerWindows); \
NUX_GLOBAL_OBJECT_VARIABLE(VisualOutputConsole); \
NUX_GLOBAL_OBJECT_VARIABLE(PrintfOutputConsole); \
NUX_GLOBAL_OBJECT_VARIABLE(LogFileOutput); \
NUX_GLOBAL_OBJECT_VARIABLE(LogOutputRedirector); \
NUX_GLOBAL_OBJECT_VARIABLE(ObjectStats);
#elif (defined NUX_OS_LINUX)
#define NUX_GLOBAL_OBJECT_INIT_SEQUENCE() \
NUX_GLOBAL_OBJECT_VARIABLE(NGlobalData); \
NUX_GLOBAL_OBJECT_VARIABLE(NullOutput); \
NUX_GLOBAL_OBJECT_VARIABLE(UniqueIndex); \
NUX_GLOBAL_OBJECT_VARIABLE(NFileManagerGNU); \
NUX_GLOBAL_OBJECT_VARIABLE(PrintfOutputConsole); \
NUX_GLOBAL_OBJECT_VARIABLE(LogFileOutput); \
NUX_GLOBAL_OBJECT_VARIABLE(LogOutputRedirector); \
NUX_GLOBAL_OBJECT_VARIABLE(ObjectStats);
#endif
namespace nux
{
// This class initialize all inalogic singleton (global objects) in order. It also initialize memory allocators.
// Therefore, do not call new GlobalSingletonInitializer as it will try to call inalogic memory allocator and fail.
// You may use the global placement new operator(it is not overwritten by inalogic) to create GlobalSingletonInitializer
// inside the application data space by calling SystemInitializer(). At shutdown, call SystemShutdown()
//
// You may also create GlobalSingletonInitializer in this way:
// main()
// {
// GlobalSingletonInitializer GlobalInitializer;
// }
//
//
class GlobalSingletonInitializer
{
NUX_DISABLE_OBJECT_COPY (GlobalSingletonInitializer);
GlobalSingletonInitializer *operator & ();
const GlobalSingletonInitializer *operator & () const;
public:
GlobalSingletonInitializer();
~GlobalSingletonInitializer();
static bool Ready();
private:
static bool m_bGlobalObjectsReady;
NUX_GLOBAL_OBJECT_INIT_SEQUENCE();
};
// Nifty Counter idiom. See http://www-d0.fnal.gov/KAI/doc/tutorials/static_initialization.html
class GlobalInitializer
{
public:
GlobalInitializer();
~GlobalInitializer();
static void ForceShutdown();
private:
static int m_Count;
};
// Every compilation unit that includes this file will have its own instance of sGlobalInitializer. sGlobalInitializer is initialized
// before the main function of the program is called. The first time sGlobalInitializer is initialized, it calls SystemStart() to create
// our global object singleton. In SystemStart() we have a change to create our singletons in any order we like.
// When the program exits, every instance of sGlobalInitializer will be destroyed. The last instance destroyed will call SystemShutdown().
// In SystemShutdown() we can destroy our global objects in any order we like.
static GlobalInitializer sGlobalInitializer;
}
#endif // NGLOBALINITIALIZER_H
nux-4.0.8+16.04.20160209/NuxCore/FileIO.h 0000644 0000156 0000165 00000003152 12656236757 017570 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NFILE_H
#define NFILE_H
#include
#include
namespace nux
{
bool LoadFileToArray ( std::vector& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
bool LoadTextFileToAnsiArray ( std::vector& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
bool LoadTextFileToUnicodeArray ( std::vector& Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
bool LoadFileToString(std::string &Result, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
bool SaveArrayToFile(const std::vector& Array, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
bool SaveStringToFile(const std::string &String, const TCHAR *Filename, NFileManager &FileManager = GFileManager );
}
#endif // NFILE_H
nux-4.0.8+16.04.20160209/NuxCore/ThreadGNU.h 0000644 0000156 0000165 00000033326 12656236757 020250 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2010 Inalogic® Inc.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 or 3.0
* of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the applicable version of the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of both the GNU Lesser General Public
* License along with this program. If not, see
*
* Authored by: Jay Taoko
*
*/
#ifndef NTHREADGNU_H
#define NTHREADGNU_H
#include "ObjectType.h"
/*#include
#include
#include
#include