Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/helpers/callback_merit.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 #include <vector> | |
| 3 #include <algorithm> | |
| 4 #include <SDK/callback_merit.h> | |
| 5 | |
| 6 namespace fb2k { | |
| 7 // Call global callbacks in correct order | |
| 8 // INTENDED FOR CORE USE ONLY | |
| 9 // Not aware of dynamically registered callbacks, if there are such for the same event type | |
| 10 // Usage: for_each_callback_by_merit< metadb_io_edit_callback > ( [] ( metadb_io_edit_callback::ptr ) { ...} ); | |
| 11 template<typename class_t> | |
| 12 void for_each_callback_by_merit(std::function<void(service_ptr_t<class_t>)> f) { | |
| 13 struct rec_t { | |
| 14 class_t* obj; // non-autoptr INTENDED, avoid destruction order bugs on shutdown | |
| 15 fb2k::callback_merit_t merit; | |
| 16 }; | |
| 17 auto generator = [] { | |
| 18 std::vector<rec_t> ret; ret.reserve(64); | |
| 19 for (auto ptr : class_t::enumerate()) { | |
| 20 rec_t r; | |
| 21 r.merit = fb2k::callback_merit_of(ptr); | |
| 22 r.obj = ptr.detach(); | |
| 23 ret.push_back( std::move(r) ); | |
| 24 } | |
| 25 std::sort(ret.begin(), ret.end(), [](rec_t const& e1, rec_t const& e2) { return e1.merit > e2.merit; }); | |
| 26 return ret; | |
| 27 }; | |
| 28 static std::vector<rec_t> cache = generator(); | |
| 29 for (auto& walk : cache) f(walk.obj); | |
| 30 } | |
| 31 } |
