Exemplo n.º 1
0
	bool from_json< cTileLib >(cTileLib & zData, const rapidjson::Value& zRoot)
	{
		std::string res, desc;
		from_json(res, zRoot["res"]);
		from_json(desc, zRoot["desc"]);
		zData.Init(GAME.GetDataPath() + res, GAME.GetDataPath() + desc);
		return true;
	}
Exemplo n.º 2
0
    virtual std::unique_ptr<Cursor> metadata_query(std::string metric, std::string where_clause) {
        boost::property_tree::ptree query;

        // No (re)sampling
        query.add("select", "names");

        // Add metric name
        if (!metric.empty()) {
            query.add("metric", metric);
        }

        // Where clause
        if (!where_clause.empty()) {
            boost::property_tree::ptree where = from_json(where_clause);
            query.add_child("where", where);
        }

        std::stringstream stream;
        boost::property_tree::json_parser::write_json(stream, query, true);
        std::string query_text = stream.str();

        auto cursor = aku_query(db_, query_text.c_str());
        std::unique_ptr<LocalCursor> ptr(new LocalCursor(db_, cursor));
        return std::move(ptr);
    }
Exemplo n.º 3
0
inline void from_json(const json_t &js, QubitNoise &noise) {
  if (JSON::check_key("noise_params", js)) {
    from_json(js["noise_params"], noise);
  } else {
    noise = QubitNoise();
    from_json(js, noise.reset);
    noise.ideal &= noise.reset.ideal;
    noise.readout = js;
    noise.ideal &= noise.readout.ideal;
    noise.relax = js;
    noise.ideal &= !(noise.relax.rate > 0.);
    for (const auto &n : QubitNoise::gate_names) {
      if (JSON::check_key(n, js)) {
        GateError g;
        if (n == "CX" || n == "CZ")
          g = load_gate_error(n, 2, js);
        else
          g = load_gate_error(n, 1, js);

        // Check coherent error
        if (g.coherent_error) {
          cmatrix_t check = MOs::Dagger(g.Uerr) * g.Uerr;
          double threshold = 1e-10;
          double delta = 0.;
          for (size_t i=0; i < check.GetRows(); i++)
            for (size_t j=0; j < check.GetColumns(); j++) {
              complex_t val = (i==j) ? 1. : 0.;
              delta += std::real(std::abs(check(i, j) - val));
            }
          if (delta > threshold) {
            throw std::runtime_error(std::string(g.label + " U_error is not unitary"));
          }
        }

        // Add gate to noise model
        noise.gate.insert(std::make_pair(n, g));
        noise.ideal &= g.ideal;
      }
    }
  }
}
Exemplo n.º 4
0
Result<Client::Request> ClientJson::to_request(Slice request) {
  auto request_str = request.str();
  TRY_RESULT(json_value, json_decode(request_str));
  if (json_value.type() != JsonValue::Type::Object) {
    return Status::Error("Expected an object");
  }
  TRY_RESULT(extra_field, get_json_object_field(json_value.get_object(), "@extra", JsonValue::Type::Null, true));
  std::uint64_t extra_id = extra_id_.fetch_add(1, std::memory_order_relaxed);
  auto extra_str = json_encode<string>(extra_field);
  if (!extra_str.empty()) {
    std::lock_guard<std::mutex> guard(mutex_);
    extra_[extra_id] = std::move(extra_str);
  }

  td_api::object_ptr<td_api::Function> func;
  TRY_STATUS(from_json(func, json_value));
  return Client::Request{extra_id, std::move(func)};
}
Exemplo n.º 5
0
    void from_json(const json &j, std::vector<AtomData> &v) {
        auto it = j.find("atomlist");
        json _j = ( it==j.end() ) ? j : *it;
        v.reserve( v.size() + _j.size() );

        for ( auto &i : _j ) {
            if ( i.is_string() ) // treat ax external file to load
                from_json( openjson(i.get<std::string>()), v );
            else if ( i.is_object() ) {
                AtomData a = i;
                auto it = findName( v, a.name );
                if ( it==v.end() )
                    v.push_back( a ); // add new atom
                else
                    *it = a;
            }
        }
        for (size_t i=0; i<v.size(); i++)
            v[i].id() = i; // id must match position in vector
    }
void mmFilterTransactionsDialog::dataToControls()
{
    BuildPayeeList();
    from_json(settings_string_);
}
Exemplo n.º 7
0
        try {
            json j = json::parse(str);
            return details::from_json(j);
        } catch (std::exception &e) {
            throw syntax_error(e.what());
        }
    }
    
    inline jtype from_json(std::istream &is) {
        try {
            json j = json::parse(is);
            return details::from_json(j);
        } catch (std::exception &e) {
            throw syntax_error(e.what());
        }
    }    
    
    inline std::ostream &operator<<(std::ostream &os, const jtype &v) {
        // use std::setw to format with intendation.
        os << details::to_json(v);
        return os;
    }
    
    inline std::istream &operator>>(std::istream &is, jtype &v) {
        v = from_json(is);
        return is;
    }
}

#endif
Exemplo n.º 8
0
SkillInfo::SkillInfo(const std::string &json)
{
	from_json(json);
}
Exemplo n.º 9
0
int
runpython_ts(const char *modname, const char * clsname, const char * funcname, const int paramhandle)
{
    PyObject *modstr, *mod, *clsstr, *cls, *funcstr, *func, *plist, *args, *retval; 
    /* convert module, class and func to utf-8 */
    modstr = strLenToUtfPy((char *)modname, strlen(modname));
    plist = getObjectFromHandle(paramhandle);
    /* parameters */
    if (PyString_Check(plist)) {
        /* parameter should be a json string */
        plist = from_json(plist); 
        if (plist == NULL) {
            error_msg("Error in json parameter string");
            return -1;
        }
    }
    if (!PyList_Check(plist)) {
        error_msg("Error in runpython: parameters must be a list");
        return -1;
    }
    /* import modules */
    mod = PyImport_Import(modstr);
    if (mod == NULL)
    {
        Py_DECREF(modstr);
        error_msg("Error in runpython: Module not found");
        return -1;
    }
    if (clsname != NULL)
        clsstr = strLenToUtfPy((char *)clsname, strlen(clsname));
    funcstr = strLenToUtfPy((char *)funcname, strlen(funcname));
    if (clsname != NULL && strlen(clsname) > 0)
    {
        cls = PyObject_GetAttr(mod, clsstr);
        if (cls != NULL)
            func = PyObject_GetAttr(cls, funcstr);
    } else {
        func = PyObject_GetAttr(mod, funcstr);
    }
    if (!func || !PyCallable_Check(func))
    {
        Py_XDECREF(cls);
        Py_XDECREF(mod);
        error_msg("Error in runpython: Function not found");
        return -1;
    }
    args = PyList_AsTuple(plist);
    retval = PyObject_CallObject(func, args);
    Py_XDECREF(args);
    Py_XDECREF(func);
    Py_XDECREF(funcstr);
    Py_XDECREF(cls);
    Py_XDECREF(clsstr);
    Py_XDECREF(mod);
    Py_XDECREF(modstr);
    if (!retval) {
        PyErr_Print();
        error_msg("Error in runpython: See QPRINT for details");
        return -1;
    }
    /* keep the return value */
    return newHandle(retval);
}
Exemplo n.º 10
0
Arquivo: Plan.cpp Projeto: timn/fawkes
Plan::Plan(const std::string &json)
{
	from_json(json);
}
Exemplo n.º 11
0
ToolConfig::ToolConfig(std::string fileName) {
    std::ifstream in(fileName);
    json config;
    in >> config;
    from_json(config, *this);
}
Exemplo n.º 12
0
Backend::Backend(const std::string &json)
{
	from_json(json);
}
Exemplo n.º 13
0
BlackboardGraph::BlackboardGraph(const std::string &json)
{
	from_json(json);
}
Exemplo n.º 14
0
DomainObjectType::DomainObjectType(const std::string &json)
{
	from_json(json);
}