From: James Turner Date: Thu, 10 Dec 2015 20:51:56 +0000 (-0600) Subject: Templated helper to retrieve a subsystem X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c62b4467b442d269c24585b7b8bf490d4cb2aed3;p=simgear.git Templated helper to retrieve a subsystem - example of naming a subsystem --- 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 #include // for std::auto_ptr - + #include #include #include @@ -55,7 +55,7 @@ public: void init(); void update(double dt); - + void suspend(); void resume(); void stop(); @@ -93,7 +93,7 @@ public: */ bool add( SGSampleGroup *sgrp, const std::string& refname ); - /** + /** * Remove a sample group from the sound manager. * @param refname Reference name of the sample group to remove * @return true if successful, false otherwise @@ -268,11 +268,12 @@ public: const std::string& get_vendor() { return _vendor; } const std::string& get_renderer() { return _renderer; } + static const char* subsystemName() { return "sound"; }; private: class SoundManagerPrivate; /// private implementation object std::auto_ptr d; - + bool _active; bool _changed; float _volume; @@ -298,5 +299,3 @@ private: #endif // _SG_SOUNDMGR_OPENAL_HXX - - diff --git a/simgear/structure/subsystem_mgr.hxx b/simgear/structure/subsystem_mgr.hxx index 4139fa68..7a07f21c 100644 --- a/simgear/structure/subsystem_mgr.hxx +++ b/simgear/structure/subsystem_mgr.hxx @@ -39,7 +39,7 @@ private: std::string eventName; SGTimeStamp time; -public: +public: TimingInfo(const std::string& name, const SGTimeStamp &t) : eventName(name), time(t) { } @@ -153,7 +153,7 @@ public: INIT_DONE, ///< subsystem is fully initialised INIT_CONTINUE ///< init should be called again } InitStatus; - + virtual InitStatus incrementalInit (); /** @@ -186,7 +186,7 @@ public: *

*/ 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;