AttachmentLoader.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2
  4. *
  5. * Copyright (c) 2013, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to install, execute and perform the Spine Runtimes
  10. * Software (the "Software") solely for internal use. Without the written
  11. * permission of Esoteric Software, you may not (a) modify, translate, adapt or
  12. * otherwise create derivative works, improvements of the Software or develop
  13. * new applications using the Software or (b) remove, delete, alter or obscure
  14. * any trademarks or any copyright, trademark, patent or other intellectual
  15. * property or proprietary rights notices on or in the Software, including
  16. * any copy thereof. Redistributions in binary or source form must include
  17. * this license and terms. THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #include <spine/AttachmentLoader.h>
  29. #include <stdio.h>
  30. #include <spine/extension.h>
  31. typedef struct _spAttachmentLoaderVtable {
  32. spAttachment* (*newAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name);
  33. void (*dispose) (spAttachmentLoader* self);
  34. } _spAttachmentLoaderVtable;
  35. void _spAttachmentLoader_init (spAttachmentLoader* self, /**/
  36. void (*dispose) (spAttachmentLoader* self), /**/
  37. spAttachment* (*newAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name)) {
  38. CONST_CAST(_spAttachmentLoaderVtable*, self->vtable) = NEW(_spAttachmentLoaderVtable);
  39. VTABLE(spAttachmentLoader, self)->dispose = dispose;
  40. VTABLE(spAttachmentLoader, self)->newAttachment = newAttachment;
  41. }
  42. void _spAttachmentLoader_deinit (spAttachmentLoader* self) {
  43. FREE(self->vtable);
  44. FREE(self->error1);
  45. FREE(self->error2);
  46. }
  47. void spAttachmentLoader_dispose (spAttachmentLoader* self) {
  48. VTABLE(spAttachmentLoader, self)->dispose(self);
  49. FREE(self);
  50. }
  51. spAttachment* spAttachmentLoader_newAttachment (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name) {
  52. FREE(self->error1);
  53. FREE(self->error2);
  54. self->error1 = 0;
  55. self->error2 = 0;
  56. return VTABLE(spAttachmentLoader, self)->newAttachment(self, skin, type, name);
  57. }
  58. void _spAttachmentLoader_setError (spAttachmentLoader* self, const char* error1, const char* error2) {
  59. FREE(self->error1);
  60. FREE(self->error2);
  61. MALLOC_STR(self->error1, error1);
  62. MALLOC_STR(self->error2, error2);
  63. }
  64. void _spAttachmentLoader_setUnknownTypeError (spAttachmentLoader* self, spAttachmentType type) {
  65. char buffer[16];
  66. sprintf(buffer, "%d", type);
  67. _spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
  68. }