1 /******************************************************************************
2 * Top contributors (to current version):
5 * This file is part of the cvc5 project.
7 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8 * in the top-level source directory and their institutional affiliations.
9 * All rights reserved. See the file COPYING in the top-level source
10 * directory for licensing information.
11 * ****************************************************************************
16 #include "api/cpp/cvc5.h"
17 #include "api_utilities.h"
18 #include "io_github_cvc5_api_Op.h"
20 using namespace cvc5::api
;
23 * Class: io_github_cvc5_api_Op
24 * Method: deletePointer
27 JNIEXPORT
void JNICALL
Java_io_github_cvc5_api_Op_deletePointer(JNIEnv
*,
31 delete reinterpret_cast<Op
*>(pointer
);
35 * Class: io_github_cvc5_api_Op
39 JNIEXPORT jboolean JNICALL
Java_io_github_cvc5_api_Op_equals(JNIEnv
* env
,
44 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
45 Op
* op1
= reinterpret_cast<Op
*>(pointer1
);
46 Op
* op2
= reinterpret_cast<Op
*>(pointer2
);
47 // We compare the actual operators, not their pointers.
48 return static_cast<jboolean
>(*op1
== *op2
);
49 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, (jboolean
) false);
53 * Class: io_github_cvc5_api_Op
57 JNIEXPORT jint JNICALL
Java_io_github_cvc5_api_Op_getKind(JNIEnv
* env
,
61 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
62 Op
* current
= reinterpret_cast<Op
*>(pointer
);
63 return static_cast<jboolean
>(current
->getKind());
64 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, 0);
68 * Class: io_github_cvc5_api_Op
72 JNIEXPORT jboolean JNICALL
Java_io_github_cvc5_api_Op_isNull(JNIEnv
* env
,
76 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
77 Op
* current
= reinterpret_cast<Op
*>(pointer
);
78 return static_cast<jboolean
>(current
->isNull());
79 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, (jboolean
) false);
83 * Class: io_github_cvc5_api_Op
87 JNIEXPORT jboolean JNICALL
Java_io_github_cvc5_api_Op_isIndexed(JNIEnv
* env
,
91 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
92 Op
* current
= reinterpret_cast<Op
*>(pointer
);
93 return static_cast<jboolean
>(current
->isIndexed());
94 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, false);
98 * Class: io_github_cvc5_api_Op
99 * Method: getNumIndices
102 JNIEXPORT jint JNICALL
Java_io_github_cvc5_api_Op_getNumIndices(JNIEnv
* env
,
106 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
107 Op
* current
= reinterpret_cast<Op
*>(pointer
);
108 return static_cast<jint
>(current
->getNumIndices());
109 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, 0);
113 * Class: io_github_cvc5_api_Op
114 * Method: getIntegerIndices
117 JNIEXPORT jintArray JNICALL
Java_io_github_cvc5_api_Op_getIntegerIndices(
118 JNIEnv
* env
, jobject
, jlong pointer
)
120 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
121 Op
* current
= reinterpret_cast<Op
*>(pointer
);
122 size_t size
= current
->getNumIndices();
123 std::vector
<jint
> indices(size
);
126 uint32_t index
= current
->getIndices
<uint32_t>();
132 std::pair
<uint32_t, uint32_t> pair
=
133 current
->getIndices
<std::pair
<uint32_t, uint32_t>>();
134 indices
[0] = pair
.first
;
135 indices
[1] = pair
.second
;
140 std::string message
= "Unhandled case when number of indices > 2.";
141 throw CVC5ApiException(message
);
144 jintArray ret
= env
->NewIntArray((jsize
)size
);
145 env
->SetIntArrayRegion(ret
, 0, size
, indices
.data());
147 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, nullptr);
151 * Class: io_github_cvc5_api_Op
152 * Method: getStringIndices
153 * Signature: (J)[Ljava/lang/String;
155 JNIEXPORT jobjectArray JNICALL
156 Java_io_github_cvc5_api_Op_getStringIndices(JNIEnv
* env
, jobject
, jlong pointer
)
158 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
159 Op
* current
= reinterpret_cast<Op
*>(pointer
);
160 size_t size
= current
->getNumIndices();
161 std::vector
<jstring
> indices(size
);
164 std::string cIndex
= current
->getIndices
<std::string
>();
165 jstring jIndex
= env
->NewStringUTF(cIndex
.c_str());
169 if (size
> 1) // currently only one string is implemented in cvc5.cpp
171 std::string message
= "Unhandled case when number of indices > 1.";
172 throw CVC5ApiException(message
);
175 // construct a java array of String
176 jclass stringClass
= env
->FindClass("Ljava/lang/String;");
177 jobjectArray ret
= env
->NewObjectArray((jsize
)size
, stringClass
, nullptr);
178 for (size_t i
= 0; i
< size
; i
++)
180 env
->SetObjectArrayElement(ret
, i
, indices
[i
]);
183 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, nullptr);
187 * Class: io_github_cvc5_api_Op
189 * Signature: (J)Ljava/lang/String;
191 JNIEXPORT jstring JNICALL
Java_io_github_cvc5_api_Op_toString(JNIEnv
* env
,
195 CVC5_JAVA_API_TRY_CATCH_BEGIN
;
196 Op
* current
= reinterpret_cast<Op
*>(pointer
);
197 return env
->NewStringUTF(current
->toString().c_str());
198 CVC5_JAVA_API_TRY_CATCH_END_RETURN(env
, nullptr);