summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-28 15:14:22 +0100
committerHaru <haru@dotalux.com>2016-01-06 15:14:49 +0100
commitaa574e36fea903b9aea31ea6f52855498d9476a9 (patch)
tree97ee413e965791ddeb0a37d488eee3871c18d81b
parenta1b0dae953f0dde5f614f828710bcee78b5f2b78 (diff)
downloadhercules-aa574e36fea903b9aea31ea6f52855498d9476a9.tar.gz
hercules-aa574e36fea903b9aea31ea6f52855498d9476a9.tar.bz2
hercules-aa574e36fea903b9aea31ea6f52855498d9476a9.tar.xz
hercules-aa574e36fea903b9aea31ea6f52855498d9476a9.zip
Added const variants of BL_CAST/BL_UCAST: BL_CCAST/BL_UCCAST
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--src/map/map.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/map/map.h b/src/map/map.h
index f785ddc83..8a32cf361 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -843,6 +843,20 @@ typedef struct elemental_data TBL_ELEM;
( ((bl) == (struct block_list *)NULL || (bl)->type != (type_)) ? (T ## type_ *)NULL : (T ## type_ *)(bl) )
/**
+ * Casts a const block list to a specific type.
+ *
+ * @remark
+ * The `bl` argument may be evaluated more than once.
+ *
+ * @param type_ The block list type (using symbols from enum bl_type).
+ * @param bl The source block list to cast.
+ * @return The block list, cast to the correct type.
+ * @retval NULL if bl is the wrong type or NULL.
+ */
+#define BL_CCAST(type_, bl) \
+ ( ((bl) == (const struct block_list *)NULL || (bl)->type != (type_)) ? (const T ## type_ *)NULL : (const T ## type_ *)(bl) )
+
+/**
* Helper function for `BL_UCAST`.
*
* @warning
@@ -870,6 +884,34 @@ static inline struct block_list *BL_UCAST_(struct block_list *bl)
#define BL_UCAST(type_, bl) \
((T ## type_ *)BL_UCAST_(bl))
+/**
+ * Helper function for `BL_UCCAST`.
+ *
+ * @warning
+ * This function shouldn't be called on it own.
+ *
+ * The purpose of this function is to produce a compile-timer error if a non-bl
+ * object is passed to BL_UCAST. It's declared as static inline to let the
+ * compiler optimize out the function call overhead.
+ */
+static inline const struct block_list *BL_UCCAST_(const struct block_list *bl)
+{
+ return bl;
+}
+
+/**
+ * Casts a const block list to a specific type, without performing any type checks.
+ *
+ * @remark
+ * The `bl` argument is guaranteed to be evaluated once and only once.
+ *
+ * @param type_ The block list type (using symbols from enum bl_type).
+ * @param bl The source block list to cast.
+ * @return The block list, cast to the correct type.
+ */
+#define BL_UCCAST(type_, bl) \
+ ((const T ## type_ *)BL_UCCAST_(bl))
+
struct charid_request {
struct charid_request* next;
int charid;// who want to be notified of the nick