Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/javahl/native/EnumMapper.cpp view on Meta::CPAN
svn_depth_t EnumMapper::toDepth(jobject jdepth)
{
// The offset for depths is -2
return static_cast<svn_depth_t>(getOrdinal(JAVA_PACKAGE"/types/Depth", jdepth) - 2);
}
jobject EnumMapper::mapDepth(svn_depth_t depth)
{
// We're assuming a valid value for the C enum above
// The offset for depths is -2
return mapEnum(JAVA_PACKAGE"/types/Depth", static_cast<int>(depth) + 2);
}
jobject EnumMapper::mapOperation(svn_wc_operation_t operation)
{
// We're assuming a valid value for the C enum above
return mapEnum(JAVA_PACKAGE"/ConflictDescriptor$Operation",
static_cast<int>(operation));
}
jobject EnumMapper::mapTristate(svn_tristate_t tristate)
{
// We're assuming a valid value for the C enum above
return mapEnum(JAVA_PACKAGE"/types/Tristate",
static_cast<int>(tristate - svn_tristate_false));
}
svn_wc_conflict_choice_t EnumMapper::toConflictChoice(jobject jchoice)
{
return static_cast<svn_wc_conflict_choice_t>
(getOrdinal(JAVA_PACKAGE"/ConflictResult$Choice", jchoice));
}
svn_opt_revision_kind EnumMapper::toRevisionKind(jobject jkind)
{
return static_cast<svn_opt_revision_kind>
(getOrdinal(JAVA_PACKAGE"/types/Revision$Kind", jkind));
}
jobject EnumMapper::mapSummarizeKind(svn_client_diff_summarize_kind_t sKind)
{
// We're assuming a valid value for the C enum above
return mapEnum(JAVA_PACKAGE"/DiffSummary$DiffKind",
static_cast<int>(sKind));
}
jobject EnumMapper::mapEnum(const char *clazzName, int index)
{
// The fact that we can even do this depends upon a couple of assumptions,
// mainly some knowledge about the orderin of the various constants in
// both the C and Java enums. Should those values ever change,
// the World Will End.
std::string methodSig("()[L");
methodSig.append(clazzName);
methodSig.append(";");
JNIEnv *env = JNIUtil::getEnv();
// Create a local frame for our references
env->PushLocalFrame(LOCAL_FRAME_SIZE);
if (JNIUtil::isJavaExceptionThrown())
return NULL;
jclass clazz = env->FindClass(clazzName);
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN_NULL;
jmethodID mid = env->GetStaticMethodID(clazz, "values", methodSig.c_str());
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN_NULL;
jobjectArray jvalues = (jobjectArray) env->CallStaticObjectMethod(clazz, mid);
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN_NULL;
jobject jthing = env->GetObjectArrayElement(jvalues, index);
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN_NULL;
return env->PopLocalFrame(jthing);
}
int EnumMapper::getOrdinal(const char *clazzName, jobject jenum)
{
JNIEnv *env = JNIUtil::getEnv();
// Create a local frame for our references
env->PushLocalFrame(LOCAL_FRAME_SIZE);
if (JNIUtil::isJavaExceptionThrown())
return -1;
jclass clazz = env->FindClass(clazzName);
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN(-1);
jmethodID mid = env->GetMethodID(clazz, "ordinal", "()I");
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN(-1);
jint jorder = env->CallIntMethod(jenum, mid);
if (JNIUtil::isJavaExceptionThrown())
POP_AND_RETURN(-1);
env->PopLocalFrame(NULL);
return static_cast<int>(jorder);
}
( run in 0.971 second using v1.01-cache-2.11-cpan-df04353d9ac )