|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef T_COMMON_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define T_COMMON_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
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>
|
|
kogaki |
5bbc3c |
#include <strstream></strstream>
|
|
Toshihiro Shimizu |
890ddd |
#include <iostream></iostream>
|
|
Toshihiro Shimizu |
890ddd |
#include <fstream></fstream>
|
|
Toshihiro Shimizu |
890ddd |
#include <algorithm></algorithm>
|
|
Toshihiro Shimizu |
890ddd |
#include <limits></limits>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using std::string;
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
#if defined(MACOSX)
|
|
Toshihiro Shimizu |
890ddd |
#warning "using dummy wstring class"
|
|
Toshihiro Shimizu |
890ddd |
class wstring {
|
|
Toshihiro Shimizu |
890ddd |
string m_str;
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
typedef int size_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef wchar_t* iterator;
|
|
Toshihiro Shimizu |
890ddd |
static const size_type npos = static_cast<size_type>(-1);</size_type>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
wstring() {}
|
|
Toshihiro Shimizu |
890ddd |
wstring(const wchar_t*wstr) { m_str=reinterpret_cast<const char*="">(wstr); }</const>
|
|
Toshihiro Shimizu |
890ddd |
wstring(const wchar_t*wstr, int len) { m_str.assign(reinterpret_cast<const char*="">(wstr), len*sizeof(wchar_t)); }</const>
|
|
Toshihiro Shimizu |
890ddd |
//wstring(const char*str) { m_str = str; }
|
|
Toshihiro Shimizu |
890ddd |
int length() const {return m_str.length()/sizeof(wchar_t); }
|
|
Toshihiro Shimizu |
890ddd |
int size() const {return m_str.size()/sizeof(wchar_t); }
|
|
Toshihiro Shimizu |
890ddd |
wstring substr(size_type pos, size_type n = npos) {
|
|
Toshihiro Shimizu |
890ddd |
size_type _n = (n==npos)? npos : n*sizeof(wchar_t);
|
|
Toshihiro Shimizu |
890ddd |
wstring ret;
|
|
Toshihiro Shimizu |
890ddd |
ret.m_str = m_str.substr(pos*sizeof(wchar_t), _n);
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//iterator begin() { return }
|
|
Toshihiro Shimizu |
890ddd |
const wchar_t* c_str() { return reinterpret_cast<const wchar_t*="">(m_str.c_str()); }</const>
|
|
Toshihiro Shimizu |
890ddd |
wstring& operator=(const wstring& w) { m_str = w.m_str; return *this; }
|
|
Toshihiro Shimizu |
890ddd |
bool operator !=(const wchar_t* wstr) const { const char* str = reinterpret_cast<const char*="">(wstr); return m_str != str; }</const>
|
|
Toshihiro Shimizu |
890ddd |
bool operator ==(const wchar_t* wstr) const { const char* str = reinterpret_cast<const char*="">(wstr); return m_str == str; }</const>
|
|
Toshihiro Shimizu |
890ddd |
bool operator ==(const wstring& wstr) const { return m_str == wstr.m_str; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
using std::wstring;
|
|
Toshihiro Shimizu |
890ddd |
//#endif
|
|
Toshihiro Shimizu |
890ddd |
using std::ostream;
|
|
Toshihiro Shimizu |
890ddd |
using std::istream;
|
|
Toshihiro Shimizu |
890ddd |
using std::iostream;
|
|
kogaki |
5bbc3c |
using std::ostrstream;
|
|
kogaki |
5bbc3c |
using std::istrstream;
|
|
Toshihiro Shimizu |
890ddd |
using std::fstream;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if 0 && defined(__GNUC__)
|
|
Toshihiro Shimizu |
890ddd |
// typedef seems strong on GCC and breaks code with TException..
|
|
Toshihiro Shimizu |
890ddd |
#define TString wstring
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
typedef wstring TString;
|
|
Toshihiro Shimizu |
890ddd |
//typedef string 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
|
|
Toshihiro Shimizu |
890ddd |
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>
|
|
Toshihiro Shimizu |
890ddd |
// .. and so on
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// idem
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using std::list;
|
|
Toshihiro Shimizu |
890ddd |
using std::vector;
|
|
Toshihiro Shimizu |
890ddd |
using std::string;
|
|
Toshihiro Shimizu |
890ddd |
using std::map;
|
|
Toshihiro Shimizu |
890ddd |
using std::pair;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* the value of pi defined in IRIX-math.h is not defined neither in WIN32-math.h nor elsewhere */
|
|
Toshihiro Shimizu |
890ddd |
namespace TConsts
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const double pi = 3.1415926535897932384626433832795;
|
|
Toshihiro Shimizu |
890ddd |
const double pi_2 = 1.5707963267948966192313216916398;
|
|
Toshihiro Shimizu |
890ddd |
const double epsilon = 1e-8;
|
|
Toshihiro Shimizu |
890ddd |
const double sqrt2 = 1.4142135623730950488016887242097;
|
|
Toshihiro Shimizu |
890ddd |
const double sqrt2_2 = 0.7071067811865475244008443621048;
|
|
Toshihiro Shimizu |
890ddd |
const double pi_180 = pi / 180.0;
|
|
Toshihiro Shimizu |
890ddd |
const double invOf_pi_180 = 180.0 / pi;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef WIN32
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned char BYTE;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tmin(T a, T b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return a < b ? a : b;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tmax(T a, T b) { return a > b ? a : b; }
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tmin(T a, T b, T c) { return tmin(tmin(a, b), c); }
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tmax(T a, T b, T c) { return tmax(tmax(a, b), c); }
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tmin(T a, T b, T c, T d) { return tmin(tmin(a, b), tmin(c, d)); }
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tmax(T a, T b, T c, T d) { return tmax(tmax(a, b), tmax(c, d)); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline void tswap(T &a, T &b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
T tmp = a;
|
|
Toshihiro Shimizu |
890ddd |
a = b;
|
|
Toshihiro Shimizu |
890ddd |
b = tmp;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline T tcrop(T x, T a, T b) { return tmin(tmax(x, a), b); }
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline void notLessThan(T threshold, T &x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (x < threshold)
|
|
Toshihiro Shimizu |
890ddd |
x = threshold;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
template <class t=""></class>
|
|
Toshihiro Shimizu |
890ddd |
inline void notMoreThan(T threshold, T &x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (x > threshold)
|
|
Toshihiro Shimizu |
890ddd |
x = threshold;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! 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() */
|
|
Toshihiro Shimizu |
890ddd |
inline int tround(double x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((int)(((int)(-0.9) == 0 && x < 0.0) ? (x - 0.5) : (x + 0.5)));
|
|
Toshihiro Shimizu |
890ddd |
//return ((int)(((int)(-0.9F) == 0 && x<0.0F) ? (x - 0.5F) : (x + 0.5F)));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! roundp(x) is like round(x), but the result if x<0 is
|
|
Toshihiro Shimizu |
890ddd |
platform dependent
|
|
Toshihiro Shimizu |
890ddd |
/sa round() */
|
|
Toshihiro Shimizu |
890ddd |
inline int troundp(double x)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((int)((x) + 0.5F));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* li metto dopo
|
|
Toshihiro Shimizu |
890ddd |
equivalenti a (int)floor() e (int)ceil() (ma piu' veloci)
|
|
Toshihiro Shimizu |
890ddd |
solo se la risoluzione dell'argomento e' inferiore ad 1
|
|
Toshihiro Shimizu |
890ddd |
#define FLOOR(x) ((int)(x) > (x) ? (int)(x)-1 : (int)(x))
|
|
Toshihiro Shimizu |
890ddd |
#define CEIL(x) ((int)(x) < (x) ? (int)(x)+1 : (int)(x))
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! byteFromUshort(u) converts integer from [0..65535] to [0..255] */
|
|
Toshihiro Shimizu |
890ddd |
inline UCHAR byteFromUshort(USHORT u)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((256U * 255U + 1U) * u + (1 << 23)) >> 24;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! ditheredByteFromUshort(u) is like byteFromUshort().
|
|
Toshihiro Shimizu |
890ddd |
It is used in dithering ...
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline UCHAR ditheredByteFromUshort(USHORT u, int r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((((u * (256U * 255U + 1U)) -
|
|
Toshihiro Shimizu |
890ddd |
((u * (256U * 255U + 1U)) >> 24)) +
|
|
Toshihiro Shimizu |
890ddd |
r) >>
|
|
Toshihiro Shimizu |
890ddd |
24);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! ushortFromByte(u) converts integer from [0..255] to [0..65535]*/
|
|
Toshihiro Shimizu |
890ddd |
inline USHORT ushortFromByte(UCHAR u)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return u | u << 8;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
#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 |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#define DV_ALIGNED(val) __declspec(align(val))
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DV_ALIGNED(val) __attribute__((aligned(val)))
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define CASE \
|
|
Toshihiro Shimizu |
890ddd |
break; \
|
|
Toshihiro Shimizu |
890ddd |
case
|
|
Toshihiro Shimizu |
890ddd |
#define __OR case
|
|
Toshihiro Shimizu |
890ddd |
#define DEFAULT \
|
|
Toshihiro Shimizu |
890ddd |
break; \
|
|
Toshihiro Shimizu |
890ddd |
default
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline short swapShort(short val)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return ((val >> 8) & 0x00ff) | (val << 8);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
inline TINT32 swapTINT32(TINT32 val)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TINT32 appo, aux, aux1;
|
|
Toshihiro Shimizu |
890ddd |
appo = 0xff0000ff;
|
|
Toshihiro Shimizu |
890ddd |
aux = (val & appo);
|
|
Toshihiro Shimizu |
890ddd |
aux1 = (aux >> 24) & 0x000000ff;
|
|
Toshihiro Shimizu |
890ddd |
aux = (aux << 24) | aux1;
|
|
Toshihiro Shimizu |
890ddd |
appo = 0x00ffff00;
|
|
Toshihiro Shimizu |
890ddd |
aux1 = (val & appo);
|
|
Toshihiro Shimizu |
890ddd |
aux1 = ((aux1 >> 8) | (aux1 << 8)) & appo;
|
|
Toshihiro Shimizu |
890ddd |
aux = (aux | aux1);
|
|
Toshihiro Shimizu |
890ddd |
return aux;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
inline USHORT swapUshort(USHORT val) { return val >> 8 | val << 8; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
inline ostream &operator<<(ostream &out, const string &s)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << s.c_str();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define tArrayCount(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const string mySettingsFileName = "mysettings.ini";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif //__T_COMMON_INCLUDED
|