Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in src/xbt/dict.cpp.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Dec 2019 21:56:21 +0000 (22:56 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Dec 2019 23:03:54 +0000 (00:03 +0100)
include/xbt/dict.h
src/xbt/dict.cpp
src/xbt/dict_cursor.c
src/xbt/dict_test.cpp

index 73b6e62..7e5b487 100644 (file)
@@ -59,7 +59,7 @@ typedef struct s_xbt_dictelm {
 
 XBT_PUBLIC xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn);
 XBT_PUBLIC void xbt_dict_free(xbt_dict_t* dict);
-XBT_PUBLIC unsigned int xbt_dict_size(xbt_dict_t dict);
+XBT_PUBLIC unsigned int xbt_dict_size(const_xbt_dict_t dict);
 
 /** @} */
 /** @defgroup XBT_dict_basic Dictionaries basic usage
@@ -71,16 +71,16 @@ XBT_PUBLIC unsigned int xbt_dict_size(xbt_dict_t dict);
  */
 
 XBT_PUBLIC void xbt_dict_set(xbt_dict_t dict, const char* key, void* data);
-XBT_PUBLIC void* xbt_dict_get(xbt_dict_t dict, const char* key);
-XBT_PUBLIC void* xbt_dict_get_or_null(xbt_dict_t dict, const char* key);
-XBT_PUBLIC char* xbt_dict_get_key(xbt_dict_t dict, const void* data);
-XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char* key);
-XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char* key);
+XBT_PUBLIC void* xbt_dict_get(const_xbt_dict_t dict, const char* key);
+XBT_PUBLIC void* xbt_dict_get_or_null(const_xbt_dict_t dict, const char* key);
+XBT_PUBLIC char* xbt_dict_get_key(const_xbt_dict_t dict, const void* data);
+XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm(const_xbt_dict_t dict, const char* key);
+XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm_or_null(const_xbt_dict_t dict, const char* key);
 
 XBT_PUBLIC void xbt_dict_remove(xbt_dict_t dict, const char* key);
 XBT_PUBLIC void xbt_dict_reset(xbt_dict_t dict);
-XBT_PUBLIC int xbt_dict_length(xbt_dict_t dict);
-XBT_PUBLIC int xbt_dict_is_empty(xbt_dict_t dict);
+XBT_PUBLIC int xbt_dict_length(const_xbt_dict_t dict);
+XBT_PUBLIC int xbt_dict_is_empty(const_xbt_dict_t dict);
 
 /** @} */
 /** @defgroup XBT_dict_nnul Dictionaries with non-nul terminated keys
@@ -91,14 +91,14 @@ XBT_PUBLIC int xbt_dict_is_empty(xbt_dict_t dict);
  *  @{
  */
 XBT_PUBLIC void xbt_dict_set_ext(xbt_dict_t dict, const char* key, int key_len, void* data);
-XBT_PUBLIC void* xbt_dict_get_ext(xbt_dict_t dict, const char* key, int key_len);
-XBT_PUBLIC void* xbt_dict_get_or_null_ext(xbt_dict_t dict, const char* key, int key_len);
+XBT_PUBLIC void* xbt_dict_get_ext(const_xbt_dict_t dict, const char* key, int key_len);
+XBT_PUBLIC void* xbt_dict_get_or_null_ext(const_xbt_dict_t dict, const char* key, int key_len);
 XBT_PUBLIC void xbt_dict_remove_ext(xbt_dict_t dict, const char* key, int key_len);
 
 struct s_xbt_dict_cursor {
   xbt_dictelm_t current;
   int line;
-  xbt_dict_t dict;
+  const_xbt_dict_t dict;
 };
 
 /** @} */
@@ -132,15 +132,15 @@ static inline xbt_dictelm_t xbt_dict_cursor_get_elm(const_xbt_dict_cursor_t curs
   return cursor->current;
 }
 
-XBT_PUBLIC xbt_dict_cursor_t xbt_dict_cursor_new(const xbt_dict_t dict);
+XBT_PUBLIC xbt_dict_cursor_t xbt_dict_cursor_new(const_xbt_dict_t dict);
 XBT_PUBLIC void xbt_dict_cursor_free(xbt_dict_cursor_t* cursor);
 
 XBT_PUBLIC void xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor);
 
-XBT_PUBLIC char* xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor);
-XBT_PUBLIC void* xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor);
+XBT_PUBLIC char* xbt_dict_cursor_get_key(const_xbt_dict_cursor_t cursor);
+XBT_PUBLIC void* xbt_dict_cursor_get_data(const_xbt_dict_cursor_t cursor);
 
-XBT_PUBLIC void xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t* cursor);
+XBT_PUBLIC void xbt_dict_cursor_first(const_xbt_dict_t dict, xbt_dict_cursor_t* cursor);
 XBT_PUBLIC void xbt_dict_cursor_step(xbt_dict_cursor_t cursor);
 XBT_PUBLIC int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t* cursor, char** key, void** data);
 /** @def xbt_dict_foreach
index 1b33417..775320b 100644 (file)
@@ -79,7 +79,7 @@ void xbt_dict_free(xbt_dict_t * dict)
 }
 
 /** Returns the amount of elements in the dict */
-unsigned int xbt_dict_size(xbt_dict_t dict)
+unsigned int xbt_dict_size(const_xbt_dict_t dict)
 {
   return (dict != nullptr ? static_cast<unsigned int>(dict->count) : static_cast<unsigned int>(0));
 }
@@ -194,7 +194,7 @@ void xbt_dict_set(xbt_dict_t dict, const char* key, void* data)
  *
  * Search the given @a key. Throws std::out_of_range when not found.
  */
-void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
+void* xbt_dict_get_ext(const_xbt_dict_t dict, const char* key, int key_len)
 {
   unsigned int hash_code = xbt_str_hash_ext(key, key_len);
   const s_xbt_dictelm* current = dict->table[hash_code & dict->table_size];
@@ -211,7 +211,7 @@ void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
 }
 
 /** @brief like xbt_dict_get_ext(), but returning nullptr when not found */
-void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
+void* xbt_dict_get_or_null_ext(const_xbt_dict_t dict, const char* key, int key_len)
 {
   unsigned int hash_code = xbt_str_hash_ext(key, key_len);
   const s_xbt_dictelm* current = dict->table[hash_code & dict->table_size];
@@ -232,7 +232,7 @@ void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
  *
  * Returns nullptr if the object cannot be found
  */
-char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
+char* xbt_dict_get_key(const_xbt_dict_t dict, const void* data)
 {
   for (int i = 0; i <= dict->table_size; i++) {
     const s_xbt_dictelm* current = dict->table[i];
@@ -255,7 +255,7 @@ char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
  * Search the given @a key. Throws std::out_of_range when not found.
  * Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
  */
-void *xbt_dict_get(xbt_dict_t dict, const char *key)
+void* xbt_dict_get(const_xbt_dict_t dict, const char* key)
 {
   return xbt_dict_get_elm(dict, key)->content;
 }
@@ -270,7 +270,7 @@ void *xbt_dict_get(xbt_dict_t dict, const char *key)
  * Search the given @a key. Throws std::out_of_range when not found.
  * Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
  */
-xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
+xbt_dictelm_t xbt_dict_get_elm(const_xbt_dict_t dict, const char* key)
 {
   xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
 
@@ -283,7 +283,7 @@ xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
 /**
  * @brief like xbt_dict_get(), but returning nullptr when not found
  */
-void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key)
+void* xbt_dict_get_or_null(const_xbt_dict_t dict, const char* key)
 {
   const s_xbt_dictelm* current = xbt_dict_get_elm_or_null(dict, key);
 
@@ -296,7 +296,7 @@ void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key)
 /**
  * @brief like xbt_dict_get_elm(), but returning nullptr when not found
  */
-xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key)
+xbt_dictelm_t xbt_dict_get_elm_or_null(const_xbt_dict_t dict, const char* key)
 {
   unsigned int hash_code = xbt_str_hash(key);
   xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
@@ -382,7 +382,7 @@ void xbt_dict_reset(xbt_dict_t dict)
  * @brief Return the number of elements in the dict.
  * @param dict a dictionary
  */
-int xbt_dict_length(xbt_dict_t dict)
+int xbt_dict_length(const_xbt_dict_t dict)
 {
   return dict->count;
 }
@@ -390,7 +390,7 @@ int xbt_dict_length(xbt_dict_t dict)
 /**
  * @brief test if the dict is empty or not
  */
-int xbt_dict_is_empty(xbt_dict_t dict)
+int xbt_dict_is_empty(const_xbt_dict_t dict)
 {
   return not dict || (xbt_dict_length(dict) == 0);
 }
index b364d32..01e544c 100644 (file)
@@ -22,7 +22,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict_cursor, xbt_dict, "To traverse dictiona
 /** @brief Creator
  *  @param dict the dict
  */
-inline xbt_dict_cursor_t xbt_dict_cursor_new(const xbt_dict_t dict)
+inline xbt_dict_cursor_t xbt_dict_cursor_new(const_xbt_dict_t dict)
 {
   xbt_dict_cursor_t res = xbt_new(struct s_xbt_dict_cursor, 1);
   res->dict = dict;
@@ -70,7 +70,7 @@ inline void xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor)
  * @param      dict   on what to let the cursor iterate
  * @param[out] cursor dest address
  */
-inline void xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t * cursor)
+inline void xbt_dict_cursor_first(const_xbt_dict_t dict, xbt_dict_cursor_t* cursor)
 {
   XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_cursor_first");
   if (!*cursor) {
@@ -146,7 +146,7 @@ inline int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t * cursor, char **key, v
  * @param cursor: the cursor
  * @returns the current key
  */
-inline char *xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor)
+inline char* xbt_dict_cursor_get_key(const_xbt_dict_cursor_t cursor)
 {
   __cursor_not_null(cursor);
 
@@ -158,7 +158,7 @@ inline char *xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor)
  * @param cursor the cursor
  * @returns the current data
  */
-inline void *xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor)
+inline void* xbt_dict_cursor_get_data(const_xbt_dict_cursor_t cursor)
 {
   __cursor_not_null(cursor);
 
index 2045fa4..f24acad 100644 (file)
@@ -49,7 +49,7 @@ static xbt_dict_t new_fixture()
   return head;
 }
 
-static void search_ext(xbt_dict_t head, const char* key, const char* data)
+static void search_ext(const_xbt_dict_t head, const char* key, const char* data)
 {
   INFO("Search " << STR(key));
   char* found = (char*)xbt_dict_get(head, key);
@@ -63,7 +63,7 @@ static void search_ext(xbt_dict_t head, const char* key, const char* data)
   }
 }
 
-static void search(xbt_dict_t head, const char* key)
+static void search(const_xbt_dict_t head, const char* key)
 {
   search_ext(head, key, key);
 }
@@ -74,7 +74,7 @@ static void debugged_remove(xbt_dict_t head, const char* key)
   xbt_dict_remove(head, key);
 }
 
-static void traverse(xbt_dict_t head)
+static void traverse(const_xbt_dict_t head)
 {
   xbt_dict_cursor_t cursor = nullptr;
   char* key;
@@ -87,13 +87,13 @@ static void traverse(xbt_dict_t head)
   }
 }
 
-static void search_not_found(xbt_dict_t head, const char* data)
+static void search_not_found(const_xbt_dict_t head, const char* data)
 {
   INFO("Search " << STR(data) << " (expected not to be found)");
   REQUIRE_THROWS_AS(xbt_dict_get(head, data), std::out_of_range);
 }
 
-static void count(xbt_dict_t dict, int length)
+static void count(const_xbt_dict_t dict, int length)
 {
   INFO("Count elements (expecting " << length << ")");
   REQUIRE(xbt_dict_length(dict) == length); // Announced length differs
@@ -108,7 +108,7 @@ static void count(xbt_dict_t dict, int length)
   REQUIRE(effective == length); // Effective length differs
 }
 
-static void count_check_get_key(xbt_dict_t dict, int length)
+static void count_check_get_key(const_xbt_dict_t dict, int length)
 {
   xbt_dict_cursor_t cursor;
   char* key;
@@ -127,7 +127,7 @@ static void count_check_get_key(xbt_dict_t dict, int length)
   REQUIRE(effective == length); // Effective length differs
 }
 
-static int countelems(xbt_dict_t head)
+static int countelems(const_xbt_dict_t head)
 {
   xbt_dict_cursor_t cursor;
   char* key;