From c62b4467b442d269c24585b7b8bf490d4cb2aed3 Mon Sep 17 00:00:00 2001
From: James Turner
Date: Thu, 10 Dec 2015 14:51:56 -0600
Subject: [PATCH] Templated helper to retrieve a subsystem
- example of naming a subsystem
---
simgear/sound/soundmgr_openal.hxx | 11 +++++------
simgear/structure/subsystem_mgr.hxx | 26 ++++++++++++++++----------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx
index 58168fc8..19897e32 100644
--- a/simgear/sound/soundmgr_openal.hxx
+++ b/simgear/sound/soundmgr_openal.hxx
@@ -34,7 +34,7 @@
#include
#include
*/
virtual void shutdown ();
-
+
/**
* Acquire the subsystem's property bindings.
*
@@ -267,7 +267,7 @@ public:
void reportTiming(void);
/**
- * Place time stamps at strategic points in the execution of subsystems
+ * Place time stamps at strategic points in the execution of subsystems
* update() member functions. Predominantly for debugging purposes.
*/
void stamp(const std::string& name);
@@ -324,12 +324,12 @@ public:
*
*/
void set_fixed_update_time(double fixed_dt);
-
+
/**
* retrive list of member subsystem names
- */
+ */
string_list member_names() const;
-
+
private:
class Member;
@@ -337,10 +337,10 @@ private:
typedef std::vector MemberVec;
MemberVec _members;
-
+
double _fixedUpdateTime;
double _updateTimeRemainder;
-
+
/// index of the member we are currently init-ing
unsigned int _initPosition;
};
@@ -398,7 +398,7 @@ public:
virtual void add (const char * name,
SGSubsystem * subsystem,
- GroupType group = GENERAL,
+ GroupType group = GENERAL,
double min_time_sec = 0);
/**
@@ -414,6 +414,12 @@ public:
void reportTiming();
void setReportTimingCb(void* userData,SGSubsystemTimingCb cb) {reportTimingCb = cb;reportTimingUserData = userData;}
+ template
+ T* get_subsystem() const
+ {
+ return dynamic_cast(get_subsystem(T::subsystemName()));
+ }
+
private:
std::vector _groups;
unsigned int _initPosition;
--
2.39.5