BKE_library_query.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * The Original Code is Copyright (C) 2014 by Blender Foundation.
  19. * All rights reserved.
  20. *
  21. * Contributor(s): Sergey SHarybin.
  22. *
  23. * ***** END GPL LICENSE BLOCK *****
  24. */
  25. #ifndef __BKE_LIBRARY_QUERY_H__
  26. #define __BKE_LIBRARY_QUERY_H__
  27. /** \file BKE_library_query.h
  28. * \ingroup bke
  29. * \since March 2014
  30. * \author sergey
  31. */
  32. struct ID;
  33. struct Main;
  34. /* Tips for the callback for cases it's gonna to modify the pointer. */
  35. enum {
  36. IDWALK_CB_NOP = 0,
  37. IDWALK_CB_NEVER_NULL = (1 << 0),
  38. IDWALK_CB_NEVER_SELF = (1 << 1),
  39. /**
  40. * Indicates whether this is direct (i.e. by local data) or indirect (i.e. by linked data) usage.
  41. * \note Object proxies are half-local, half-linked...
  42. */
  43. IDWALK_CB_INDIRECT_USAGE = (1 << 2),
  44. /** That ID is used as mere sub-data by its owner
  45. * (only case currently: those f***ing nodetrees in materials etc.).
  46. * This means callback shall not *do* anything, only use this as informative data if it needs it. */
  47. IDWALK_CB_PRIVATE = (1 << 3),
  48. /** That ID is not really used by its owner, it's just an internal hint/helper.
  49. * This addresses Their Highest Ugliness the 'from' pointers: Object->from_proxy and Key->from.
  50. * How to handle that kind of cases totally depends on what caller code is doing... */
  51. IDWALK_CB_LOOPBACK = (1 << 4),
  52. /**
  53. * Adjusts #ID.us reference-count.
  54. * \note keep in sync with 'newlibadr_us' use in readfile.c
  55. */
  56. IDWALK_CB_USER = (1 << 8),
  57. /** Ensure #ID.us is at least 1 on use. */
  58. IDWALK_CB_USER_ONE = (1 << 9),
  59. };
  60. enum {
  61. IDWALK_RET_NOP = 0,
  62. IDWALK_RET_STOP_ITER = 1 << 0, /* Completly stop iteration. */
  63. IDWALK_RET_STOP_RECURSION = 1 << 1, /* Stop recursion, that is, do not loop over ID used by current one. */
  64. };
  65. /**
  66. * Call a callback for each ID link which the given ID uses.
  67. *
  68. * \return a set of flags to control further iteration (0 to keep going).
  69. */
  70. typedef int (*LibraryIDLinkCallback) (void *user_data, struct ID *id_self, struct ID **id_pointer, int cb_flag);
  71. /* Flags for the foreach function itself. */
  72. enum {
  73. IDWALK_NOP = 0,
  74. IDWALK_READONLY = (1 << 0),
  75. IDWALK_RECURSE = (1 << 1), /* Also implies IDWALK_READONLY. */
  76. IDWALK_NO_INDIRECT_PROXY_DATA_USAGE = (1 << 8), /* Ugly special case :(((( */
  77. };
  78. /* Loop over all of the ID's this datablock links to. */
  79. void BKE_library_foreach_ID_link(
  80. struct Main *bmain, struct ID *id, LibraryIDLinkCallback callback, void *user_data, int flag);
  81. void BKE_library_update_ID_link_user(struct ID *id_dst, struct ID *id_src, const int cb_flag);
  82. int BKE_library_ID_use_ID(struct ID *id_user, struct ID *id_used);
  83. bool BKE_library_id_can_use_idtype(struct ID *id_owner, const short id_type_used);
  84. bool BKE_library_ID_is_locally_used(struct Main *bmain, void *idv);
  85. bool BKE_library_ID_is_indirectly_used(struct Main *bmain, void *idv);
  86. void BKE_library_ID_test_usages(struct Main *bmain, void *idv, bool *is_used_local, bool *is_used_linked);
  87. void BKE_library_unused_linked_data_set_tag(struct Main *bmain, const bool do_init_tag);
  88. void BKE_library_indirectly_used_data_tag_clear(struct Main *bmain);
  89. #endif /* __BKE_LIBRARY_QUERY_H__ */