CGEchoObject.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /******************************************************************
  2. *
  3. * uEcho for ObjC
  4. *
  5. * Copyright (C) Satoshi Konno 2015
  6. *
  7. * This is licensed under BSD-style license, see file COPYING.
  8. *
  9. ******************************************************************/
  10. #import "CGEchoObject.h"
  11. #import "CGEchoProperty.h"
  12. #include <uecho/object.h>
  13. @implementation CGEchoObject {
  14. uEchoObject* cObject;
  15. }
  16. - (id)initWithCObject:(uEchoObject*)cobj
  17. {
  18. if ((self = [super init]) == nil)
  19. return nil;
  20. cObject = cobj;
  21. return self;
  22. }
  23. - (void)dealloc
  24. {
  25. }
  26. - (NSArray*)properties;
  27. {
  28. if (!cObject)
  29. return [NSArray array];
  30. NSMutableArray* props = [NSMutableArray array];
  31. for (uEchoProperty* cProp = uecho_object_getproperties(cObject); cProp; cProp = uecho_property_next(cProp)) {
  32. CGEchoProperty* prop = [[CGEchoProperty alloc] initWithCObject:cProp];
  33. [props addObject:prop];
  34. }
  35. return props;
  36. }
  37. - (NSString*)name
  38. {
  39. if (!cObject)
  40. return nil;
  41. const char* name = uecho_object_getname(cObject);
  42. if (!name)
  43. return nil;
  44. return [NSString stringWithUTF8String:name];
  45. }
  46. - (int)code
  47. {
  48. if (!cObject)
  49. return 0;
  50. return uecho_object_getcode(cObject);
  51. }
  52. - (Byte)group
  53. {
  54. if (!cObject)
  55. return 0;
  56. return uecho_object_getgroupcode(cObject);
  57. }
  58. - (Byte)class
  59. {
  60. if (!cObject)
  61. return 0;
  62. return uecho_object_getclasscode(cObject);
  63. }
  64. - (Byte)instance
  65. {
  66. if (!cObject)
  67. return 0;
  68. return uecho_object_getinstancecode(cObject);
  69. }
  70. @end