SampleStatistic timeStat;
std::string name;
- SGSubsystem * subsystem;
+ SGSharedPtr<SGSubsystem> subsystem;
double min_step_sec;
double elapsed_sec;
bool collectTimeStats;
void
SGSubsystemGroup::remove_subsystem (const string &name)
{
- for( size_t i = 0; i < _members.size(); i++ ) {
- if (name == _members[i]->name) {
- _members.erase(_members.begin() + i);
+ MemberVec::iterator it = _members.begin();
+ for (; it != _members.end(); ++it) {
+ if (name == (*it)->name) {
+ delete *it;
+ _members.erase(it);
return;
}
}
+
+ SG_LOG(SG_GENERAL, SG_WARN, "remove_subsystem: missing:" << name);
}
void
SGSubsystemGroup::Member::~Member ()
{
- delete subsystem;
}
void
if (_subsystem_map.find(name) != _subsystem_map.end()) {
SG_LOG(SG_GENERAL, SG_ALERT, "Adding duplicate subsystem " << name);
- throw sg_exception("duplicate subsystem");
+ throw sg_exception("duplicate subsystem:" + std::string(name));
}
_subsystem_map[name] = subsystem;
}
-SGSubsystem*
+void
SGSubsystemMgr::remove(const char* name)
{
SubsystemDict::iterator s =_subsystem_map.find(name);
if (s == _subsystem_map.end()) {
- return NULL;
+ return;
}
- SGSubsystem* sub = s->second;
_subsystem_map.erase(s);
// tedious part - we don't know which group the subsystem belongs too
for (int i = 0; i < MAX_GROUPS; i++) {
- if (_groups[i]->get_subsystem(name) == sub) {
+ if (_groups[i]->get_subsystem(name) != NULL) {
_groups[i]->remove_subsystem(name);
break;
}
} // of groups iteration
-
- return sub;
}
static void* reportTimingUserData;
};
-
+typedef SGSharedPtr<SGSubsystem> SGSubsystemRef;
+
\f
/**
* A group of FlightGear subsystems.
class Member;
Member* get_member (const std::string &name, bool create = false);
- std::vector<Member *> _members;
+ typedef std::vector<Member *> MemberVec;
+ MemberVec _members;
double _fixedUpdateTime;
double _updateTimeRemainder;
* remove a subsystem, and return a pointer to it.
* returns NULL if the subsystem was not found.
*/
- virtual SGSubsystem* remove(const char* name);
+ virtual void remove(const char* name);
virtual SGSubsystemGroup * get_group (GroupType group);
- virtual SGSubsystem * get_subsystem(const std::string &name) const;
+ virtual SGSubsystem* get_subsystem(const std::string &name) const;
void reportTiming();
void setReportTimingCb(void* userData,SGSubsystemTimingCb cb) {reportTimingCb = cb;reportTimingUserData = userData;}
SGSubsystemGroup* _groups[MAX_GROUPS];
unsigned int _initPosition;
+ // non-owning reference
typedef std::map<std::string, SGSubsystem*> SubsystemDict;
SubsystemDict _subsystem_map;
};