msg.template.h 759 B

123456789101112131415161718192021222324252627
  1. #ifndef AFUN_MSG_TEMPLATE_H
  2. #define AFUN_MSG_TEMPLATE_H
  3. #include "msg.h"
  4. namespace aFuncore {
  5. template<class T>
  6. T *MessageStream::getMessage(const std::string &type) const {
  7. Message *msg = this->_getMessage(type);
  8. T *ret = dynamic_cast<T*>(msg);
  9. return ret;
  10. }
  11. template <typename Callable, typename...T>
  12. inline void MessageStream::forEach(Callable func, T...arg) {
  13. for (auto &msg : stream)
  14. func(msg.second, arg...);
  15. }
  16. template<typename Callable, typename... T>
  17. void UpMessage::forEachAll(Callable func, T... arg) {
  18. for (const UpMessage *up = this; up != nullptr; up = up->old)
  19. up->MessageStream::forEach(func, arg...);
  20. }
  21. }
  22. #endif //AFUN_MSG_TEMPLATE_H