Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sort include lists according to clang-format.
[simgrid.git] / src / bindings / java / jmsg_storage.cpp
index 15bd3fe..e92d050 100644 (file)
@@ -6,15 +6,14 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/msg.h"
-#include "surf/surf_routing.h"
 
-#include "jmsg.h"
+#include "jmsg.hpp"
 #include "jmsg_storage.h"
-#include "jxbt_utilities.h"
+#include "jxbt_utilities.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
 
-SG_BEGIN_DECL()
+extern "C" {
 
 static jmethodID jstorage_method_Storage_constructor;
 static jfieldID jstorage_field_Storage_bind;
@@ -57,24 +56,24 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j
 
   /* get the C string from the java string */
   if (jname == nullptr) {
-    jxbt_throw_null(env,bprintf("No host can have a null name"));
+    jxbt_throw_null(env, "No host can have a null name");
     return nullptr;
   }
   const char *name = env->GetStringUTFChars(jname, 0);
   storage = MSG_storage_get_by_name(name);
 
-  if (!storage) {                  /* invalid name */
+  if (not storage) { /* invalid name */
     jxbt_throw_storage_not_found(env, name);
     env->ReleaseStringUTFChars(jname, name);
     return nullptr;
   }
   env->ReleaseStringUTFChars(jname, name);
 
-  if (java_storage_map.find(storage->key) == java_storage_map.end()) {
+  if (java_storage_map.find(storage) == java_storage_map.end()) {
     /* Instantiate a new java storage */
     jstorage = jstorage_new_instance(env);
 
-    if (!jstorage) {
+    if (not jstorage) {
       jxbt_throw_jni(env, "java storage instantiation failed");
       return nullptr;
     }
@@ -82,7 +81,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j
     /* get a global reference to the newly created storage */
     jstorage = jstorage_ref(env, jstorage);
 
-    if (!jstorage) {
+    if (not jstorage) {
       jxbt_throw_jni(env, "new global ref allocation failed");
       return nullptr;
     }
@@ -94,9 +93,9 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j
     /* the native storage data field is set with the global reference to the
      * java storage returned by this function
      */
-    java_storage_map.insert({storage->key, jstorage});
+    java_storage_map.insert({storage, jstorage});
   } else
-    jstorage = java_storage_map.at(storage->key);
+    jstorage = java_storage_map.at(storage);
 
   /* return the global reference to the java storage instance */
   return (jobject)jstorage;
@@ -105,7 +104,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getSize(JNIEnv * env,jobject jstorage) {
   msg_storage_t storage = jstorage_get_native(env, jstorage);
 
-  if (!storage) {
+  if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
     return -1;
   }
@@ -116,7 +115,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getSize(JNIEnv * env,jobjec
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv * env,jobject jstorage) {
   msg_storage_t storage = jstorage_get_native(env, jstorage);
 
-  if (!storage) {
+  if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
     return -1;
   }
@@ -127,7 +126,7 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getFreeSize(JNIEnv * env,jo
 JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jobject jstorage) {
   msg_storage_t storage = jstorage_get_native(env, jstorage);
 
-  if (!storage) {
+  if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
     return -1;
   }
@@ -138,14 +137,14 @@ JNIEXPORT jlong JNICALL Java_org_simgrid_msg_Storage_getUsedSize(JNIEnv * env,jo
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getProperty(JNIEnv *env, jobject jstorage, jobject jname) {
   msg_storage_t storage = jstorage_get_native(env, jstorage);
 
-  if (!storage) {
+  if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
     return nullptr;
   }
   const char *name = env->GetStringUTFChars((jstring) jname, 0);
 
   const char *property = MSG_storage_get_property_value(storage, name);
-  if (!property) {
+  if (not property) {
     return nullptr;
   }
   jobject jproperty = env->NewStringUTF(property);
@@ -159,7 +158,7 @@ JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject jname, jobject jvalue) {
   msg_storage_t storage = jstorage_get_native(env, jstorage);
 
-  if (!storage) {
+  if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
     return;
   }
@@ -177,12 +176,12 @@ Java_org_simgrid_msg_Storage_setProperty(JNIEnv *env, jobject jstorage, jobject
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getHost(JNIEnv * env,jobject jstorage) {
   msg_storage_t storage = jstorage_get_native(env, jstorage);
 
-  if (!storage) {
+  if (not storage) {
     jxbt_throw_notbound(env, "storage", jstorage);
     return nullptr;
   }
   const char *host_name = MSG_storage_get_host(storage);
-  if (!host_name) {
+  if (not host_name) {
     return nullptr;
   }
   jobject jhost_name = env->NewStringUTF(host_name);
@@ -203,21 +202,21 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jc
 
   jclass cls = jxbt_get_class(env, "org/simgrid/msg/Storage");
 
-  if (!cls) {
+  if (not cls) {
     return nullptr;
   }
 
   jtable = env->NewObjectArray((jsize) count, cls, nullptr);
 
-  if (!jtable) {
+  if (not jtable) {
     jxbt_throw_jni(env, "Storages table allocation failed");
     return nullptr;
   }
 
   for (index = 0; index < count; index++) {
     storage = xbt_dynar_get_as(table,index,msg_storage_t);
-    if (java_storage_map.find(storage->key) != java_storage_map.end()) {
-      jstorage = java_storage_map.at(storage->key);
+    if (java_storage_map.find(storage) != java_storage_map.end()) {
+      jstorage = java_storage_map.at(storage);
     } else {
       jname = env->NewStringUTF(MSG_storage_get_name(storage));
       jstorage = Java_org_simgrid_msg_Storage_getByName(env, cls_arg, jname);
@@ -228,5 +227,4 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Storage_all(JNIEnv * env, jc
   xbt_dynar_free(&table);
   return jtable;
 }
-
-SG_END_DECL()
+}