Example #1
0
void
Object::Serialise(TextWriter &writer, int indent) const
{
  writer.Write('{');
  if (indent >= 0)
    writer.NewLine();

  for (auto it = children.begin(), end = children.end(); it != end;) {
    if (indent >= 0) {
      SerialiseIndent(writer, indent + 1);
      writer.Format("\"%s\": ", it->first.c_str());
      it->second->Serialise(writer, indent + 1);
      if (++it != end)
        writer.Write(',');
      writer.NewLine();
    } else {
      writer.Format("\"%s\":", it->first.c_str());
      it->second->Serialise(writer, indent);
      if (++it != end)
        writer.Write(',');
    }
  }

  if (indent >= 0)
    SerialiseIndent(writer, indent);

  writer.Write('}');
}
Example #2
0
void
WriteCup(TextWriter &writer, const Waypoint &wp)
{
  // Write Title
  writer.Format(_T("\"%s\","), wp.name.c_str());

  // Write Code
  writer.Write(',');

  // Write Country
  writer.Write(',');

  // Write Latitude
  WriteAngleDMM(writer, wp.location.latitude, true);
  writer.Write(',');

  // Write Longitude
  WriteAngleDMM(writer, wp.location.longitude, false);
  writer.Write(',');

  // Write Elevation
  WriteAltitude(writer, wp.elevation);
  writer.Write(',');

  // Write Style
  WriteSeeYouFlags(writer, wp);
  writer.Write(',');

  // Write Runway Direction
  if ((wp.type == Waypoint::Type::AIRFIELD ||
       wp.type == Waypoint::Type::OUTLANDING) &&
      wp.runway.IsDirectionDefined())
    writer.Format("%03u", wp.runway.GetDirectionDegrees());

  writer.Write(',');

  // Write Runway Length
  if ((wp.type == Waypoint::Type::AIRFIELD ||
       wp.type == Waypoint::Type::OUTLANDING) &&
      wp.runway.IsLengthDefined())
    writer.Format("%03uM", wp.runway.GetLength());

  writer.Write(',');

  // Write Airport Frequency
  if (wp.radio_frequency.IsDefined()) {
    const unsigned freq = wp.radio_frequency.GetKiloHertz();
    writer.Format("\"%u.%03u\"", freq / 1000, freq % 1000);
  }

  writer.Write(',');

  // Write Description
  writer.FormatLine(_T("\"%s\""), wp.comment.c_str());
}
Example #3
0
static void
WriteAngleDMM(TextWriter &writer, const Angle angle, bool is_latitude)
{
  // Calculate degrees, minutes and decimal minutes
  unsigned deg, min, mmm;
  bool is_positive;
  angle.ToDMM(deg, min, mmm, is_positive);

  // Save them into the buffer string
  writer.Format(is_latitude ? "%02u%02u.%03u" : "%03u%02u.%03u",
                deg, min, mmm);

  // Attach the buffer string to the output
  if (is_latitude)
    writer.Write(is_positive ? "N" : "S");
  else
    writer.Write(is_positive ? "E" : "W");
}
Example #4
0
static void
WriteAltitude(TextWriter &writer, fixed altitude)
{
  writer.Format("%dM", (int)altitude);
}
Example #5
0
void
String::Serialise(TextWriter &writer, gcc_unused int indent) const
{
  writer.Format("\"%s\"", value.c_str());
}
Example #6
0
void
Double::Serialise(TextWriter &writer, gcc_unused int indent) const
{
  writer.Format("%f", value);
}
Example #7
0
void
Integer::Serialise(TextWriter &writer, gcc_unused int indent) const
{
  writer.Format("%d", value);
}
Example #8
0
 /**
  * Writer for a JSON integer value.
  */
 static inline void WriteLong(TextWriter &writer, long value) {
   writer.Format("%ld", value);
 }
Example #9
0
 /**
  * Writer for a JSON integer value.
  */
 static inline void WriteUnsigned(TextWriter &writer, unsigned value) {
   writer.Format("%u", value);
 }
Example #10
0
 /**
  * Writer for a JSON integer value.
  */
 static inline void WriteInteger(TextWriter &writer, int value) {
   writer.Format("%d", value);
 }
Example #11
0
/**
 * Writer for a JSON floating/fixed point value.
 */
static inline void WriteFixed(TextWriter &writer, fixed value) {
    writer.Format("%f", (double)value);
}