예제 #1
0
  to_if_held_down(const nlohmann::json& json) : dispatcher_client(),
                                                current_held_down_id_(0) {
    try {
      if (json.is_object()) {
        to_ = std::vector<to_event_definition>{
            json.get<to_event_definition>(),
        };

      } else if (json.is_array()) {
        to_ = json.get<std::vector<to_event_definition>>();

      } else {
        throw pqrs::json::unmarshal_error(fmt::format("json must be object or array, but is `{0}`", json.dump()));
      }

    } catch (...) {
      detach_from_dispatcher();
      throw;
    }
  }
예제 #2
0
파일: core.cpp 프로젝트: gitesei/faunus
 void from_json(const nlohmann::json &j, Tensor &t) {
     if ( j.size()!=6 || !j.is_array() )
         throw std::runtime_error("Json->Tensor: array w. exactly six coefficients expected.");
     t = Tensor(j[0],j[1],j[2],j[3],j[4],j[5]);
 }