pando_object.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*******************************************************
  2. * File name: pando_object.c
  3. * Author: razr
  4. * Versions: 1.0
  5. * Description:
  6. * History:
  7. * 1.Date: Sep 11, 2015
  8. * Author: razr
  9. * Modification:
  10. *********************************************************/
  11. #include "pando_object.h"
  12. #include "pando_sys.h"
  13. #include "pando_machine.h"
  14. #define MAX_OBJECTS 16
  15. static pando_object s_pando_object_list[MAX_OBJECTS];
  16. static int s_pando_object_list_idx = 0;
  17. void FUNCTION_ATTRIBUTE
  18. register_pando_object(pando_object object)
  19. {
  20. if(s_pando_object_list_idx > MAX_OBJECTS - 1)
  21. {
  22. return;
  23. }
  24. s_pando_object_list[s_pando_object_list_idx++] = object;
  25. }
  26. pando_object* FUNCTION_ATTRIBUTE
  27. find_pando_object(uint8_t no)
  28. {
  29. int i;
  30. for(i = 0; i < s_pando_object_list_idx; i++)
  31. {
  32. if( s_pando_object_list[i].no == no)
  33. {
  34. return &s_pando_object_list[i];
  35. }
  36. }
  37. return NULL;
  38. }
  39. pando_objects_iterator* FUNCTION_ATTRIBUTE
  40. create_pando_objects_iterator()
  41. {
  42. pando_objects_iterator* it = (pando_objects_iterator*)pd_malloc(sizeof(pando_objects_iterator));
  43. it->cur = 0;
  44. return it;
  45. }
  46. void FUNCTION_ATTRIBUTE
  47. delete_pando_objects_iterator(pando_objects_iterator* it)
  48. {
  49. if(it)
  50. {
  51. pd_free(it);
  52. }
  53. }
  54. pando_object* FUNCTION_ATTRIBUTE
  55. pando_objects_iterator_next(pando_objects_iterator *it)
  56. {
  57. if(it->cur == s_pando_object_list_idx)
  58. {
  59. return NULL;
  60. }
  61. return &s_pando_object_list[it->cur++];
  62. }