Ejemplo n.º 1
0
std::vector<T> convertJArrayToNumericVector(const Pothos::Proxy &proxy)
{
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());
    switch (sig)
    {
    #define cjatnv(PrimitiveType, jtype) \
    { \
        auto ar = (jtype ## Array) std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle())->value.l; \
        std::vector<T> vec(jenv->env->GetArrayLength(ar)); \
        jtype *elems = jenv->env->Get ## PrimitiveType ## ArrayElements(ar, nullptr); \
        for (size_t i = 0; i < vec.size(); i++) vec[i] = static_cast<T>(elems[i]); \
        jenv->env->Release ## PrimitiveType ## ArrayElements(ar, elems, JNI_ABORT); \
        return vec; \
    }
    case 'Z': cjatnv(Boolean, jboolean)
    case 'C': cjatnv(Char, jchar)
    case 'B': cjatnv(Byte, jbyte)
    case 'S': cjatnv(Short, jshort)
    case 'I': cjatnv(Int, jint)
    case 'J': cjatnv(Long, jlong)
    case 'F': cjatnv(Float, jfloat)
    case 'D': cjatnv(Double, jdouble)
    }
    poco_bugcheck_msg(std::string(1, sig).c_str()); throw;
}
Ejemplo n.º 2
0
void save(Archive & ar, const Pothos::Proxy &t, const unsigned int)
{
    auto name = t.getEnvironment()->getName();
    ar << name;

    //serialize to stringstream
    std::stringstream ss;
    t.getEnvironment()->serialize(t, ss);
    const auto buff = ss.str();

    //save length and buffer
    const Poco::UInt32 length = Poco::UInt32(buff.size());
    ar << length;
    Pothos::serialization::binary_object bo((void *)buff.data(), buff.size());
    ar << bo;
}
Ejemplo n.º 3
0
static Pothos::ProxyVector convertJObjectArrayToVector(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());

    auto ar = (jobjectArray) handle->value.l;
    Pothos::ProxyVector vec(jenv->env->GetArrayLength(ar));
    for (size_t i = 0; i < vec.size(); i++)
    {
        vec[i] = jenv->makeHandle(jenv->env->GetObjectArrayElement(ar, i));
    }
    return vec;
}
Ejemplo n.º 4
0
/***********************************************************************
 * evaluate an args array (calls and constructors)
 **********************************************************************/
static std::vector<Pothos::Proxy> evalArgsArray(
    const Pothos::Proxy &evaluator,
    const Poco::JSON::Array::Ptr &argsArray,
    const size_t offset = 0)
{
    std::vector<Pothos::Proxy> args;
    if (argsArray) for (size_t i = offset; i < argsArray->size(); i++)
    {
        auto arg = argsArray->get(i).toString();
        if (argsArray->get(i).isString()) arg = "\""+arg+"\"";
        const auto obj = evaluator.call<Pothos::Object>("eval", arg);
        args.push_back(evaluator.getEnvironment()->convertObjectToProxy(obj));
    }
    return args;
}
Ejemplo n.º 5
0
static std::string convertJStringToString(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto env = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());
    return env->jstringToString(handle->value.l);
}