Commit 4db23960 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

improved plot_element code structure

parent b563704a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -28,10 +28,11 @@ add_library(signaltk STATIC
    graphics/rasterize.cc
    graphics/png.cc
    elements/context.cc
    elements/element.cc
    elements/plot/gridlines.cc
    elements/plot/axes.cc
    elements/plot/plot_domain.cc
    elements/plot/plot_layout.cc
    elements/plot/plot_element.cc
    elements/plot/legenddefinition.cc
    elements/plot/series.cc
    utils/random.cc
+0 −5
Original line number Diff line number Diff line
@@ -11,10 +11,5 @@

namespace signaltk {

Status Context::element_add(ElementRef elem) {
  elements.emplace(std::move(elem));
  return Status::OK;
}

} // namespace signaltk
+4 −4
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@
#pragma once
#include <stack>
#include "element.h"
#include "elements/plot/plot_config.h"
#include "graphics/layer.h"

namespace signaltk {
@@ -19,12 +18,13 @@ class Context {
public:

  template <typename T>
  Status element_get(T** elem);
  Status element_config(T** elem);

  template <typename T>
  Status element_get(T const** elem) const;
  Status element_config(T const** elem) const;

  Status element_add(ElementRef elem);
  template <typename T>
  Status element_add();

  std::unique_ptr<Layer> frame;

+14 −4
Original line number Diff line number Diff line
@@ -12,22 +12,32 @@
namespace signaltk {

template <typename T>
Status Context::element_get(T** elem) {
Status Context::element_config(T** elem) {
  if (elements.empty()) {
    return Status::ERROR_INVALID_ELEM;
  }

  *elem = static_cast<T*>(elements.top().get());
  *elem = static_cast<T*>(elements.top()->config);
  return OK;
}

template <typename T>
Status Context::element_get(T const** elem) const {
Status Context::element_config(T const** elem) const {
  if (elements.empty()) {
    return Status::ERROR_INVALID_ELEM;
  }

  *elem = static_cast<const T*>(elements.top().get());
  *elem = static_cast<const T*>(elements.top()->config);
  return OK;
}

template <typename T>
Status Context::element_add() {
  auto e = std::make_unique<Element>();
  e->config = new T();
  e->destroy = [] (Element* e) { delete static_cast<T*>(e->config); };

  elements.emplace(std::move(e));
  return OK;
}

+6 −5
Original line number Diff line number Diff line
@@ -7,14 +7,15 @@
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#pragma once
#include "signaltk.h"
#include "element.h"

namespace signaltk {

Status plot_add(Context* ctx);

Status plot_render(Context* ctx);
Element::~Element() {
  if (destroy) {
    destroy(this);
  }
}

} // namespace signaltk
Loading