gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

pport.h (3912B)


      1 /*
      2  *
      3  *  C++ Portable Types Library (PTypes)
      4  *  Version 2.1.1  Released 27-Jun-2007
      5  *
      6  *  Copyright (C) 2001-2007 Hovik Melikyan
      7  *
      8  *  http://www.melikyan.com/ptypes/
      9  *
     10  */
     11 
     12 #ifndef __PPORT_H__
     13 #define __PPORT_H__
     14 
     15 
     16 #if defined(linux)
     17 #  include <stdint.h>     // for uintptr_t
     18 #endif
     19 
     20 #include <sys/types.h>
     21 
     22 
     23 #ifndef __cplusplus
     24 #  error "This is a C++ source"
     25 #endif
     26 
     27 //
     28 // Windows DLL export/import and calling convention macros
     29 //
     30 
     31 #ifdef WIN32
     32 #  if defined(PTYPES_DLL_EXPORTS)
     33 #    define ptpublic	 __declspec(dllexport)
     34 #  elif defined(PTYPES_DLL)
     35 #    define ptpublic	__declspec(dllimport)
     36 #  else
     37 #    define ptpublic
     38 #  endif
     39 #  define ptdecl	__stdcall
     40 #  define __PFASTCALL __fastcall
     41 #else
     42 #  define ptpublic	
     43 #  define ptdecl	
     44 #  define __PFASTCALL
     45 #endif
     46 
     47 
     48 //
     49 // versioning
     50 //
     51 
     52 
     53 extern "C" ptpublic unsigned long __ptypes_version;
     54 
     55 // this enables old algebraic list interfaces; NO_PTYPES19_COMPAT
     56 // can be defined at command line
     57 #if !defined(NO_PTYPES19_COMPAT)
     58 #  define PTYPES19_COMPAT
     59 #endif
     60 
     61 
     62 namespace ptypes {
     63 
     64 
     65 #ifdef _MSC_VER
     66 // we don't want "unreferenced inline function" warning
     67 #  pragma warning (disable: 4514)
     68 // ... also "copy constructor/assignment operator could not be generated"
     69 #  pragma warning (disable: 4511)
     70 #  pragma warning (disable: 4512)
     71 // disable deprecation warnings for snprintf and others
     72 #  pragma warning (disable: 4996)
     73 #endif
     74 
     75 #if defined(_DEBUG) && !defined(DEBUG)
     76 #  define DEBUG
     77 #endif
     78 
     79 #if defined(__WIN32__) && !defined(WIN32)
     80 #  define WIN32
     81 #endif
     82 
     83 // __APPLE__ is the only predefined macro on MacOS X
     84 #if defined(__APPLE__)
     85 #  define __DARWIN__
     86 #endif
     87 
     88 // CHECK_BOUNDS enables bounds checking for strings and lists
     89 #if defined(DEBUG) && !defined(CHECK_BOUNDS)
     90 #  define CHECK_BOUNDS
     91 #endif
     92 
     93 // COUNT_OBJALLOC helps to keep track of the number of
     94 // objects created/destroyed
     95 #if defined(DEBUG) && !defined(COUNT_OBJALLOC)
     96 #  define COUNT_OBJALLOC
     97 #endif
     98 
     99 
    100 //
    101 // useful typedefs
    102 //
    103 
    104 typedef unsigned int    uint;
    105 typedef unsigned long   ulong;
    106 typedef unsigned short  ushort;
    107 typedef unsigned char   uchar;
    108 typedef signed char     schar;
    109 typedef char*           pchar;
    110 typedef const char*     pconst;
    111 typedef void*           ptr;
    112 typedef int*            pint;
    113 
    114 #ifdef WIN32
    115   typedef size_t       pintptr;
    116 #else
    117   typedef uintptr_t    pintptr;
    118 #endif
    119 
    120 
    121 //
    122 // portable 64-bit integers
    123 //
    124 
    125 #if defined(_MSC_VER) || defined(__BORLANDC__)
    126    typedef __int64             large;
    127    typedef unsigned __int64    ularge;
    128 #  define LLCONST(a) (a##i64)
    129 #else
    130    typedef long long           large;
    131    typedef unsigned long long  ularge;
    132 #  define LLCONST(a) (a##ll)
    133 #endif
    134 
    135 #define LARGE_MIN (LLCONST(-9223372036854775807)-1)
    136 #define LARGE_MAX (LLCONST(9223372036854775807))
    137 #define ULARGE_MAX (LLCONST(18446744073709551615u))
    138 
    139 #if defined(_MSC_VER) || defined(__BORLANDC__)
    140 #  define strcasecmp stricmp
    141 #endif
    142 #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(__BORLANDC__)
    143 #  define snprintf _snprintf
    144 #endif
    145 
    146 
    147 //
    148 // misc.
    149 //
    150 
    151 // I like Pascal's nil
    152 #define nil 0
    153 
    154 inline int   imax(int x, int y)       { return (x > y) ? x : y; }
    155 inline int   imin(int x, int y)       { return (x < y) ? x : y; }
    156 inline large lmax(large x, large y)   { return (x > y) ? x : y; }
    157 inline large lmin(large x, large y)   { return (x < y) ? x : y; }
    158 
    159 
    160 //
    161 // critical error processing
    162 //
    163 
    164 #define CRIT_FIRST 0xC0000
    165 
    166 typedef void (ptdecl *_pcrithandler)(int code, const char* msg);
    167 
    168 ptpublic _pcrithandler ptdecl getcrithandler();
    169 ptpublic _pcrithandler ptdecl setcrithandler(_pcrithandler newh);
    170 
    171 ptpublic void ptdecl fatal(int code, const char* msg);
    172 
    173 
    174 //
    175 // memory management (undocumented)
    176 // hides some BSD* incompatibility issues
    177 //
    178 
    179 ptpublic void* ptdecl memalloc(uint a);
    180 ptpublic void* ptdecl memrealloc(void* p, uint a);
    181 ptpublic void  ptdecl memfree(void* p);
    182 ptpublic void  ptdecl memerror();
    183 ptpublic int   ptdecl memquantize(int);
    184 
    185 
    186 }
    187 
    188 
    189 #endif // __PPORT_H__