diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-12-28 18:49:12 +0100 |
---|---|---|
committer | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2016-02-01 13:58:13 +0100 |
commit | aa9daa1b9dfc74deb2ab4993f74ba61ee2712f73 (patch) | |
tree | 2b83b2e2820dcb02bc5fada8a4db45bd36ef3ba2 /src/tbf.h | |
parent | 38f18698b3413bf3e608026aff519427af740335 (diff) |
tbf: Replace static casts by calls to as_ul_tbf/as_dl_tbf
Currently casts from gprs_rlcmac_tbf to gprs_rlcmac_ul_tbf and
gprs_rlcmac_dl_tbf are done by using static_cast. This doesn't provide
protection against converting a gprs_rlcmac_ul_tbf pointer to a
gprs_rlcmac_dl_tbf pointer and vice versa.
This commit provides two functions as_ul_tbf and as_dl_tbf, that
behave similar like dynamic_cast but use the direction field instead
of RTTI.
Sponsored-by: On-Waves ehf
Diffstat (limited to 'src/tbf.h')
-rw-r--r-- | src/tbf.h | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -452,6 +452,23 @@ inline enum gprs_rlcmac_tbf_direction reverse(enum gprs_rlcmac_tbf_direction dir return (enum gprs_rlcmac_tbf_direction) ((int)GPRS_RLCMAC_UL_TBF - (int)dir + (int)GPRS_RLCMAC_DL_TBF); } + +inline gprs_rlcmac_ul_tbf *as_ul_tbf(gprs_rlcmac_tbf *tbf) +{ + if (tbf && tbf->direction == GPRS_RLCMAC_UL_TBF) + return static_cast<gprs_rlcmac_ul_tbf *>(tbf); + else + return NULL; +} + +inline gprs_rlcmac_dl_tbf *as_dl_tbf(gprs_rlcmac_tbf *tbf) +{ + if (tbf && tbf->direction == GPRS_RLCMAC_DL_TBF) + return static_cast<gprs_rlcmac_dl_tbf *>(tbf); + else + return NULL; +} + #endif #ifdef __cplusplus |