Example #1
0
void Option::writeStrings(JSON::Sink &sink, const string &value,
                          const string &delims) {
  strings_t l = parseStrings(value, delims);

  sink.beginList();
  for (unsigned i = 0; i < l.size(); i++) sink.append(l[i]);
  sink.endList();
}
Example #2
0
void ToolTable::write(JSON::Sink &sink) const {
  sink.beginDict();

  for (const_iterator it = begin(); it != end(); it++)
    if (it->second->getNumber()) {
      sink.beginInsert(String(it->second->getNumber()));
      it->second->write(sink, false);
    }

  sink.endDict();
}
Example #3
0
void IPRangeSet::write(JSON::Sink &sink) const {
  sink.beginList();

  for (unsigned i = 0; i < rangeSet.size(); i += 2)
    if (rangeSet[i] == rangeSet[i + 1])
      sink.append(IPAddress(rangeSet[i]).toString());

    else sink.append(IPAddress(rangeSet[i]).toString() + "-" +
                     IPAddress(rangeSet[i + 1]).toString());
  sink.endList();
}
Example #4
0
void Option::writeDoubles(JSON::Sink &sink, const string &value,
                          const string &delims) {
  doubles_t l = parseDoubles(value, delims);

  sink.beginList();
  for (unsigned i = 0; i < value.size(); i++) {
    sink.beginAppend();
    sink.append(l[i]);
  }
  sink.endList();
}
Example #5
0
void Option::writeIntegers(JSON::Sink &sink, const string &value,
                           const string &delims) {
  integers_t l = parseIntegers(value, delims);

  sink.beginList();
  for (unsigned i = 0; i < l.size(); i++) {
    sink.beginAppend();
    if (JSON_MIN_INT < l[i] && l[i] < JSON_MAX_INT) sink.write(l[i]);
    else sink.write(SSTR("0x" << hex << l[i]));
  }
  sink.endList();
}
void Workpiece::write(JSON::Sink &sink) const {
  sink.beginDict();

  sink.insertBoolean("automatic", automatic);
  sink.insert("margin", margin);
  if (bounds.isValid()) {
    sink.beginInsert("bounds");
    bounds.write(sink);
  }

  sink.endDict();
}
Example #7
0
void ToolPath::write(JSON::Sink &sink) const {
  Axes lastPos(numeric_limits<double>::infinity());
  MoveType type = (MoveType::enum_t)-1;
  int line = -1;
  int tool = -1;
  double feed = -1;
  double speed = -1;

  sink.beginList();
  for (unsigned i = 0; i < size(); i++) {
    const Move &move = at(i);
    sink.appendDict(true);

    // Axes
    for (unsigned j = 0; j < 9; j++)
      if (move.getEnd()[j] != lastPos[j])
        sink.insert(string(1, Axes::toAxis(j)), lastPos[j] = move.getEnd()[j]);

    // Type
    if (type != move.getType())
      sink.insert("type", (type = move.getType()).toString());

    // Line number
    if (line != (int)move.getLine())
      sink.insert("line", line = move.getLine());

    // Tool
    if (tool != (int)move.getTool())
      sink.insert("tool", tool = move.getTool());

    // Feed
    if (feed != move.getFeed())
      sink.insert("feed", feed = move.getFeed());

    // Speed
    if (speed != move.getSpeed())
      sink.insert("speed", speed = move.getSpeed());

    sink.endDict();
  }

  sink.endList();
}
Example #8
0
void Option::writeValue(JSON::Sink &sink, const string &value,
                        const string &delims) const {
  switch (type) {
  case BOOLEAN_TYPE: writeBoolean(sink, value); break;
  case STRING_TYPE: sink.write(value); break;
  case INTEGER_TYPE: writeInteger(sink, value); break;
  case DOUBLE_TYPE: writeDouble(sink, value); break;
  case STRINGS_TYPE: writeStrings(sink, value, delims); break;
  case INTEGERS_TYPE: writeIntegers(sink, value, delims); break;
  case DOUBLES_TYPE: writeDoubles(sink, value, delims); break;
  default: THROWS("Invalid type " << type);
  }
}
Example #9
0
void Tool::write(JSON::Sink &sink, bool withNumber) const {
  sink.beginDict();

  double scale = units == ToolUnits::UNITS_INCH ? 1.0 / 25.4 : 1;

  if (withNumber) sink.insert("number", number);
  sink.insert("units", getUnits().toString());
  sink.insert("shape", getShape().toString());
  sink.insert("length", getLength() * scale);
  sink.insert("diameter", getDiameter() * scale);
  if (getShape() == ToolShape::TS_SNUBNOSE)
    sink.insert("snub_diameter", getSnubDiameter() * scale);
  sink.insert("description", getDescription());

  sink.endDict();
}
Example #10
0
void Simulation::write(JSON::Sink &sink) const {
  sink.beginDict();

  sink.beginInsert("tools");
  tools.write(sink);

  sink.beginInsert("path");
  path->write(sink);

  sink.beginInsert("workpiece");
  workpiece.write(sink);

  sink.insert("resolution", resolution);
  sink.insert("time", time);

  sink.endDict();
}
void DwellCommand::insert(JSON::Sink &sink) const {
  sink.insert("seconds", seconds);
}
Example #12
0
void Option::write(JSON::Sink &sink, bool config, const string &delims) const {
  if (config) {
    string value = toString();

    if (isObscured() && !(flags & OBSCURED_FLAG))
      sink.write(string(value.size(), '*'));
    else writeValue(sink, value, delims);

    return;
  }

  sink.beginDict();

  if (!getHelp().empty()) sink.insert("help", getHelp());

  if (hasValue()) {
    sink.beginInsert("value");
    string value = toString();

    if (isObscured() && !(flags & OBSCURED_FLAG))
      sink.write(string(value.size(), '*'));
    else writeValue(sink, value, delims);
  }

  if (hasDefault()) {
    sink.beginInsert("default");
    writeValue(sink, getDefault(), delims);
  }

  sink.insert("type", getTypeString());
  if (isOptional()) sink.insertBoolean("optional", true);
  if (shortName) sink.insert("short", string(1, shortName));
  if (isSet()) sink.insertBoolean("set", true);
  if (isCommandLine()) sink.insertBoolean("command_line", true);
  if (isDepreciated()) sink.insertBoolean("depreciated", true);
  if (!constraint.isNull()) sink.insert("constraint", constraint->getHelp());

  sink.endDict();
}
Example #13
0
void Option::writeDouble(JSON::Sink &sink, const string &value) {
  sink.write(parseDouble(value));
}
Example #14
0
void Option::writeInteger(JSON::Sink &sink, const string &value) {
  int64_t x = parseInteger(value);

  if (JSON_MIN_INT < x && x < JSON_MAX_INT) sink.write(x);
  else sink.write(SSTR("0x" << hex << x));
}
Example #15
0
void Option::writeBoolean(JSON::Sink &sink, const string &value) {
  sink.writeBoolean(parseBoolean(value));
}
void OutputCommand::insert(JSON::Sink &sink) const {
  sink.insert("port", String::transcode
              (String::toLower(PortType(port).toString()), "_", "-"));
  sink.insert("value", value);
}