1 /* 2 * Copyright (c) 2020 Endian Technologies AB 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_NET_LWM2M_PATH_H_ 8 #define ZEPHYR_INCLUDE_NET_LWM2M_PATH_H_ 9 10 /** 11 * @brief Generate LwM2M string paths using numeric components. 12 * 13 * Accepts at least one and up to four arguments. Each argument will be 14 * stringified by the pre-processor, so calling this with non-literals will 15 * likely not do what you want. For example, 16 * 17 * #define MY_OBJ_ID 3 18 * LWM2M_PATH(MY_OBJ_ID, 0, 1) 19 * 20 * would evaluate to "3/0/1", while 21 * 22 * int x = 3; 23 * LWM2M_PATH(x, 0, 1) 24 * 25 * evalutes to "x/0/1". 26 */ 27 #define LWM2M_PATH(...) \ 28 LWM2M_PATH_MACRO(__VA_ARGS__, LWM2M_PATH4, LWM2M_PATH3, \ 29 LWM2M_PATH2, LWM2M_PATH1)(__VA_ARGS__) 30 31 32 /* Internal helper macros for the LWM2M_PATH macro */ 33 #define LWM2M_PATH_VA_NUM_ARGS(...) \ 34 LWM2M_PATH_VA_NUM_ARGS_IMPL(__VA_ARGS__, 5, 4, 3, 2, 1) 35 #define LWM2M_PATH_VA_NUM_ARGS_IMPL(_1, _2, _3, _4, N, ...) N 36 37 #define LWM2M_PATH1(_x) #_x 38 #define LWM2M_PATH2(_x, _y) #_x "/" #_y 39 #define LWM2M_PATH3(_x, _y, _z) #_x "/" #_y "/" #_z 40 #define LWM2M_PATH4(_a, _x, _y, _z) #_a "/" #_x "/" #_y "/" #_z 41 42 #define LWM2M_PATH_MACRO(_1, _2, _3, _4, NAME, ...) NAME 43 44 45 46 #endif /* ZEPHYR_INCLUDE_NET_LWM2M_PATH_H_ */ 47