context_listener.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * context_listener.h - Context-dependent entity
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __STUDIO__CONTEXT_LISTENER_H__9E128DC4
  19. #define __STUDIO__CONTEXT_LISTENER_H__9E128DC4
  20. #include <memory>
  21. #include <type_traits>
  22. #include <core/context.h>
  23. namespace core {
  24. class AbstractValue;
  25. }
  26. namespace studio {
  27. class ContextListener {
  28. public:
  29. ContextListener(std::shared_ptr<core::Context> context_=nullptr);
  30. public:
  31. virtual std::shared_ptr<core::Context> get_context() const;
  32. virtual void set_context(std::shared_ptr<core::Context> context_);
  33. protected:
  34. virtual core::Time get_time() {
  35. return time;
  36. }
  37. virtual void time_changed(core::Time time_) {
  38. time = time_;
  39. }
  40. virtual void fps_changed(core::Time::fps_type) {}
  41. virtual void active_node_changed(std::shared_ptr<core::AbstractValue>) {}
  42. template <class S, class F>
  43. void connect_boost(S& signal, F lambda) {
  44. auto slot = typename S::slot_type(lambda);
  45. slot.track_foreign(destroy_detector);
  46. signal.connect(slot);
  47. }
  48. private:
  49. std::shared_ptr<core::Context> context;
  50. core::Time time;
  51. struct Null {};
  52. std::shared_ptr<Null> destroy_detector;
  53. };
  54. }
  55. #endif