| 1 |
#ifndef RBIMPL_RHASH_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_RHASH_H |
| 3 |
/** |
| 4 |
* @file |
| 5 |
* @author Ruby developers <[email protected]> |
| 6 |
* @copyright This file is a part of the programming language Ruby. |
| 7 |
* Permission is hereby granted, to either redistribute and/or |
| 8 |
* modify this file, provided that the conditions mentioned in the |
| 9 |
* file COPYING are met. Consult the file for details. |
| 10 |
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are |
| 11 |
* implementation details. Don't take them as canon. They could |
| 12 |
* rapidly appear then vanish. The name (path) of this header file |
| 13 |
* is also an implementation detail. Do not expect it to persist |
| 14 |
* at the place it is now. Developers are free to move it anywhere |
| 15 |
* anytime at will. |
| 16 |
* @note To ruby-core: remember that this header can be possibly |
| 17 |
* recursively included from extension libraries written in C++. |
| 18 |
* Do not expect for instance `__VA_ARGS__` is always available. |
| 19 |
* We assume C99 for ruby itself but we don't assume languages of |
| 20 |
* extension libraries. They could be written in C++98. |
| 21 |
* @brief Routines to manipulate struct RHash. |
| 22 |
* @note The struct RHash itself is opaque. |
| 23 |
*/ |
| 24 |
#include "ruby/internal/config.h" |
| 25 |
|
| 26 |
#ifdef STDC_HEADERS |
| 27 |
# include <stddef.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#include "ruby/internal/dllexport.h" |
| 31 |
#include "ruby/internal/value.h" |
| 32 |
#if !defined RUBY_EXPORT && !defined RUBY_NO_OLD_COMPATIBILITY |
| 33 |
# include "ruby/backward.h" |
| 34 |
#endif |
| 35 |
|
| 36 |
/** |
| 37 |
* Retrieves the internal table. |
| 38 |
* |
| 39 |
* @param[in] h An instance of RHash. |
| 40 |
* @pre `h` must be of ::RUBY_T_HASH. |
| 41 |
* @return A struct st_table which has the contents of this hash. |
| 42 |
* @note Nowadays as Ruby evolved over ages, RHash has multiple backend |
| 43 |
* storage engines. `h`'s backend is not guaranteed to be a |
| 44 |
* st_table. This function creates one when necessary. |
| 45 |
*/ |
| 46 |
#define RHASH_TBL(h) rb_hash_tbl(h, __FILE__, __LINE__) |
| 47 |
|
| 48 |
/** |
| 49 |
* @private |
| 50 |
* |
| 51 |
* @deprecated This macro once was a thing in the old days, but makes no sense |
| 52 |
* any longer today. Exists here for backwards compatibility |
| 53 |
* only. You can safely forget about it. |
| 54 |
* |
| 55 |
* @internal |
| 56 |
* |
| 57 |
* Declaration of rb_hash_ifnone() is at include/ruby/backward.h. |
| 58 |
*/ |
| 59 |
#define RHASH_IFNONE(h) rb_hash_ifnone(h) |
| 60 |
|
| 61 |
/** |
| 62 |
* Queries the size of the hash. Size here means the number of keys that the |
| 63 |
* hash stores. |
| 64 |
* |
| 65 |
* @param[in] h An instance of RHash. |
| 66 |
* @pre `h` must be of ::RUBY_T_HASH. |
| 67 |
* @return The size of the hash. |
| 68 |
*/ |
| 69 |
#define RHASH_SIZE(h) rb_hash_size_num(h) |
| 70 |
|
| 71 |
/** |
| 72 |
* Checks if the hash is empty. |
| 73 |
* |
| 74 |
* @param[in] h An instance of RHash. |
| 75 |
* @pre `h` must be of ::RUBY_T_HASH. |
| 76 |
* @retval true It is. |
| 77 |
* @retval false It isn't. |
| 78 |
*/ |
| 79 |
#define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0) |
| 80 |
|
| 81 |
/** |
| 82 |
* Destructively updates the default value of the hash. |
| 83 |
* |
| 84 |
* @param[out] h An instance of RHash. |
| 85 |
* @param[in] ifnone Arbitrary default value. |
| 86 |
* @pre `h` must be of ::RUBY_T_HASH. |
| 87 |
* |
| 88 |
* @internal |
| 89 |
* |
| 90 |
* But why you can set this, given rb_hash_ifnone() doesn't exist? |
| 91 |
*/ |
| 92 |
#define RHASH_SET_IFNONE(h, ifnone) rb_hash_set_ifnone((VALUE)h, ifnone) |
| 93 |
|
| 94 |
struct st_table; /* in ruby/st.h */ |
| 95 |
|
| 96 |
RBIMPL_SYMBOL_EXPORT_BEGIN() |
| 97 |
|
| 98 |
/** |
| 99 |
* This is the implementation detail of #RHASH_SIZE. People don't call this |
| 100 |
* directly. |
| 101 |
* |
| 102 |
* @param[in] hash An instance of RHash. |
| 103 |
* @pre `hash` must be of ::RUBY_T_HASH. |
| 104 |
* @return The size of the hash. |
| 105 |
*/ |
| 106 |
size_t rb_hash_size_num(VALUE hash); |
| 107 |
|
| 108 |
/** |
| 109 |
* This is the implementation detail of #RHASH_TBL. People don't call this |
| 110 |
* directly. |
| 111 |
* |
| 112 |
* @param[in] hash An instance of RHash. |
| 113 |
* @param[in] file The `__FILE__`. |
| 114 |
* @param[in] line The `__LINE__`. |
| 115 |
* @pre `hash` must be of ::RUBY_T_HASH. |
| 116 |
* @return Table that has the contents of the hash. |
| 117 |
*/ |
| 118 |
struct st_table *rb_hash_tbl(VALUE hash, const char *file, int line); |
| 119 |
|
| 120 |
/** |
| 121 |
* This is the implementation detail of #RHASH_SET_IFNONE. People don't call |
| 122 |
* this directly. |
| 123 |
* |
| 124 |
* @param[out] hash An instance of RHash. |
| 125 |
* @param[in] ifnone Arbitrary default value. |
| 126 |
* @pre `hash` must be of ::RUBY_T_HASH. |
| 127 |
*/ |
| 128 |
VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone); |
| 129 |
RBIMPL_SYMBOL_EXPORT_END() |
| 130 |
|
| 131 |
#endif /* RBIMPL_RHASH_H */ |