Exemplo n.º 1
0
  void MultipleChoice::deserializeAnswer(JSONValue const &document) {
    QuizQuestion::deserializeAnswer(document);

    if (document.isMember("answer")) {
      ID answerId = ResourceParser::parseIdElement(document["answer"]);

      if (answerId) {
        choose(answerId);
      }
    }
  }
Exemplo n.º 2
0
  void QuizSubmission::save(QuizQuestion const* qq,
                            Session &session,
                            AsyncCallback callback) const {
    JSONValue document;
    JSONValue answerDocument;

    document["marked"] = qq->isMarked();

    answerDocument = qq->serializeAnswer();

    if (answerDocument.isMember("answer")) {
      document["answer"] = answerDocument["answer"];
    }

    save(qq, document, session, callback);
  }
Exemplo n.º 3
0
/*--------------------------------------------------------------------------------*/
bool AudioObjectParameters::FromJSON(const JSONValue& obj, bool reset)
{
  Position     pval;
  ParameterSet sval;
  std::string  str;
  double       dval;
  sint64_t     i64val;
  float        fval;
  uint_t       uval;
  int          ival;
  bool         bval;
  bool         success = true;
    
  success &= SetFromJSON<>(Parameter_channel, values.channel, ival, obj, reset, 0U, &Limit0u);
  success &= SetFromJSON<>(Parameter_duration, values.duration, i64val, obj, reset, (uint64_t)0);
  success &= SetFromJSON<>(Parameter_cartesian, values.cartesian, bval, obj, reset);
  success &= SetFromJSON<>(Parameter_position, position, pval, obj, reset);
  success &= SetFromJSON<>(Parameter_minposition, &minposition, pval, obj, reset);
  success &= SetFromJSON<>(Parameter_maxposition, &maxposition, pval, obj, reset);
  success &= SetFromJSON<>(Parameter_gain, values.gain, dval, obj, reset, 1.0);
  success &= SetFromJSON<>(Parameter_width, values.width, fval, obj, reset, 0.f, &Limit0f);
  success &= SetFromJSON<>(Parameter_depth, values.depth, fval, obj, reset, 0.f, &Limit0f);
  success &= SetFromJSON<>(Parameter_height, values.height, fval, obj, reset, 0.f, &Limit0f);
  success &= SetFromJSON<>(Parameter_divergencebalance, values.divergencebalance, fval, obj, reset, 0.f, &Limit0to1f);
  success &= SetFromJSON<>(Parameter_divergenceazimuth, values.divergenceazimuth, fval, obj, reset, 0.f, &Limit0f);
  success &= SetFromJSON<>(Parameter_diffuseness, values.diffuseness, fval, obj, reset, 0.f, &Limit0to1f);
  success &= SetFromJSON<>(Parameter_delay, values.delay, fval, obj, reset, 0.f, &Limit0f);
  success &= SetFromJSON<>(Parameter_objectimportance, values.objectimportance, uval, obj, reset, (uint8_t)GetObjectImportanceDefault(), &LimitImportance);
  success &= SetFromJSON<>(Parameter_channelimportance, values.channelimportance, uval, obj, reset, (uint8_t)GetChannelImportanceDefault(), &LimitImportance);
  success &= SetFromJSON<>(Parameter_dialogue, values.dialogue, uval, obj, reset, (uint8_t)GetDialogueDefault(), &LimitDialogue);
  success &= SetFromJSON<>(Parameter_channellock, values.channellock, bval, obj, reset);
  success &= SetFromJSON<>(Parameter_channellockmaxdistance, values.channellockmaxdistance, fval, obj, reset, 0.f, &LimitMaxDistance);
  success &= SetFromJSON<>(Parameter_interact, values.interact, bval, obj, reset, (uint8_t)GetInteractDefault());
  success &= SetFromJSON<>(Parameter_interpolate, values.interpolate, bval, obj, reset, (uint8_t)1);
  success &= SetFromJSON<>(Parameter_interpolationtime, values.interpolationtime, i64val, obj, reset, (uint64_t)0);
  success &= SetFromJSON<>(Parameter_onscreen, values.onscreen, bval, obj, reset);
  success &= SetFromJSON<>(Parameter_disableducking, values.disableducking, bval, obj, reset, (uint8_t)GetDisableDuckingDefault());
  success &= SetFromJSON<>(Parameter_othervalues, othervalues, sval, obj, reset);
  
  // support legacy 'importance' parameter name for channel importance
  if (obj.isObject() && obj.isMember("importance"))
  {
    // read value from JSON into intermediate value
    if (json::FromJSON(obj["importance"], uval))
    {
      // use intermediate value to set parameter
      SetParameter<>(Parameter_channelimportance, values.channelimportance, uval, &LimitImportance);
    }
    else success = false;
  }

  // delete existing list of excluded zones
  if (excludedZones)
  {
    delete excludedZones;
    excludedZones = NULL;
  }

  {
    // try and find zoneExclusion item in object
    if (obj.isObject() && obj.isMember("excludedzones") && obj["excludedzones"].isArray())
    {
      const JSONValue& zones = obj["excludedzones"];

      for (uint_t i = 0; i < zones.size(); i++)
      {
        if (zones[i].isObject())
        {
          const JSONValue& obj = zones[i];
          std::string name;
          float minx, miny, minz, maxx, maxy, maxz;

          // extract name and limits of excluded zone
          if (json::FromJSON(obj, "name", name) &&
              json::FromJSON(obj, "minx", minx) &&
              json::FromJSON(obj, "miny", miny) &&
              json::FromJSON(obj, "minz", minz) &&
              json::FromJSON(obj, "maxx", maxx) &&
              json::FromJSON(obj, "maxy", maxy) &&
              json::FromJSON(obj, "maxz", maxz))
          {
            AddExcludedZone(name, minx, miny, minz, maxx, maxy, maxz);
          }
          else
          {
            BBCERROR("Unable to extract excluded zones from JSON '%s'", json::ToJSONString(obj).c_str());
            success = false;
          }
        }
      }
    }
  }
  
  return success;
}