Object.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright (c) 2006-2011 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_OBJECT_H
  21. #define LOVE_OBJECT_H
  22. namespace love
  23. {
  24. /**
  25. * Superclass for all object that should be able to cross the Lua/C border
  26. * (this pertains to most objects).
  27. *
  28. * This class is an alternative to using smart pointers; it contains retain/release
  29. * methods, and will delete itself with the reference count hits zero. The wrapper
  30. * code assumes that all userdata inherits from this class.
  31. **/
  32. class Object
  33. {
  34. private:
  35. // The reference count.
  36. int count;
  37. public:
  38. /**
  39. * Constructor. Sets reference count to one.
  40. **/
  41. Object();
  42. /**
  43. * Destructor.
  44. **/
  45. virtual ~Object() = 0;
  46. /**
  47. * Gets the reference count of this Object.
  48. * @returns The reference count.
  49. **/
  50. int getReferenceCount() const;
  51. /**
  52. * Retains the Object, i.e. increases the
  53. * reference count by one.
  54. **/
  55. void retain();
  56. /**
  57. * Releases one reference to the Object, i.e. decrements the
  58. * reference count by one, and potentially deletes the Object
  59. * if there are no more references.
  60. **/
  61. void release();
  62. }; // Object
  63. } // love
  64. #endif // LOVE_OBJECT_H