From 79b25c850e561f83590717700eb58e22f7818a09 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 10 Aug 2001 05:16:41 +0000 Subject: [PATCH] - modified to use pointers to bindings to avoid copying --- src/Cockpit/panel.cxx | 8 +++++--- src/Cockpit/panel.hxx | 6 ++++-- src/Cockpit/panel_io.cxx | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index f04952d17..11d69e046 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -450,6 +450,8 @@ FGPanelAction::FGPanelAction () FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h) : _button(button), _x(x), _y(y), _w(w), _h(h) { + for (unsigned int i = 0; i < _bindings.size(); i++) + delete _bindings[i]; } FGPanelAction::~FGPanelAction () @@ -457,7 +459,7 @@ FGPanelAction::~FGPanelAction () } void -FGPanelAction::addBinding (const FGBinding &binding) +FGPanelAction::addBinding (FGBinding * binding) { _bindings.push_back(binding); } @@ -468,7 +470,7 @@ FGPanelAction::doAction () if (test()) { int nBindings = _bindings.size(); for (int i = 0; i < nBindings; i++) { - _bindings[i].fire(); + _bindings[i]->fire(); } } } @@ -714,7 +716,7 @@ FGGroupLayer::FGGroupLayer () FGGroupLayer::~FGGroupLayer () { - for (int i = 0; i < _layers.size(); i++) + for (unsigned int i = 0; i < _layers.size(); i++) delete _layers[i]; } diff --git a/src/Cockpit/panel.hxx b/src/Cockpit/panel.hxx index f18916084..ba07155b1 100644 --- a/src/Cockpit/panel.hxx +++ b/src/Cockpit/panel.hxx @@ -228,7 +228,9 @@ public: virtual int getHeight () const { return _h; } // Setters. - virtual void addBinding (const FGBinding &binding); + + // transfer pointer ownership + virtual void addBinding (FGBinding * binding); virtual void setButton (int button) { _button = button; } virtual void setX (int x) { _x = x; } virtual void setY (int y) { _y = y; } @@ -249,7 +251,7 @@ public: virtual void doAction (); private: - typedef vector binding_list_t; + typedef vector binding_list_t; int _button; int _x; diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index b9390429b..2ade65f0d 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -242,10 +242,10 @@ readAction (const SGPropertyNode * node, float w_scale, float h_scale) FGPanelAction * action = new FGPanelAction(button, x, y, w, h); vectorbindings = node->getChildren("binding"); - for (int i = 0; i < bindings.size(); i++) { + for (unsigned int i = 0; i < bindings.size(); i++) { SG_LOG(SG_INPUT, SG_INFO, "Reading binding " << bindings[i]->getStringValue("command")); - action->addBinding(FGBinding(bindings[i])); // TODO: allow modifiers + action->addBinding(new FGBinding(bindings[i])); // TODO: allow modifiers } readConditions(action, node);