|
82 | 82 | } \ |
83 | 83 | } Object##type##param##RegistrationVariable |
84 | 84 |
|
| 85 | +/** |
| 86 | + * @ingroup object |
| 87 | + * @brief Explicitly instantiate a template class with one template parameter |
| 88 | + * and register the resulting instance with the TypeId system. |
| 89 | + * |
| 90 | + * This version of the macro allows the user to specify a namespace |
| 91 | + * for the template class and a different namespace for the template parameter. |
| 92 | + * |
| 93 | + * The `nst` parameter is the namespace of the templated class, which must be |
| 94 | + * in the `ns3` namespace and can be in a nested namespace, e.g., `ns3::aodv`. |
| 95 | + * Adding the leading `ns3` namespace is optional for nested namespace, while for |
| 96 | + * classes in the `ns3` namespace is mandatory. |
| 97 | + * |
| 98 | + * The `nsp` parameter is the namespace of the template parameter, and can be |
| 99 | + * any namespace, including `std`, `ns3`, or a nested namespace like `ns3::aodv`. |
| 100 | + * Also in this case, adding the leading `ns3` namespace is optional for nested |
| 101 | + * namespace, while for objects in the `ns3` namespace is mandatory. |
| 102 | + * The parameter can also be in the `std` namespace, e.g., `std::uint16_t` will have |
| 103 | + * `nsp` set to `std` and `param` to `uint16_t`. |
| 104 | + * |
| 105 | + * The result of the function ``GetTemplateClassName`` depends on these values, and |
| 106 | + * typically will be something like `ns3::nst::type<nsp::param>`. |
| 107 | + * |
| 108 | + * @sa NS_OBJECT_TEMPLATE_CLASS_DEFINE |
| 109 | + * |
| 110 | + * @note This macro must be used in the `ns3` namespace. |
| 111 | + * |
| 112 | + * @param nst the namespace of the template class |
| 113 | + * @param type the template class |
| 114 | + * @param nsp the namespace of the parameter (typically `ns3`) |
| 115 | + * @param param the first template parameter |
| 116 | + */ |
| 117 | +#define NS_OBJECT_TEMPLATE_CLASS_WITH_NS_DEFINE(nst, type, nsp, param) \ |
| 118 | + template class nst::type<nsp::param>; \ |
| 119 | + template <> \ |
| 120 | + std::string DoGetTemplateClassName<nst::type<nsp::param>>() \ |
| 121 | + { \ |
| 122 | + constexpr std::string_view prefix = "ns3::"; \ |
| 123 | + std::string cName = std::string(#nst) + "::" + #type; \ |
| 124 | + if (cName.starts_with(prefix)) \ |
| 125 | + cName.erase(0, prefix.size()); \ |
| 126 | + std::string pName = std::string(#nsp) + "::" + #param; \ |
| 127 | + if (pName.starts_with(prefix)) \ |
| 128 | + pName.erase(0, prefix.size()); \ |
| 129 | + return std::string("ns3::") + cName + std::string("<") + pName + std::string(">"); \ |
| 130 | + } \ |
| 131 | + namespace nst \ |
| 132 | + { \ |
| 133 | + static struct Object##type##nsp##param##RegistrationClass \ |
| 134 | + { \ |
| 135 | + Object##type##nsp##param##RegistrationClass() \ |
| 136 | + { \ |
| 137 | + ns3::TypeId tid = type<nsp::param>::GetTypeId(); \ |
| 138 | + tid.SetSize(sizeof(type<nsp::param>)); \ |
| 139 | + tid.GetParent(); \ |
| 140 | + } \ |
| 141 | + } Object##type##nsp##param##RegistrationVariable; \ |
| 142 | + } |
| 143 | + |
85 | 144 | /** |
86 | 145 | * @ingroup object |
87 | 146 | * @brief Explicitly instantiate a template class with two template parameters |
|
0 commit comments