template<> float get(Mixed m) { return m.get_type() == type_Float ? m.get_float() : static_cast<float>(m.get_double()); }
Exemplo n.º 2
0
jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed)
{
    jclass jMixedClass = GetClassMixed(env);
    if (jMixedClass == NULL)
        return NULL;

    TR((env, "CreateJMixedFromMixed(type %d)\n", mixed.get_type()));
    switch (mixed.get_type()) {
    case type_Int:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(J)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_int());
    }
    case type_Float:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(F)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_float());
    }
    case type_Double:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(D)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_double());
    }
    case type_String:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/lang/String;)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, to_jstring(env, mixed.get_string()));
    }
    case type_Bool:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(Z)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_bool());
    }
    case type_DateTime:
        {
            time_t timeValue = mixed.get_datetime().get_datetime();
            jclass jDateClass = env->FindClass("java/util/Date");
            if (jDateClass == NULL) {
                ThrowException(env, ClassNotFound, "Date");
                return NULL;
            }
            jmethodID jDateConsId = env->GetMethodID(jDateClass, "<init>", "(J)V");
            if (jDateConsId == NULL) {
                ThrowException(env, NoSuchMethod, "Date", "<init>");
                return NULL;
            }
            jobject jDate = env->NewObject(jDateClass, jDateConsId, static_cast<jlong>(timeValue));
            jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/util/Date;)V");
            if (consId)
                return env->NewObject(jMixedClass, consId, jDate);
        }
    case type_Binary:
        {
            BinaryData binaryData = mixed.get_binary();
            jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/nio/ByteBuffer;)V");
            if (consId) {
                jobject jByteBuffer = env->NewDirectByteBuffer(const_cast<char*>(binaryData.data()), binaryData.size());
                return env->NewObject(jMixedClass, consId, jByteBuffer);
            }
        }
    case type_Table:
        {
            // param input: Table* t.
            TR((env, "   --Mixed(type_Table)\n"));
            jmethodID consId = GetMixedMethodID(env, "<init>", "(Lio/realm/internal/ColumnType;)V");

            jobject jColumnType = NULL; // GetJColumnTypeFromColumnType(env, type_Table);
            if (consId)
                return env->NewObject(jMixedClass, consId, jColumnType);
        }
    case type_Mixed:
        break;
    case type_Link:
        break;
    case type_LinkList:
        break;
    }

    return NULL;
}