Commit f2430572 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

update to improved plist api

parent c0e9a524
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ enable_testing()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/extra/cmake")
set(CMAKE_CXX_STANDARD 17)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/utils)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

find_package(Threads)
+28 −63
Original line number Diff line number Diff line
@@ -34,62 +34,19 @@

namespace plotfx {


ReturnCode parse_classlike(
    const plist::Property& prop,
    const std::string& fn,
    std::vector<std::string>* args) {
  if (prop.size() < 3) {
    return ERROR_INVALID_ARGUMENT;
  }

  if (!prop[0].is_literal || prop[0].data != fn) {
    return ERROR_INVALID_ARGUMENT;
  }

  if (!prop[1].is_literal || prop[1].data != "(") {
    return ERROR_INVALID_ARGUMENT;
  }

  size_t argidx = 2;
  for (; argidx < prop.size() - 1; ++argidx) {
    if (prop[argidx].is_literal && prop[argidx].data == ",") {
      continue;
    }

    if (prop[argidx].is_literal && prop[argidx].data == ")") {
      break;
    }

    args->emplace_back(prop[argidx].data);
    continue;
  }

  if (argidx >= prop.size()) {
    return ERROR_INVALID_ARGUMENT;
  }

  if (!prop[argidx].is_literal || prop[argidx].data != ")") {
    return ERROR_INVALID_ARGUMENT;
  }

  return OK;
}

ReturnCode parse_data_series_csv(
    const plist::Property& prop ,
    std::vector<double>* data) {
  std::vector<std::string> args;
  if (auto rc = parse_classlike(prop, "csv", &args); !rc) {
    return rc;
  if (!plist::is_enum(prop, "csv")) {
    return ERROR_INVALID_ARGUMENT;
  }

  if (args.size() < 2) {
  if (prop.size() < 2) {
    return ERROR_INVALID_ARGUMENT; // FIXME
  }

  const auto& csv_path = args[0];
  const auto& csv_column = args[1];
  const auto& csv_path = prop[0].value;
  const auto& csv_column = prop[1].value;

  size_t csv_column_idx = 0;
  try {
@@ -102,8 +59,8 @@ ReturnCode parse_data_series_csv(
  auto csv_data = CSVData{};
  auto csv_opts = CSVParserConfig{};

  for (size_t i = 2; i < args.size(); ++i) {
    if (args[i] == "noheaders") {
  for (size_t i = 2; i < prop.size(); ++i) {
    if (prop[i].value == "noheaders") {
      csv_opts.headers = false;
      continue;
    }
@@ -132,10 +89,14 @@ ReturnCode parse_data_series_csv(
ReturnCode parse_data_series_inline(
    const plist::Property& prop ,
    std::vector<double>* data) {
  for (const auto& v : prop.values) {
  if (!plist::is_list(prop)) {
    return ERROR_INVALID_ARGUMENT;
  }

  for (const auto& v : *prop.next) {
    double value;
    try {
      value = std::stod(v.data);
      value = std::stod(v);
    } catch (... ) {
      return ERROR_INVALID_ARGUMENT;
    }
@@ -149,24 +110,28 @@ ReturnCode parse_data_series_inline(
ReturnCode parseDataSeries(
    const plist::Property& prop,
    std::vector<double>* data) {
  if (prop.size() > 0 && prop[0].is_literal && prop[0].data == "csv") {
  if (plist::is_enum(prop, "csv")) {
    return parse_data_series_csv(prop, data);
  }

  if (plist::is_list(prop)) {
    return parse_data_series_inline(prop, data);
  }

  return ERROR_INVALID_ARGUMENT;
}

ReturnCode parseMeasureProp(
    const plist::Property& prop,
    Measure* value) {
  if (prop.size() != 1) {
  if (!plist::is_value(prop)) {
    return ReturnCode::errorf(
        "EARG",
        "incorrect number of arguments; expected: 1, got: $0",
        prop.size());
  }

  return parse_measure(prop[0], value);
  return parse_measure(prop, value);
}

ParserFn configure_multiprop(const std::vector<ParserFn>& parsers) {
@@ -184,15 +149,15 @@ ParserFn configure_multiprop(const std::vector<ParserFn>& parsers) {
ReturnCode configure_colour(
    const plist::Property& prop,
    Colour* value) {
  if (prop.size() != 1) {
  if (!plist::is_value(prop)) {
    return ReturnCode::errorf(
        "EARG",
        "incorrect number of arguments; expected: 1, got: $0",
        prop.size());
  }

  if (prop.size() > 0 && StringUtil::beginsWith(prop[0].data, "#")) {
    if (value->parse(prop[0].data)) {
  if (StringUtil::beginsWith(prop, "#")) {
    if (value->parse(prop)) {
      return OK;
    }
  }
@@ -203,7 +168,7 @@ ReturnCode configure_colour(
ReturnCode configure_float(
    const plist::Property& prop,
    double* value) {
  if (prop.size() != 1) {
  if (!plist::is_value(prop)) {
    return ReturnCode::errorf(
        "EARG",
        "incorrect number of arguments; expected: 1, got: $0",
@@ -211,7 +176,7 @@ ReturnCode configure_float(
  }

  try {
    *value = std::stod(prop[0].data);
    *value = std::stod(prop);
  } catch (... ) {
    return ERROR_INVALID_ARGUMENT;
  }
@@ -222,7 +187,7 @@ ReturnCode configure_float(
ReturnCode configure_float_opt(
    const plist::Property& prop,
    std::optional<double>* value) {
  if (prop.size() != 1) {
  if (!plist::is_value(prop)) {
    return ReturnCode::errorf(
        "EARG",
        "incorrect number of arguments; expected: 1, got: $0",
@@ -230,7 +195,7 @@ ReturnCode configure_float_opt(
  }

  try {
    *value = std::optional<double>(std::stod(prop[0].data));
    *value = std::optional<double>(std::stod(prop));
  } catch (... ) {
    return ERROR_INVALID_ARGUMENT;
  }
+2 −2
Original line number Diff line number Diff line
@@ -91,11 +91,11 @@ ReturnCode buildDocument(
  for (size_t i = 0; i < plist.size(); ++i) {
    const auto& elem_name = plist[i].name;

    if (!plist[i].child) {
    if (!plist::is_map(plist[i])) {
      continue;
    }

    const auto& elem_config = plist[i].child.get();
    const auto& elem_config = plist[i].next.get();

    std::unique_ptr<Element> elem;
    if (auto rc = buildElement(*doc, elem_name, *elem_config, &elem); !rc.isSuccess()) {
+18 −18
Original line number Diff line number Diff line
@@ -49,18 +49,17 @@ Formatter format_decimal_scientific(size_t precision) {
ReturnCode confgure_format_decimal_scientific(
    const plist::Property& prop,
    Formatter* formatter) {
  std::vector<std::string> args;
  if (auto rc = parse_classlike(prop, "scientific", &args); !rc) {
    return rc;
  if (!plist::is_enum(prop, "scientific")) {
    return ERROR_INVALID_ARGUMENT;
  }

  uint32_t precision = 1;
  switch (args.size()) {
  switch (prop.size()) {
    case 0:
      break;
    case 1:
      try {
        precision = std::stod(args[0]);
        precision = std::stod(prop[0]);
        break;
      } catch (... ) {
        return ERROR_INVALID_ARGUMENT;
@@ -87,18 +86,17 @@ Formatter format_decimal_fixed(size_t precision) {
ReturnCode confgure_format_decimal_fixed(
    const plist::Property& prop,
    Formatter* formatter) {
  std::vector<std::string> args;
  if (auto rc = parse_classlike(prop, "fixed", &args); !rc) {
    return rc;
  if (!plist::is_enum(prop, "fixed")) {
    return ERROR_INVALID_ARGUMENT;
  }

  uint32_t precision = 1;
  switch (args.size()) {
  switch (prop.size()) {
    case 0:
      break;
    case 1:
      try {
        precision = std::stod(args[0]);
        precision = std::stod(prop[0]);
        break;
      } catch (... ) {
        return ERROR_INVALID_ARGUMENT;
@@ -124,17 +122,16 @@ Formatter format_datetime(const std::string& fmt) {
ReturnCode confgure_format_datetime(
    const plist::Property& prop,
    Formatter* formatter) {
  std::vector<std::string> args;
  if (auto rc = parse_classlike(prop, "datetime", &args); !rc) {
    return rc;
  if (!plist::is_enum(prop, "datetime")) {
    return ERROR_INVALID_ARGUMENT;
  }

  std::string fmtspec = "%Y-%m-%d %H:%M:%S"; // FIXME improved auto format
  switch (args.size()) {
  switch (prop.size()) {
    case 0:
      break;
    case 1:
      fmtspec = args[0];
      fmtspec = prop[0];
      break;
    default:
      return ERROR_INVALID_ARGUMENT;
@@ -151,15 +148,18 @@ ReturnCode confgure_format(
    return ERROR_INVALID_ARGUMENT;
  }

  if (prop[0].data == "fixed") {
  if (plist::is_value(prop, "fixed") ||
      plist::is_enum(prop, "fixed")) {
    return confgure_format_decimal_fixed(prop, formatter);
  }

  if (prop[0].data == "scientific") {
  if (plist::is_value(prop, "scientific") ||
      plist::is_enum(prop, "scientific")) {
    return confgure_format_decimal_scientific(prop, formatter);
  }

  if (prop[0].data == "datetime") {
  if (plist::is_value(prop, "datetime") ||
      plist::is_enum(prop, "datetime")) {
    return confgure_format_datetime(prop, formatter);
  }

+2 −2
Original line number Diff line number Diff line
@@ -59,14 +59,14 @@ ReturnCode parseAxisMode(
}

ReturnCode parseAxisModeProp(const plist::Property& prop, AxisMode* value) {
  if (prop.size() != 1) {
  if (!plist::is_value(prop)) {
    return ReturnCode::errorf(
        "EARG",
        "incorrect number of arguments; expected: 1, got: $0",
        prop.size());
  }

  return parseAxisMode(prop[0], value);
  return parseAxisMode(prop, value);
}

static Status renderAxisVertical(
Loading