gcsx_datatype.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* GCSx
  2. ** DATATYPE.H
  3. **
  4. ** Basic data types and structures, and simple data-type conversion
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_DATATYPE_H_
  24. #define __GCSx_DATATYPE_H_
  25. // Because SDL_Rect uses 16bit numbers which are too small for some purposes
  26. struct Rect {
  27. Sint32 x, y;
  28. Sint32 w, h;
  29. };
  30. // Number of Uint32s to use for a void* (for bytecode)
  31. extern int vPtrSize;
  32. // Floating point type used for bytecode
  33. // Also, printf code that displays it, and lib function to convert it
  34. typedef float BCfloat;
  35. #define BC_FLOAT_PRINTF "f"
  36. #define BC_FLOAT_CONVERT strtof
  37. /*
  38. typedef double BCfloat;
  39. #define BC_FLOAT_PRINTF "f"
  40. #define BC_FLOAT_CONVERT strtod
  41. typedef long double BCfloat;
  42. #define BC_FLOAT_PRINTF "Lf"
  43. #define BC_FLOAT_CONVERT strtold
  44. */
  45. // Number of Uint32s to use for it
  46. extern int bcFloatSize;
  47. // Blank constant string
  48. extern const std::string blankString;
  49. // Converts between integers/floats and strings
  50. // You must use string return values immediately! (buffer is overwritten each time)
  51. // (NOT THREAD SAFE)
  52. const char* intToStr(long value);
  53. const char* floatToStr(BCfloat value);
  54. long strToInt(const std::string& value);
  55. BCfloat strToFloat(const std::string& value);
  56. // Throws 1 if junk at end of string, 2 if entire string is unconvertable
  57. long strToIntErr(const std::string& value) throw_int;
  58. // printf for string class; limited to 255 characters at this time
  59. // (NOT THREAD SAFE)
  60. std::string formatString(const char* format, ...);
  61. // Copies data from one matrix (layer, etc.) to another
  62. // All sizes in bytes
  63. // Works with sizes of 0; does NOT work with overlapping buffers
  64. // @TODO: matrixSwap? (mostly for Undo)
  65. void matrixCopy(const void* source, void* dest, int w, int h, int sourcePitch, int destPitch);
  66. // Fills a Uint32 array (like memset but 32bit)
  67. void memSet32(Uint32* dest, Uint32 value, int size);
  68. // Not all platforms have stricmp
  69. int myStricmp(const char* a, const char* b);
  70. void toLower(std::string& str);
  71. // Allocates a char[] to match the given string
  72. char* newCpCopy(const std::string& fromStr);
  73. // Used in hashes or maps that key off const char*
  74. struct hash_eqstr {
  75. bool operator() (const char* s1, const char* s2) const {
  76. return (strcmp(s1, s2) == 0);
  77. }
  78. };
  79. struct map_ltstr {
  80. bool operator() (const char* s1, const char* s2) const {
  81. return (strcmp(s1, s2) < 0);
  82. }
  83. };
  84. #endif