diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-02-14 18:24:49 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-02-14 18:26:32 +0300 |
commit | fa7149893a6c9d61ba840475b6d96172b0d55a67 (patch) | |
tree | 015369a94910b8c53695eee9d4b310263c6cf12c /source/blender/blenkernel/BKE_main.h | |
parent | caf89c3de16993a8153281ecf5919b40e2fff069 (diff) |
Cleanup: replace Main ID's foreach functions by macros.
Am really no a big fan of using macros for that kind of things, but
meh... C solution to do that with functions (using callbacks) is
even worse. :(
Diffstat (limited to 'source/blender/blenkernel/BKE_main.h')
-rw-r--r-- | source/blender/blenkernel/BKE_main.h | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index a96c1399979..08b6d47877e 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -140,14 +140,39 @@ void BKE_main_relations_free(struct Main *bmain); struct GSet *BKE_main_gset_create(struct Main *bmain, struct GSet *gset); /* *** Generic utils to loop over whole Main database. *** */ -/** \return false to stop iteration, true to keep going. */ -typedef bool (*MainForeachIDCallback) (struct Main *bmain, struct ID *id, void *user_data); -bool BKE_main_listbase_foreach_id( - struct Main *bmain, struct ListBase *lb, - MainForeachIDCallback callback, void *user_data); -bool BKE_main_foreach_id( - struct Main *bmain, const bool reverse_type_order, - MainForeachIDCallback callback, void *user_data); + +#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id) \ + for (_id = _lb->first; _id != NULL; _id = _id->next) { \ + +#define FOREACH_MAIN_LISTBASE_ID_END \ + } ((void)0) + + +#define FOREACH_MAIN_ID_BEGIN(_bmain, _id) \ + { \ + ListBase *_lbarray[MAX_LIBARRAY]; \ + int i = set_listbasepointers(_bmain, _lbarray); \ + while (i--) { \ + FOREACH_MAIN_LISTBASE_ID_BEGIN(_lbarray[i], _id) \ + +#define FOREACH_MAIN_ID_END \ + FOREACH_MAIN_LISTBASE_ID_END; \ + } \ + } ((void)0) + +/** \param _do_break A boolean, to allow breaking iteration (only used to break by type, + * you must also use an explicit `break;` operation if you want to + * immediately break from inner by-ID loop). + */ +#define FOREACH_MAIN_ID_BREAKABLE_BEGIN(_bmain, _id, _do_break) \ + { \ + ListBase *_lbarray[MAX_LIBARRAY]; \ + int i = set_listbasepointers(_bmain, _lbarray); \ + while (i-- && !_do_break) { \ + FOREACH_MAIN_LISTBASE_ID_BEGIN(_lbarray[i], _id) \ + +#define FOREACH_MAIN_ID_BREAKABLE_END FOREACH_MAIN_ID_END + struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct ImBuf *img); struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data); |