|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef T_COMMON_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define T_COMMON_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
e280ae |
#ifdef _MSC_VER
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4786)
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4251)
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4146)
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4267)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#undef _STLP_DEBUG
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define _STLP_DEBUG 1
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#if defined(NDEBUG) && defined(VERIFY_TNZCORE)
|
|
Toshihiro Shimizu |
890ddd |
#undef NDEBUG
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
#define NDEBUG
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <string></string>
|
|
Toshihiro Shimizu |
890ddd |
#include <iostream></iostream>
|
|
Toshihiro Shimizu |
890ddd |
#include <fstream></fstream>
|
|
Toshihiro Shimizu |
890ddd |
#include <algorithm></algorithm>
|
|
Toshihiro Shimizu |
890ddd |
#include <limits></limits>
|
|
otakuto |
ed7dcd |
#include <utility></utility>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if 0 && defined(__GNUC__)
|
|
Toshihiro Shimizu |
890ddd |
// typedef seems strong on GCC and breaks code with TException..
|
|
Shinya Kitaoka |
3bfa54 |
#define TString std::wstring
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
3bfa54 |
typedef std::wstring TString;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// STL
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
* On Irix stl_alloc.h refers to nanosleep and timespec
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef __sgi
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
#if (_MIPS_SZLONG == 32)
|
|
Toshihiro Shimizu |
890ddd |
struct timespec {TLong tv_sec; TLong tv_nsec;};
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
struct timespec {int tv_sec; TLong tv_nsec;};
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef __cplusplus
|
|
Shinya Kitaoka |
120a6e |
extern "C"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
int nanosleep(struct timespec *, int);
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <list></list>
|
|
Toshihiro Shimizu |
890ddd |
#include <vector></vector>
|
|
Toshihiro Shimizu |
890ddd |
#include <map></map>
|
|
shun-iwasawa |
481b59 |
#include <cmath></cmath>
|
|
Toshihiro Shimizu |
890ddd |
// .. and so on
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace TConsts {
|
|
Toshihiro Shimizu |
890ddd |
const double epsilon = 1e-8;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
luz paz |
6454c4 |
// use macros instead of constexprs, because MSVC2013 does not support
|
|
Shinya Kitaoka |
120a6e |
// `constexpr`.
|
|
Shinya Kitaoka |
ee259f |
#define M_PI_3 (M_PI / 3)
|
|
Shinya Kitaoka |
ee259f |
#define M_PI_180 (M_PI_4 / 45)
|
|
Shinya Kitaoka |
ee259f |
#define M_180_PI (90 * M_2_PI)
|
|
Shinya Kitaoka |
ee259f |
#define M_2PI (2 * M_PI)
|
|
Shinya Kitaoka |
ee259f |
|
|
Toshihiro Shimizu |
890ddd |
// typedef's
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tnztypes.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef signed char SCHAR;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned char UCHAR;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned short USHORT;
|
|
Toshihiro Shimizu |
890ddd |
typedef short SHORT;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned int UINT;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifndef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned char BYTE;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline T tcrop(T x, T a, T b) {
|
|
Shinya Kitaoka |
120a6e |
return std::min(std::max(x, a), b);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline void notLessThan(T threshold, T &x) {
|
|
Shinya Kitaoka |
120a6e |
if (x < threshold) x = threshold;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Shinya Kitaoka |
120a6e |
inline void notMoreThan(T threshold, T &x) {
|
|
Shinya Kitaoka |
120a6e |
if (x > threshold) x = threshold;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*! round(x) returns the nearest integer to x.
|
|
Toshihiro Shimizu |
890ddd |
Works well for x<0, but is slower than roundp()
|
|
Toshihiro Shimizu |
890ddd |
/sa roundp() */
|
|
Shinya Kitaoka |
120a6e |
inline int tround(double x) {
|
|
Shinya Kitaoka |
120a6e |
return ((int)(((int)(-0.9) == 0 && x < 0.0) ? (x - 0.5) : (x + 0.5)));
|
|
Shinya Kitaoka |
120a6e |
// return ((int)(((int)(-0.9F) == 0 && x<0.0F) ? (x - 0.5F) : (x + 0.5F)));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*! roundp(x) is like round(x), but the result if x<0 is
|
|
Shinya Kitaoka |
120a6e |
platform dependent
|
|
Shinya Kitaoka |
120a6e |
/sa round() */
|
|
Shinya Kitaoka |
120a6e |
inline int troundp(double x) { return ((int)((x) + 0.5F)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! byteFromUshort(u) converts integer from [0..65535] to [0..255] */
|
|
Shinya Kitaoka |
120a6e |
inline UCHAR byteFromUshort(USHORT u) {
|
|
Shinya Kitaoka |
120a6e |
return ((256U * 255U + 1U) * u + (1 << 23)) >> 24;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
481b59 |
/*! from[0. .. 1.] to [0..255] */
|
|
shun-iwasawa |
481b59 |
inline UCHAR byteFromFloat(float f) {
|
|
shun-iwasawa |
481b59 |
return (f >= 1.f) ? 0xFF : (f <= 0.f) ? 0 : (UCHAR)(std::floor(f * 256.f));
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
481b59 |
|
|
Toshihiro Shimizu |
890ddd |
/*! ditheredByteFromUshort(u) is like byteFromUshort().
|
|
Shinya Kitaoka |
120a6e |
It is used in dithering ...
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline UCHAR ditheredByteFromUshort(USHORT u, int r) {
|
|
Shinya Kitaoka |
120a6e |
return ((((u * (256U * 255U + 1U)) - ((u * (256U * 255U + 1U)) >> 24)) + r) >>
|
|
Shinya Kitaoka |
120a6e |
24);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! ushortFromByte(u) converts integer from [0..255] to [0..65535]*/
|
|
Shinya Kitaoka |
120a6e |
inline USHORT ushortFromByte(UCHAR u) { return u | u << 8; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const int c_maxint = ((int)((~0U) >> 1));
|
|
Toshihiro Shimizu |
890ddd |
const int c_minint = ~c_maxint;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const unsigned int c_maxuint = (unsigned int)(~0U);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#define DV_EXPORT_API __declspec(dllexport)
|
|
Toshihiro Shimizu |
890ddd |
#define DV_IMPORT_API __declspec(dllimport)
|
|
Toshihiro Shimizu |
890ddd |
#define DV_EXPORT_VAR __declspec(dllexport)
|
|
Toshihiro Shimizu |
890ddd |
#define DV_IMPORT_VAR __declspec(dllimport)
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#define DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
2f0c77 |
#ifdef _MSC_VER
|
|
|
2f0c77 |
#define DV_ALIGNED(val) __declspec(align(val))
|
|
|
2f0c77 |
#else
|
|
|
2f0c77 |
#define DV_ALIGNED(val) __attribute__((aligned(val)))
|
|
|
2f0c77 |
#endif
|
|
|
2f0c77 |
|
|
Shinya Kitaoka |
120a6e |
inline short swapShort(short val) { return ((val >> 8) & 0x00ff) | (val << 8); }
|
|
Shinya Kitaoka |
120a6e |
inline TINT32 swapTINT32(TINT32 val) {
|
|
Shinya Kitaoka |
120a6e |
TINT32 appo, aux, aux1;
|
|
Shinya Kitaoka |
120a6e |
appo = 0xff0000ff;
|
|
Shinya Kitaoka |
120a6e |
aux = (val & appo);
|
|
Shinya Kitaoka |
120a6e |
aux1 = (aux >> 24) & 0x000000ff;
|
|
Shinya Kitaoka |
120a6e |
aux = (aux << 24) | aux1;
|
|
Shinya Kitaoka |
120a6e |
appo = 0x00ffff00;
|
|
Shinya Kitaoka |
120a6e |
aux1 = (val & appo);
|
|
Shinya Kitaoka |
120a6e |
aux1 = ((aux1 >> 8) | (aux1 << 8)) & appo;
|
|
Shinya Kitaoka |
120a6e |
aux = (aux | aux1);
|
|
Shinya Kitaoka |
120a6e |
return aux;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
inline USHORT swapUshort(USHORT val) { return val >> 8 | val << 8; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
inline std::ostream &operator<<(std::ostream &out, const std::string &s) {
|
|
Shinya Kitaoka |
120a6e |
return out << s.c_str();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
160579 |
const std::string styleNameEasyInputWordsFileName = "stylename_easyinput.ini";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif //__T_COMMON_INCLUDED
|