Templated helper to retrieve a subsystem

- example of naming a subsystem
This commit is contained in:
James Turner
2015-12-10 14:52:04 -06:00
parent 31095c39cc
commit c62b4467b4
2 changed files with 21 additions and 16 deletions
+5 -6
View File
@@ -34,7 +34,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <memory> // for std::auto_ptr #include <memory> // for std::auto_ptr
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/math/SGMath.hxx> #include <simgear/math/SGMath.hxx>
@@ -55,7 +55,7 @@ public:
void init(); void init();
void update(double dt); void update(double dt);
void suspend(); void suspend();
void resume(); void resume();
void stop(); void stop();
@@ -93,7 +93,7 @@ public:
*/ */
bool add( SGSampleGroup *sgrp, const std::string& refname ); bool add( SGSampleGroup *sgrp, const std::string& refname );
/** /**
* Remove a sample group from the sound manager. * Remove a sample group from the sound manager.
* @param refname Reference name of the sample group to remove * @param refname Reference name of the sample group to remove
* @return true if successful, false otherwise * @return true if successful, false otherwise
@@ -268,11 +268,12 @@ public:
const std::string& get_vendor() { return _vendor; } const std::string& get_vendor() { return _vendor; }
const std::string& get_renderer() { return _renderer; } const std::string& get_renderer() { return _renderer; }
static const char* subsystemName() { return "sound"; };
private: private:
class SoundManagerPrivate; class SoundManagerPrivate;
/// private implementation object /// private implementation object
std::auto_ptr<SoundManagerPrivate> d; std::auto_ptr<SoundManagerPrivate> d;
bool _active; bool _active;
bool _changed; bool _changed;
float _volume; float _volume;
@@ -298,5 +299,3 @@ private:
#endif // _SG_SOUNDMGR_OPENAL_HXX #endif // _SG_SOUNDMGR_OPENAL_HXX
+16 -10
View File
@@ -39,7 +39,7 @@ private:
std::string eventName; std::string eventName;
SGTimeStamp time; SGTimeStamp time;
public: public:
TimingInfo(const std::string& name, const SGTimeStamp &t) : TimingInfo(const std::string& name, const SGTimeStamp &t) :
eventName(name), time(t) eventName(name), time(t)
{ } { }
@@ -153,7 +153,7 @@ public:
INIT_DONE, ///< subsystem is fully initialised INIT_DONE, ///< subsystem is fully initialised
INIT_CONTINUE ///< init should be called again INIT_CONTINUE ///< init should be called again
} InitStatus; } InitStatus;
virtual InitStatus incrementalInit (); virtual InitStatus incrementalInit ();
/** /**
@@ -186,7 +186,7 @@ public:
* </p> * </p>
*/ */
virtual void shutdown (); virtual void shutdown ();
/** /**
* Acquire the subsystem's property bindings. * Acquire the subsystem's property bindings.
* *
@@ -267,7 +267,7 @@ public:
void reportTiming(void); 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. * update() member functions. Predominantly for debugging purposes.
*/ */
void stamp(const std::string& name); void stamp(const std::string& name);
@@ -324,12 +324,12 @@ public:
* *
*/ */
void set_fixed_update_time(double fixed_dt); void set_fixed_update_time(double fixed_dt);
/** /**
* retrive list of member subsystem names * retrive list of member subsystem names
*/ */
string_list member_names() const; string_list member_names() const;
private: private:
class Member; class Member;
@@ -337,10 +337,10 @@ private:
typedef std::vector<Member *> MemberVec; typedef std::vector<Member *> MemberVec;
MemberVec _members; MemberVec _members;
double _fixedUpdateTime; double _fixedUpdateTime;
double _updateTimeRemainder; double _updateTimeRemainder;
/// index of the member we are currently init-ing /// index of the member we are currently init-ing
unsigned int _initPosition; unsigned int _initPosition;
}; };
@@ -398,7 +398,7 @@ public:
virtual void add (const char * name, virtual void add (const char * name,
SGSubsystem * subsystem, SGSubsystem * subsystem,
GroupType group = GENERAL, GroupType group = GENERAL,
double min_time_sec = 0); double min_time_sec = 0);
/** /**
@@ -414,6 +414,12 @@ public:
void reportTiming(); void reportTiming();
void setReportTimingCb(void* userData,SGSubsystemTimingCb cb) {reportTimingCb = cb;reportTimingUserData = userData;} void setReportTimingCb(void* userData,SGSubsystemTimingCb cb) {reportTimingCb = cb;reportTimingUserData = userData;}
template<class T>
T* get_subsystem() const
{
return dynamic_cast<T*>(get_subsystem(T::subsystemName()));
}
private: private:
std::vector<SGSubsystemGroupRef> _groups; std::vector<SGSubsystemGroupRef> _groups;
unsigned int _initPosition; unsigned int _initPosition;