Skip to content

Commit

Permalink
linux: clsid.cpp builds. _std_extensions.h updated from Kaffeine/xray…
Browse files Browse the repository at this point in the history
…-16. CXX flag replaced to std=c++17
  • Loading branch information
q4a committed May 19, 2018
1 parent 45bf650 commit ae72922
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 67 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(OpenXRay)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++17")

add_definitions(-D_MT -D_CPPUNWIND -DPURE_DYNAMIC_CAST -DDECLARE_SPECIALIZATION -DM_NOSTDCONTAINERS_EXT -DUSE_OGL)

Expand Down
1 change: 1 addition & 0 deletions Externals/cximage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(HEADERS
xmemfile.h
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive --std=c++14")
add_definitions(-DCXIMAGE_BUILD)

include_directories("." ${CMAKE_SOURCE_DIR})
Expand Down
7 changes: 5 additions & 2 deletions src/xrCore/LocatorAPI.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

#ifdef WINDOWS
#pragma warning(push)
#pragma warning(disable : 4995)
#ifdef WINDOWS
#include <io.h>
#pragma warning(pop)
#else
#define _finddata_t _finddata64i32_t
#endif
#pragma warning(pop)


#include "Common/Util.hpp"
#include "LocatorAPI_defs.h"
Expand Down
235 changes: 173 additions & 62 deletions src/xrCore/_std_extensions.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once
#ifndef _STD_EXT_internal
#define _STD_EXT_internal

#include <math.h>
#include <float.h>
#include <stdio.h>
#include "xrCommon/math_funcs_inline.h"
//#include "xr_token.h"
#include <cmath>

#define BREAK_AT_STRCMP
#ifndef DEBUG
#undef BREAK_AT_STRCMP
#endif
#ifdef _EDITOR
#undef BREAK_AT_STRCMP
#endif

#ifdef abs
#undef abs
Expand All @@ -28,7 +31,46 @@
#undef max
#endif

#if 0//def _EDITOR
#include <cmath>

#include <stdio.h>
#include <string.h>

#ifndef __WIN32
#define stricmp strcasecmp
#define strnicmp strncasecmp

inline char *itoa(int value, char *str, int base)
{
switch (base) {
case 8:
sprintf(str, "%o", value);
break;
default:
case 10:
sprintf(str, "%d", value);
break;
case 16:
sprintf(str, "%x", value);
break;
}
return str;
}

inline int wcstombs_s(size_t *outsize, char *mbstr, size_t inbytes, const wchar_t *wcstr, size_t max)
{
*outsize = wcstombs(mbstr, wcstr, max);
return 0;
}

inline int mbstowcs_s(size_t *outsize, wchar_t *wcstr, size_t inwords, const char *mbstr, size_t max)
{
*outsize = mbstowcs(wcstr, mbstr, max);
return 0;
}
#endif

#ifdef _EDITOR
IC char* strncpy_s(char* strDestination, size_t sizeInBytes, const char* strSource, size_t count)
{
return strncpy(strDestination, strSource, count);
Expand All @@ -39,14 +81,26 @@ IC char* xr_strcpy(char* strDestination, size_t sizeInBytes, const char* strSour
return strcpy(strDestination, strSource);
}

IC char* xr_strcpy(char* strDestination, const char* strSource) { return strcpy(strDestination, strSource); }
IC char* _strlwr_s(char* strDestination, size_t sizeInBytes) { return xr_strlwr(strDestination); }
IC char* xr_strcpy(char* strDestination, const char* strSource)
{
return strcpy(strDestination, strSource);
}

IC char* _strlwr_s(char* strDestination, size_t sizeInBytes)
{
return strlwr(strDestination);
}

IC char* xr_strcat(char* strDestination, size_t sizeInBytes, const char* strSource)
{
return strncat(strDestination, strSource, sizeInBytes);
}

IC char* xr_strcat(char* strDestination, const char* strSource) { return strcat(strDestination, strSource); }
IC char* xr_strcat(char* strDestination, const char* strSource)
{
return strcat(strDestination, strSource);
}

IC int xr_sprintf(char* dest, size_t sizeOfBuffer, const char* format, ...)
{
va_list mark;
Expand All @@ -56,89 +110,133 @@ IC int xr_sprintf(char* dest, size_t sizeOfBuffer, const char* format, ...)
va_end(mark);
return sz;
}
#endif // _EDITOR
#endif

// generic
template <class T>
IC T _min(T a, T b)
// token type definition
struct XRCORE_API xr_token
{
return a < b ? a : b;
}
template <class T>
IC T _max(T a, T b)
LPCSTR name;
int id;
};

IC LPCSTR get_token_name(xr_token* tokens, int key)
{
return a > b ? a : b;
for (int k = 0; tokens[k].name; k++)
if (key == tokens[k].id) return tokens[k].name;
return "";
}
template <class T>
IC T _sqr(T a)

IC int get_token_id(xr_token* tokens, LPCSTR key)
{
return a * a;
for (int k = 0; tokens[k].name; k++)
if (stricmp(tokens[k].name, key) == 0)
return tokens[k].id;
return -1;
}

IC bool _valid(const float x) noexcept
struct XRCORE_API xr_token2
{
// check for: Signaling NaN, Quiet NaN, Negative infinity ( –INF), Positive infinity (+INF), Negative denormalized,
// Positive denormalized
int cls = _fpclass(double(x));
if (cls & (_FPCLASS_SNAN + _FPCLASS_QNAN + _FPCLASS_NINF + _FPCLASS_PINF + _FPCLASS_ND + _FPCLASS_PD))
return false;
LPCSTR name;
LPCSTR info;
int id;
};

/* *****other cases are*****
_FPCLASS_NN Negative normalized non-zero
_FPCLASS_NZ Negative zero ( – 0)
_FPCLASS_PZ Positive 0 (+0)
_FPCLASS_PN Positive normalized non-zero
*/
return true;
// generic
template <class T> IC T _min(T a, T b) { return a < b ? a : b; }
template <class T> IC T _max(T a, T b) { return a > b ? a : b; }
template <class T> IC T _sqr(T a) { return a*a; }

// float
IC float _abs(float x) { return fabsf(x); }
IC float _sqrt(float x) { return sqrtf(x); }
IC float _sin(float x) { return sinf(x); }
IC float _cos(float x) { return cosf(x); }
IC BOOL _valid(const float x)
{
return std::isnormal(x);
}


// double
IC bool _valid(const double x)
IC double _abs(double x) { return fabs(x); }
IC double _sqrt(double x) { return sqrt(x); }
IC double _sin(double x) { return sin(x); }
IC double _cos(double x) { return cos(x); }
IC BOOL _valid(const double x)
{
// check for: Signaling NaN, Quiet NaN, Negative infinity ( –INF), Positive infinity (+INF), Negative denormalized,
// Positive denormalized
int cls = _fpclass(x);
if (cls & (_FPCLASS_SNAN + _FPCLASS_QNAN + _FPCLASS_NINF + _FPCLASS_PINF + _FPCLASS_ND + _FPCLASS_PD))
return false;

/* *****other cases are*****
_FPCLASS_NN Negative normalized non-zero
_FPCLASS_NZ Negative zero ( – 0)
_FPCLASS_PZ Positive 0 (+0)
_FPCLASS_PN Positive normalized non-zero
*/
return true;
return std::isnormal(x);
}

// XXX: "magic" specializations, that really require profiling to see if they are worth this effort.
// int8
IC s8 _abs(s8 x) { return (x >= 0) ? x : s8(-x); }
IC s8 _min(s8 x, s8 y) { return y + ((x - y) & ((x - y) >> (sizeof(s8) * 8 - 1))); };
IC s8 _max(s8 x, s8 y) { return x - ((x - y) & ((x - y) >> (sizeof(s8) * 8 - 1))); };

// unsigned int8
IC u8 _abs(u8 x) { return x; }

// int16
IC s16 _abs(s16 x) { return (x >= 0) ? x : s16(-x); }
IC s16 _min(s16 x, s16 y) { return y + ((x - y) & ((x - y) >> (sizeof(s16) * 8 - 1))); };
IC s16 _max(s16 x, s16 y) { return x - ((x - y) & ((x - y) >> (sizeof(s16) * 8 - 1))); };

// unsigned int16
IC u16 _abs(u16 x) { return x; }

// int32
IC s32 _abs(s32 x) { return (x >= 0) ? x : s32(-x); }
IC s32 _min(s32 x, s32 y) { return y + ((x - y) & ((x - y) >> (sizeof(s32) * 8 - 1))); };
IC s32 _max(s32 x, s32 y) { return x - ((x - y) & ((x - y) >> (sizeof(s32) * 8 - 1))); };

// int64
IC s64 _abs(s64 x) { return (x >= 0) ? x : s64(-x); }
IC s64 _min(s64 x, s64 y) { return y + ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); };
IC s64 _max(s64 x, s64 y) { return x - ((x - y) & ((x - y) >> (sizeof(s64) * 8 - 1))); };

IC u32 xr_strlen(const char* S);

// string management

// return pointer to ".ext"
IC char* strext(const char* S) { return (char*)strrchr(S, '.'); }
IC size_t xr_strlen(const char* S) { return strlen(S); }
IC char* strext(const char* S)
{
return (char*)strrchr(S, '.');
}

//#ifndef _EDITOR
IC u32 xr_strlen(const char* S)
{
return (u32)strlen(S);
}

IC char* xr_strupr(char* S)
{
#ifdef _WIN32
return _strupr(S);
#else
char *p = S;
for ( ; *S; ++S)
{
*S = toupper(*S);
}
return p;
#endif
}

IC char* xr_strlwr(char* S)
{
#ifdef _WIN32
return strlwr(S);
#else
char *p = S;
for ( ; *S; ++S)
{
*S = tolower(*S);
}
return p;
#endif
}

#ifndef _EDITOR
#ifndef MASTER_GOLD

inline int xr_strcpy(LPSTR destination, size_t const destination_size, LPCSTR source)
Expand All @@ -159,7 +257,7 @@ inline int __cdecl xr_sprintf(LPSTR destination, size_t const buffer_size, LPCST
}

template <int count>
inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string, ...)
inline int __cdecl xr_sprintf(char(&destination)[count], LPCSTR format_string, ...)
{
va_list args;
va_start(args, format_string);
Expand All @@ -169,7 +267,12 @@ inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string,

inline int xr_strcpy(LPSTR destination, size_t const destination_size, LPCSTR source)
{
#ifdef _WIN32
return strncpy_s(destination, destination_size, source, destination_size);
#else
strncpy(destination, source, destination_size);
return 0;
#endif
}

inline int xr_strcat(LPSTR destination, size_t const buffer_size, LPCSTR source)
Expand All @@ -191,36 +294,44 @@ inline int __cdecl xr_sprintf(LPSTR destination, size_t const buffer_size, LPCST
{
va_list args;
va_start(args, format_string);
#ifdef _WIN32
return vsnprintf_s(destination, buffer_size, buffer_size - 1, format_string, args);
#else
return vsnprintf(destination, buffer_size, format_string, args);
#endif
}

template <int count>
inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string, ...)
inline int __cdecl xr_sprintf(char(&destination)[count], LPCSTR format_string, ...)
{
va_list args;
va_start(args, format_string);
#ifdef _WIN32
return vsnprintf_s(destination, count, count - 1, format_string, args);
#else
return vsnprintf(destination, count, format_string, args);
#endif
}
#endif // #ifndef MASTER_GOLD

template <int count>
inline int xr_strcpy(char (&destination)[count], LPCSTR source)
inline int xr_strcpy(char(&destination)[count], LPCSTR source)
{
return xr_strcpy(destination, count, source);
}

template <int count>
inline int xr_strcat(char (&destination)[count], LPCSTR source)
inline int xr_strcat(char(&destination)[count], LPCSTR source)
{
return xr_strcat(destination, count, source);
}
//#endif // #ifndef _EDITOR
#endif // #ifndef _EDITOR

inline void MemFill32(void* dst, u32 value, size_t dstSize)
inline void MemFill32(void *dst, u32 value, size_t dstSize)
{
u32* ptr = static_cast<u32*>(dst);
u32* end = ptr + dstSize;
while (ptr != end)
u32 *ptr = static_cast<u32 *>(dst);
u32 *end = ptr+dstSize;
while (ptr!=end)
*ptr++ = value;
}

Expand Down
2 changes: 0 additions & 2 deletions src/xrCore/xrCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
#endif // frequently in release code due to large amount of VERIFY

// Our headers
#ifdef WINDOWS
#include "xrDebug.h"
#endif
//#include "vector.h"

#include "clsid.h"
Expand Down
Loading

0 comments on commit ae72922

Please sign in to comment.