summaryrefslogtreecommitdiff
path: root/src/map/map.h
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-06 17:36:33 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-06 17:36:33 +0300
commitd5199cee806fb9f18987dea0c3a20a2d381927ca (patch)
tree135f15dadc1c7964b3078fd8223771f94d1ed0e6 /src/map/map.h
parent756be9835054a3b2b8ebace388546fa15ffd4a92 (diff)
parente3eac134b1607cfe78331e298aaa20b260662571 (diff)
downloadhercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.tar.gz
hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.tar.bz2
hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.tar.xz
hercules-d5199cee806fb9f18987dea0c3a20a2d381927ca.zip
Merge pull request #1034 from HerculesWS/bl_cast
Changed all TBL_* to the appropriate structs
Diffstat (limited to 'src/map/map.h')
-rw-r--r--src/map/map.h101
1 files changed, 93 insertions, 8 deletions
diff --git a/src/map/map.h b/src/map/map.h
index 7047feab6..4c74d352c 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -828,8 +828,89 @@ typedef struct homun_data TBL_HOM;
typedef struct mercenary_data TBL_MER;
typedef struct elemental_data TBL_ELEM;
+/**
+ * Casts a 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_CAST(type_, bl) \
- ( ((bl) == (struct block_list*)NULL || (bl)->type != (type_)) ? (T ## type_ *)NULL : (T ## type_ *)(bl) )
+ ( ((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
+ * 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 struct block_list *BL_UCAST_(struct block_list *bl)
+{
+ return bl;
+}
+
+/**
+ * Casts a 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_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;
@@ -1029,13 +1110,17 @@ END_ZEROED_BLOCK;
int (*vforeachininstance)(int (*func)(struct block_list*,va_list), int16 instance_id, int type, va_list ap);
int (*foreachininstance)(int (*func)(struct block_list*,va_list), int16 instance_id, int type,...);
- struct map_session_data * (*id2sd) (int id);
- struct mob_data * (*id2md) (int id);
- struct npc_data * (*id2nd) (int id);
- struct homun_data* (*id2hd) (int id);
- struct mercenary_data* (*id2mc) (int id);
- struct chat_data* (*id2cd) (int id);
- struct block_list * (*id2bl) (int id);
+ struct map_session_data *(*id2sd) (int id);
+ struct npc_data *(*id2nd) (int id);
+ struct mob_data *(*id2md) (int id);
+ struct flooritem_data *(*id2fi) (int id);
+ struct chat_data *(*id2cd) (int id);
+ struct skill_unit *(*id2su) (int id);
+ struct pet_data *(*id2pd) (int id);
+ struct homun_data *(*id2hd) (int id);
+ struct mercenary_data *(*id2mc) (int id);
+ struct elemental_data *(*id2ed) (int id);
+ struct block_list *(*id2bl) (int id);
bool (*blid_exists) (int id);
int16 (*mapindex2mapid) (unsigned short map_index);
int16 (*mapname2mapid) (const char* name);