Commit 1c271b86 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add element_factory

parent a5b8d93f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ add_library(signaltk STATIC
    graphics/rasterize.cc
    graphics/png.cc
    elements/context.cc
    elements/element_factory.cc
    elements/element_spec_parser.cc
    elements/plot/gridlines.cc
    elements/plot/axes.cc
@@ -59,7 +60,7 @@ set(SIGNALTK_LDFLAGS signaltk ${CAIRO_LIBRARIES} ${FREETYPE_LIBRARIES} ${HARFBUZ
add_executable(plotfx platform/signaltk_cli.cc)
target_link_libraries(plotfx ${SIGNALTK_LDFLAGS})

file(GLOB test_files "testing/**/test_*.cc")
file(GLOB test_files "testing/unit/test_*.cc")
foreach(test_path ${test_files})
  get_filename_component(test_name ${test_path} NAME_WE)
  get_filename_component(test_srcdir ${test_path} DIRECTORY)
+4 −1
Original line number Diff line number Diff line
@@ -15,10 +15,13 @@
namespace signaltk {

class Element {
public:

  virtual ~Element() = default;

}
};

using ElementRef = std::unique_ptr<Element>;


} // namespace signaltk
+35 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2018 Paul Asmuth
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#include "element_factory.h"
#include "elements/plot/plot_element.h"
#include <unordered_map>

namespace signaltk {

using ElementConfigureFn = std::function<ReturnCode (const PropertyList&, ElementRef*)>;

static std::unordered_map<std::string, ElementConfigureFn> elems = {
  {"plot", &PlotElement::configure}
};

ReturnCode buildElement(
    const std::string& name,
    const PropertyList& plist,
    std::unique_ptr<Element>* elem) {
  const auto& elem_entry = elems.find(name);
  if (elem_entry == elems.end()) {
    return ReturnCode::errorf("NOTFOUND", "no such element: $0", name);
  }

  return elem_entry->second(plist, elem);
}

} // namespace signaltk
+10 −2
Original line number Diff line number Diff line
@@ -10,6 +10,9 @@
#pragma once
#include <memory>
#include "signaltk.h"
#include "elements/element.h"
#include "elements/element_spec.h"
#include "utils/return_code.h"
#include "axes.h"
#include "plot_domain.h"

@@ -25,9 +28,14 @@ struct PlotConfig {
  std::vector<std::unique_ptr<AxisDefinition>> axes;
};

Status plot_add(context* ctx);
class PlotElement : public Element {
public:

Status plot_render(context* ctx);
  static ReturnCode configure(
      const PropertyList& plist,
      std::unique_ptr<Element>* elem);

};

} // namespace signaltk
Baidu
map