common_types.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Copyright (C) 2005-2012 Gekko Emulator
  3. *
  4. * @file common_types.h
  5. * @author ShizZy <shizzy247@gmail.com>
  6. * @date 2012-02-11
  7. * @brief Common types used throughout the project
  8. *
  9. * @section LICENSE
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details at
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * Official project repository can be found at:
  22. * http://code.google.com/p/gekko-gc-emu/
  23. */
  24. #pragma once
  25. #include <cmath>
  26. #include <cstdint>
  27. #include <cstdlib>
  28. #ifdef _MSC_VER
  29. #ifndef __func__
  30. #define __func__ __FUNCTION__
  31. #endif
  32. #endif
  33. typedef std::uint8_t u8; ///< 8-bit unsigned byte
  34. typedef std::uint16_t u16; ///< 16-bit unsigned short
  35. typedef std::uint32_t u32; ///< 32-bit unsigned word
  36. typedef std::uint64_t u64; ///< 64-bit unsigned int
  37. typedef std::int8_t s8; ///< 8-bit signed byte
  38. typedef std::int16_t s16; ///< 16-bit signed short
  39. typedef std::int32_t s32; ///< 32-bit signed word
  40. typedef std::int64_t s64; ///< 64-bit signed int
  41. typedef float f32; ///< 32-bit floating point
  42. typedef double f64; ///< 64-bit floating point
  43. // TODO: It would be nice to eventually replace these with strong types that prevent accidental
  44. // conversion between each other.
  45. typedef u32 VAddr; ///< Represents a pointer in the userspace virtual address space.
  46. typedef u32 PAddr; ///< Represents a pointer in the ARM11 physical address space.
  47. /// Union for fast 16-bit type casting
  48. union t16 {
  49. u8 _u8[2]; ///< 8-bit unsigned char(s)
  50. u16 _u16; ///< 16-bit unsigned shorts(s)
  51. };
  52. /// Union for fast 32-bit type casting
  53. union t32 {
  54. f32 _f32; ///< 32-bit floating point(s)
  55. u32 _u32; ///< 32-bit unsigned int(s)
  56. s32 _s32; ///< 32-bit signed int(s)
  57. u16 _u16[2]; ///< 16-bit unsigned shorts(s)
  58. u8 _u8[4]; ///< 8-bit unsigned char(s)
  59. };
  60. /// Union for fast 64-bit type casting
  61. union t64 {
  62. f64 _f64; ///< 64-bit floating point
  63. u64 _u64; ///< 64-bit unsigned long
  64. f32 _f32[2]; ///< 32-bit floating point(s)
  65. u32 _u32[2]; ///< 32-bit unsigned int(s)
  66. s32 _s32[2]; ///< 32-bit signed int(s)
  67. u16 _u16[4]; ///< 16-bit unsigned shorts(s)
  68. u8 _u8[8]; ///< 8-bit unsigned char(s)
  69. };
  70. // An inheritable class to disallow the copy constructor and operator= functions
  71. class NonCopyable {
  72. protected:
  73. NonCopyable() = default;
  74. ~NonCopyable() = default;
  75. NonCopyable(NonCopyable&) = delete;
  76. NonCopyable& operator=(NonCopyable&) = delete;
  77. };