| 1 | /* |
| 2 | * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP |
| 8 | #define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <type_traits> |
| 12 | |
| 13 | #include <babeltrace2/babeltrace.h> |
| 14 | |
| 15 | #include "common/assert.h" |
| 16 | #include "cpp-common/bt2s/optional.hpp" |
| 17 | |
| 18 | #include "borrowed-object-iterator.hpp" |
| 19 | #include "borrowed-object.hpp" |
| 20 | #include "exc.hpp" |
| 21 | #include "field-path.hpp" |
| 22 | #include "integer-range-set.hpp" |
| 23 | #include "internal/utils.hpp" |
| 24 | #include "optional-borrowed-object.hpp" |
| 25 | #include "shared-object.hpp" |
| 26 | #include "value.hpp" |
| 27 | |
| 28 | namespace bt2 { |
| 29 | namespace internal { |
| 30 | |
| 31 | struct FieldClassRefFuncs final |
| 32 | { |
| 33 | static void get(const bt_field_class * const libObjPtr) noexcept |
| 34 | { |
| 35 | bt_field_class_get_ref(libObjPtr); |
| 36 | } |
| 37 | |
| 38 | static void put(const bt_field_class * const libObjPtr) noexcept |
| 39 | { |
| 40 | bt_field_class_put_ref(libObjPtr); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | template <typename LibObjT> |
| 45 | struct CommonFieldClassSpec; |
| 46 | |
| 47 | /* Functions specific to mutable field classes */ |
| 48 | template <> |
| 49 | struct CommonFieldClassSpec<bt_field_class> final |
| 50 | { |
| 51 | static bt_value *userAttributes(bt_field_class * const libObjPtr) noexcept |
| 52 | { |
| 53 | return bt_field_class_borrow_user_attributes(libObjPtr); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | /* Functions specific to constant field classes */ |
| 58 | template <> |
| 59 | struct CommonFieldClassSpec<const bt_field_class> final |
| 60 | { |
| 61 | static const bt_value *userAttributes(const bt_field_class * const libObjPtr) noexcept |
| 62 | { |
| 63 | return bt_field_class_borrow_user_attributes_const(libObjPtr); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | } /* namespace internal */ |
| 68 | |
| 69 | template <typename ObjT, typename LibObjT> |
| 70 | using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>; |
| 71 | |
| 72 | template <typename LibObjT> |
| 73 | class CommonBitArrayFieldClass; |
| 74 | |
| 75 | template <typename LibObjT> |
| 76 | class CommonIntegerFieldClass; |
| 77 | |
| 78 | template <typename LibObjT> |
| 79 | class ConstEnumerationFieldClassMapping; |
| 80 | |
| 81 | template <typename LibObjT> |
| 82 | class CommonBaseEnumerationFieldClass; |
| 83 | |
| 84 | template <typename LibObjT, typename MappingT> |
| 85 | class CommonEnumerationFieldClass; |
| 86 | |
| 87 | template <typename LibObjT> |
| 88 | class CommonStructureFieldClass; |
| 89 | |
| 90 | template <typename LibObjT> |
| 91 | class CommonArrayFieldClass; |
| 92 | |
| 93 | template <typename LibObjT> |
| 94 | class CommonStaticArrayFieldClass; |
| 95 | |
| 96 | template <typename LibObjT> |
| 97 | class CommonDynamicArrayWithLengthFieldClass; |
| 98 | |
| 99 | template <typename LibObjT> |
| 100 | class CommonOptionFieldClass; |
| 101 | |
| 102 | template <typename LibObjT> |
| 103 | class CommonOptionWithSelectorFieldClass; |
| 104 | |
| 105 | template <typename LibObjT> |
| 106 | class CommonOptionWithBoolSelectorFieldClass; |
| 107 | |
| 108 | template <typename LibObjT> |
| 109 | class CommonVariantFieldClass; |
| 110 | |
| 111 | template <typename LibObjT, typename RangeSetT> |
| 112 | class CommonOptionWithIntegerSelectorFieldClass; |
| 113 | |
| 114 | template <typename LibObjT> |
| 115 | class CommonVariantWithoutSelectorFieldClass; |
| 116 | |
| 117 | template <typename LibObjT> |
| 118 | class CommonVariantWithSelectorFieldClass; |
| 119 | |
| 120 | template <typename LibObjT> |
| 121 | class ConstVariantWithIntegerSelectorFieldClassOption; |
| 122 | |
| 123 | template <typename LibObjT, typename RangeSetT> |
| 124 | class CommonVariantWithIntegerSelectorFieldClass; |
| 125 | |
| 126 | template <typename LibObjT> |
| 127 | class CommonEventClass; |
| 128 | |
| 129 | template <typename LibObjT> |
| 130 | class CommonStreamClass; |
| 131 | |
| 132 | template <typename LibObjT> |
| 133 | class CommonTraceClass; |
| 134 | |
| 135 | enum class FieldClassType |
| 136 | { |
| 137 | BOOL = BT_FIELD_CLASS_TYPE_BOOL, |
| 138 | BIT_ARRAY = BT_FIELD_CLASS_TYPE_BIT_ARRAY, |
| 139 | UNSIGNED_INTEGER = BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER, |
| 140 | SIGNED_INTEGER = BT_FIELD_CLASS_TYPE_SIGNED_INTEGER, |
| 141 | UNSIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
| 142 | SIGNED_ENUMERATION = BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
| 143 | SINGLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, |
| 144 | DOUBLE_PRECISION_REAL = BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, |
| 145 | STRING = BT_FIELD_CLASS_TYPE_STRING, |
| 146 | STRUCTURE = BT_FIELD_CLASS_TYPE_STRUCTURE, |
| 147 | STATIC_ARRAY = BT_FIELD_CLASS_TYPE_STATIC_ARRAY, |
| 148 | DYNAMIC_ARRAY_WITHOUT_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD, |
| 149 | DYNAMIC_ARRAY_WITH_LENGTH = BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, |
| 150 | OPTION_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD, |
| 151 | OPTION_WITH_BOOL_SELECTOR = BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, |
| 152 | OPTION_WITH_UNSIGNED_INTEGER_SELECTOR = |
| 153 | BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
| 154 | OPTION_WITH_SIGNED_INTEGER_SELECTOR = |
| 155 | BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
| 156 | VARIANT_WITHOUT_SELECTOR = BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD, |
| 157 | VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR = |
| 158 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
| 159 | VARIANT_WITH_SIGNED_INTEGER_SELECTOR = |
| 160 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
| 161 | }; |
| 162 | |
| 163 | template <typename LibObjT> |
| 164 | class CommonFieldClass : public BorrowedObject<LibObjT> |
| 165 | { |
| 166 | private: |
| 167 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 168 | |
| 169 | protected: |
| 170 | using _ThisCommonFieldClass = CommonFieldClass<LibObjT>; |
| 171 | |
| 172 | public: |
| 173 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 174 | using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>; |
| 175 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 176 | |
| 177 | explicit CommonFieldClass(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr} |
| 178 | { |
| 179 | } |
| 180 | |
| 181 | template <typename OtherLibObjT> |
| 182 | CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObject {fc} |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | template <typename OtherLibObjT> |
| 187 | CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept |
| 188 | { |
| 189 | _ThisBorrowedObject::operator=(fc); |
| 190 | return *this; |
| 191 | } |
| 192 | |
| 193 | CommonFieldClass<const bt_field_class> asConst() const noexcept |
| 194 | { |
| 195 | return CommonFieldClass<const bt_field_class> {*this}; |
| 196 | } |
| 197 | |
| 198 | FieldClassType type() const noexcept |
| 199 | { |
| 200 | return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr())); |
| 201 | } |
| 202 | |
| 203 | bool isBool() const noexcept |
| 204 | { |
| 205 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BOOL); |
| 206 | } |
| 207 | |
| 208 | bool isBitArray() const noexcept |
| 209 | { |
| 210 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_BIT_ARRAY); |
| 211 | } |
| 212 | |
| 213 | bool isInteger() const noexcept |
| 214 | { |
| 215 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_INTEGER); |
| 216 | } |
| 217 | |
| 218 | bool isUnsignedInteger() const noexcept |
| 219 | { |
| 220 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
| 221 | } |
| 222 | |
| 223 | bool isSignedInteger() const noexcept |
| 224 | { |
| 225 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); |
| 226 | } |
| 227 | |
| 228 | bool isEnumeration() const noexcept |
| 229 | { |
| 230 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ENUMERATION); |
| 231 | } |
| 232 | |
| 233 | bool isUnsignedEnumeration() const noexcept |
| 234 | { |
| 235 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); |
| 236 | } |
| 237 | |
| 238 | bool isSignedEnumeration() const noexcept |
| 239 | { |
| 240 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); |
| 241 | } |
| 242 | |
| 243 | bool isReal() const noexcept |
| 244 | { |
| 245 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_REAL); |
| 246 | } |
| 247 | |
| 248 | bool isSinglePrecisionReal() const noexcept |
| 249 | { |
| 250 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL); |
| 251 | } |
| 252 | |
| 253 | bool isDoublePrecisionReal() const noexcept |
| 254 | { |
| 255 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL); |
| 256 | } |
| 257 | |
| 258 | bool isString() const noexcept |
| 259 | { |
| 260 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRING); |
| 261 | } |
| 262 | |
| 263 | bool isStructure() const noexcept |
| 264 | { |
| 265 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STRUCTURE); |
| 266 | } |
| 267 | |
| 268 | bool isArray() const noexcept |
| 269 | { |
| 270 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_ARRAY); |
| 271 | } |
| 272 | |
| 273 | bool isStaticArray() const noexcept |
| 274 | { |
| 275 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_STATIC_ARRAY); |
| 276 | } |
| 277 | |
| 278 | bool isDynamicArray() const noexcept |
| 279 | { |
| 280 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY); |
| 281 | } |
| 282 | |
| 283 | bool isDynamicArrayWithoutLength() const noexcept |
| 284 | { |
| 285 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD); |
| 286 | } |
| 287 | |
| 288 | bool isDynamicArrayWithLength() const noexcept |
| 289 | { |
| 290 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD); |
| 291 | } |
| 292 | |
| 293 | bool isOption() const noexcept |
| 294 | { |
| 295 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION); |
| 296 | } |
| 297 | |
| 298 | bool isOptionWithoutSelector() const noexcept |
| 299 | { |
| 300 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD); |
| 301 | } |
| 302 | |
| 303 | bool isOptionWithSelector() const noexcept |
| 304 | { |
| 305 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SELECTOR_FIELD); |
| 306 | } |
| 307 | |
| 308 | bool isOptionWithBoolSelector() const noexcept |
| 309 | { |
| 310 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD); |
| 311 | } |
| 312 | |
| 313 | bool isOptionWithIntegerSelector() const noexcept |
| 314 | { |
| 315 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_INTEGER_SELECTOR_FIELD); |
| 316 | } |
| 317 | |
| 318 | bool isOptionWithUnsignedIntegerSelector() const noexcept |
| 319 | { |
| 320 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); |
| 321 | } |
| 322 | |
| 323 | bool isOptionWithSignedIntegerSelector() const noexcept |
| 324 | { |
| 325 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD); |
| 326 | } |
| 327 | |
| 328 | bool isVariant() const noexcept |
| 329 | { |
| 330 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT); |
| 331 | } |
| 332 | |
| 333 | bool isVariantWithoutSelector() const noexcept |
| 334 | { |
| 335 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD); |
| 336 | } |
| 337 | |
| 338 | bool isVariantWithSelector() const noexcept |
| 339 | { |
| 340 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD); |
| 341 | } |
| 342 | |
| 343 | bool isVariantWithIntegerSelector() const noexcept |
| 344 | { |
| 345 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_INTEGER_SELECTOR_FIELD); |
| 346 | } |
| 347 | |
| 348 | bool isVariantWithUnsignedIntegerSelector() const noexcept |
| 349 | { |
| 350 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); |
| 351 | } |
| 352 | |
| 353 | bool isVariantWithSignedIntegerSelector() const noexcept |
| 354 | { |
| 355 | return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD); |
| 356 | } |
| 357 | |
| 358 | template <typename FieldClassT> |
| 359 | FieldClassT as() const noexcept |
| 360 | { |
| 361 | return FieldClassT {this->libObjPtr()}; |
| 362 | } |
| 363 | |
| 364 | CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept; |
| 365 | CommonIntegerFieldClass<LibObjT> asInteger() const noexcept; |
| 366 | CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept; |
| 367 | CommonEnumerationFieldClass<LibObjT, ConstEnumerationFieldClassMapping< |
| 368 | const bt_field_class_enumeration_unsigned_mapping>> |
| 369 | asUnsignedEnumeration() const noexcept; |
| 370 | |
| 371 | CommonEnumerationFieldClass< |
| 372 | LibObjT, ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>> |
| 373 | asSignedEnumeration() const noexcept; |
| 374 | |
| 375 | CommonStructureFieldClass<LibObjT> asStructure() const noexcept; |
| 376 | CommonArrayFieldClass<LibObjT> asArray() const noexcept; |
| 377 | CommonStaticArrayFieldClass<LibObjT> asStaticArray() const noexcept; |
| 378 | CommonDynamicArrayWithLengthFieldClass<LibObjT> asDynamicArrayWithLength() const noexcept; |
| 379 | CommonOptionFieldClass<LibObjT> asOption() const noexcept; |
| 380 | CommonOptionWithSelectorFieldClass<LibObjT> asOptionWithSelector() const noexcept; |
| 381 | CommonOptionWithBoolSelectorFieldClass<LibObjT> asOptionWithBoolSelector() const noexcept; |
| 382 | |
| 383 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> |
| 384 | asOptionWithUnsignedIntegerSelector() const noexcept; |
| 385 | |
| 386 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> |
| 387 | asOptionWithSignedIntegerSelector() const noexcept; |
| 388 | |
| 389 | CommonVariantFieldClass<LibObjT> asVariant() const noexcept; |
| 390 | CommonVariantWithoutSelectorFieldClass<LibObjT> asVariantWithoutSelector() const noexcept; |
| 391 | CommonVariantWithSelectorFieldClass<LibObjT> asVariantWithSelector() const noexcept; |
| 392 | |
| 393 | CommonVariantWithIntegerSelectorFieldClass< |
| 394 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< |
| 395 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>> |
| 396 | asVariantWithUnsignedIntegerSelector() const noexcept; |
| 397 | |
| 398 | CommonVariantWithIntegerSelectorFieldClass< |
| 399 | LibObjT, ConstVariantWithIntegerSelectorFieldClassOption< |
| 400 | const bt_field_class_variant_with_selector_field_integer_signed_option>> |
| 401 | asVariantWithSignedIntegerSelector() const noexcept; |
| 402 | |
| 403 | template <typename LibValT> |
| 404 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 405 | { |
| 406 | static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstFieldClass`."); |
| 407 | |
| 408 | bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 409 | } |
| 410 | |
| 411 | UserAttributes userAttributes() const noexcept |
| 412 | { |
| 413 | return UserAttributes { |
| 414 | internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())}; |
| 415 | } |
| 416 | |
| 417 | Shared shared() const noexcept |
| 418 | { |
| 419 | return Shared::createWithRef(*this); |
| 420 | } |
| 421 | |
| 422 | protected: |
| 423 | bool _libTypeIs(const bt_field_class_type type) const noexcept |
| 424 | { |
| 425 | return bt_field_class_type_is(bt_field_class_get_type(this->libObjPtr()), type); |
| 426 | } |
| 427 | }; |
| 428 | |
| 429 | using FieldClass = CommonFieldClass<bt_field_class>; |
| 430 | using ConstFieldClass = CommonFieldClass<const bt_field_class>; |
| 431 | |
| 432 | namespace internal { |
| 433 | |
| 434 | struct FieldClassTypeDescr |
| 435 | { |
| 436 | using Const = ConstFieldClass; |
| 437 | using NonConst = FieldClass; |
| 438 | }; |
| 439 | |
| 440 | template <> |
| 441 | struct TypeDescr<FieldClass> : public FieldClassTypeDescr |
| 442 | { |
| 443 | }; |
| 444 | |
| 445 | template <> |
| 446 | struct TypeDescr<ConstFieldClass> : public FieldClassTypeDescr |
| 447 | { |
| 448 | }; |
| 449 | |
| 450 | } /* namespace internal */ |
| 451 | |
| 452 | template <typename LibObjT> |
| 453 | class CommonBitArrayFieldClass final : public CommonFieldClass<LibObjT> |
| 454 | { |
| 455 | private: |
| 456 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 457 | |
| 458 | public: |
| 459 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 460 | using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>; |
| 461 | |
| 462 | explicit CommonBitArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 463 | _ThisCommonFieldClass {libObjPtr} |
| 464 | { |
| 465 | BT_ASSERT_DBG(this->isBitArray()); |
| 466 | } |
| 467 | |
| 468 | template <typename OtherLibObjT> |
| 469 | CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept : |
| 470 | _ThisCommonFieldClass {fc} |
| 471 | { |
| 472 | } |
| 473 | |
| 474 | template <typename OtherLibObjT> |
| 475 | CommonBitArrayFieldClass<LibObjT> |
| 476 | operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept |
| 477 | { |
| 478 | _ThisCommonFieldClass::operator=(fc); |
| 479 | return *this; |
| 480 | } |
| 481 | |
| 482 | CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept |
| 483 | { |
| 484 | return CommonBitArrayFieldClass<const bt_field_class> {*this}; |
| 485 | } |
| 486 | |
| 487 | std::uint64_t length() const noexcept |
| 488 | { |
| 489 | return bt_field_class_bit_array_get_length(this->libObjPtr()); |
| 490 | } |
| 491 | |
| 492 | Shared shared() const noexcept |
| 493 | { |
| 494 | return Shared::createWithRef(*this); |
| 495 | } |
| 496 | }; |
| 497 | |
| 498 | using BitArrayFieldClass = CommonBitArrayFieldClass<bt_field_class>; |
| 499 | using ConstBitArrayFieldClass = CommonBitArrayFieldClass<const bt_field_class>; |
| 500 | |
| 501 | namespace internal { |
| 502 | |
| 503 | struct BitArrayFieldClassTypeDescr |
| 504 | { |
| 505 | using Const = ConstBitArrayFieldClass; |
| 506 | using NonConst = BitArrayFieldClass; |
| 507 | }; |
| 508 | |
| 509 | template <> |
| 510 | struct TypeDescr<BitArrayFieldClass> : public BitArrayFieldClassTypeDescr |
| 511 | { |
| 512 | }; |
| 513 | |
| 514 | template <> |
| 515 | struct TypeDescr<ConstBitArrayFieldClass> : public BitArrayFieldClassTypeDescr |
| 516 | { |
| 517 | }; |
| 518 | |
| 519 | } /* namespace internal */ |
| 520 | |
| 521 | enum class DisplayBase |
| 522 | { |
| 523 | BINARY = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY, |
| 524 | OCTAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL, |
| 525 | DECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL, |
| 526 | HEXADECIMAL = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL, |
| 527 | }; |
| 528 | |
| 529 | template <typename LibObjT> |
| 530 | class CommonIntegerFieldClass : public CommonFieldClass<LibObjT> |
| 531 | { |
| 532 | private: |
| 533 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 534 | |
| 535 | protected: |
| 536 | using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>; |
| 537 | |
| 538 | public: |
| 539 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 540 | using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>; |
| 541 | |
| 542 | explicit CommonIntegerFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 543 | _ThisCommonFieldClass {libObjPtr} |
| 544 | { |
| 545 | BT_ASSERT_DBG(this->isInteger()); |
| 546 | } |
| 547 | |
| 548 | template <typename OtherLibObjT> |
| 549 | CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept : |
| 550 | _ThisCommonFieldClass {fc} |
| 551 | { |
| 552 | } |
| 553 | |
| 554 | template <typename OtherLibObjT> |
| 555 | CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept |
| 556 | { |
| 557 | _ThisCommonFieldClass::operator=(fc); |
| 558 | return *this; |
| 559 | } |
| 560 | |
| 561 | CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept |
| 562 | { |
| 563 | return CommonIntegerFieldClass<const bt_field_class> {*this}; |
| 564 | } |
| 565 | |
| 566 | void fieldValueRange(const std::uint64_t n) const noexcept |
| 567 | { |
| 568 | static_assert(!std::is_const<LibObjT>::value, |
| 569 | "Not available with `bt2::ConstIntegerFieldClass`."); |
| 570 | |
| 571 | bt_field_class_integer_set_field_value_range(this->libObjPtr(), n); |
| 572 | } |
| 573 | |
| 574 | std::uint64_t fieldValueRange() const noexcept |
| 575 | { |
| 576 | return bt_field_class_integer_get_field_value_range(this->libObjPtr()); |
| 577 | } |
| 578 | |
| 579 | void preferredDisplayBase(const DisplayBase base) const noexcept |
| 580 | { |
| 581 | static_assert(!std::is_const<LibObjT>::value, |
| 582 | "Not available with `bt2::ConstIntegerFieldClass`."); |
| 583 | |
| 584 | bt_field_class_integer_set_preferred_display_base( |
| 585 | this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base)); |
| 586 | } |
| 587 | |
| 588 | DisplayBase preferredDisplayBase() const noexcept |
| 589 | { |
| 590 | return static_cast<DisplayBase>( |
| 591 | bt_field_class_integer_get_preferred_display_base(this->libObjPtr())); |
| 592 | } |
| 593 | |
| 594 | Shared shared() const noexcept |
| 595 | { |
| 596 | return Shared::createWithRef(*this); |
| 597 | } |
| 598 | }; |
| 599 | |
| 600 | using IntegerFieldClass = CommonIntegerFieldClass<bt_field_class>; |
| 601 | using ConstIntegerFieldClass = CommonIntegerFieldClass<const bt_field_class>; |
| 602 | |
| 603 | namespace internal { |
| 604 | |
| 605 | struct IntegerFieldClassTypeDescr |
| 606 | { |
| 607 | using Const = ConstIntegerFieldClass; |
| 608 | using NonConst = IntegerFieldClass; |
| 609 | }; |
| 610 | |
| 611 | template <> |
| 612 | struct TypeDescr<IntegerFieldClass> : public IntegerFieldClassTypeDescr |
| 613 | { |
| 614 | }; |
| 615 | |
| 616 | template <> |
| 617 | struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr |
| 618 | { |
| 619 | }; |
| 620 | |
| 621 | template <typename LibObjT> |
| 622 | struct ConstEnumerationFieldClassMappingSpec; |
| 623 | |
| 624 | /* Functions specific to unsigned enumeration field class mappings */ |
| 625 | template <> |
| 626 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_unsigned_mapping> |
| 627 | final |
| 628 | { |
| 629 | static const bt_integer_range_set_unsigned * |
| 630 | ranges(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept |
| 631 | { |
| 632 | return bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(libObjPtr); |
| 633 | } |
| 634 | |
| 635 | static const char * |
| 636 | label(const bt_field_class_enumeration_unsigned_mapping * const libObjPtr) noexcept |
| 637 | { |
| 638 | return bt_field_class_enumeration_mapping_get_label( |
| 639 | bt_field_class_enumeration_unsigned_mapping_as_mapping_const(libObjPtr)); |
| 640 | } |
| 641 | }; |
| 642 | |
| 643 | /* Functions specific to signed enumeration field class mappings */ |
| 644 | template <> |
| 645 | struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_signed_mapping> final |
| 646 | { |
| 647 | static const bt_integer_range_set_signed * |
| 648 | ranges(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept |
| 649 | { |
| 650 | return bt_field_class_enumeration_signed_mapping_borrow_ranges_const(libObjPtr); |
| 651 | } |
| 652 | |
| 653 | static const char * |
| 654 | label(const bt_field_class_enumeration_signed_mapping * const libObjPtr) noexcept |
| 655 | { |
| 656 | return bt_field_class_enumeration_mapping_get_label( |
| 657 | bt_field_class_enumeration_signed_mapping_as_mapping_const(libObjPtr)); |
| 658 | } |
| 659 | }; |
| 660 | |
| 661 | } /* namespace internal */ |
| 662 | |
| 663 | template <typename LibObjT> |
| 664 | class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT> |
| 665 | { |
| 666 | private: |
| 667 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 668 | |
| 669 | public: |
| 670 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 671 | |
| 672 | using RangeSet = typename std::conditional< |
| 673 | std::is_same<LibObjT, const bt_field_class_enumeration_unsigned_mapping>::value, |
| 674 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; |
| 675 | |
| 676 | explicit ConstEnumerationFieldClassMapping(const LibObjPtr libObjPtr) noexcept : |
| 677 | _ThisBorrowedObject {libObjPtr} |
| 678 | { |
| 679 | } |
| 680 | |
| 681 | ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept : |
| 682 | _ThisBorrowedObject {mapping} |
| 683 | { |
| 684 | } |
| 685 | |
| 686 | ConstEnumerationFieldClassMapping |
| 687 | operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept |
| 688 | { |
| 689 | _ThisBorrowedObject::operator=(mapping); |
| 690 | return *this; |
| 691 | } |
| 692 | |
| 693 | RangeSet ranges() const noexcept |
| 694 | { |
| 695 | return RangeSet { |
| 696 | internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())}; |
| 697 | } |
| 698 | |
| 699 | const char *label() const noexcept |
| 700 | { |
| 701 | return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr()); |
| 702 | } |
| 703 | }; |
| 704 | |
| 705 | using ConstUnsignedEnumerationFieldClassMapping = |
| 706 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_unsigned_mapping>; |
| 707 | |
| 708 | using ConstSignedEnumerationFieldClassMapping = |
| 709 | ConstEnumerationFieldClassMapping<const bt_field_class_enumeration_signed_mapping>; |
| 710 | |
| 711 | namespace internal { |
| 712 | |
| 713 | template <typename MappingT> |
| 714 | struct CommonEnumerationFieldClassSpec; |
| 715 | |
| 716 | /* Functions specific to unsigned enumeration field classes */ |
| 717 | template <> |
| 718 | struct CommonEnumerationFieldClassSpec<ConstUnsignedEnumerationFieldClassMapping> final |
| 719 | { |
| 720 | static const bt_field_class_enumeration_unsigned_mapping * |
| 721 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 722 | { |
| 723 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(libObjPtr, index); |
| 724 | } |
| 725 | |
| 726 | static const bt_field_class_enumeration_unsigned_mapping * |
| 727 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept |
| 728 | { |
| 729 | return bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(libObjPtr, label); |
| 730 | } |
| 731 | |
| 732 | static bt_field_class_enumeration_add_mapping_status |
| 733 | addMapping(bt_field_class * const libObjPtr, const char * const label, |
| 734 | const bt_integer_range_set_unsigned * const libRanges) noexcept |
| 735 | { |
| 736 | return bt_field_class_enumeration_unsigned_add_mapping(libObjPtr, label, libRanges); |
| 737 | } |
| 738 | }; |
| 739 | |
| 740 | /* Functions specific to signed enumeration field classes */ |
| 741 | template <> |
| 742 | struct CommonEnumerationFieldClassSpec<ConstSignedEnumerationFieldClassMapping> final |
| 743 | { |
| 744 | static const bt_field_class_enumeration_signed_mapping * |
| 745 | mappingByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 746 | { |
| 747 | return bt_field_class_enumeration_signed_borrow_mapping_by_index_const(libObjPtr, index); |
| 748 | } |
| 749 | |
| 750 | static const bt_field_class_enumeration_signed_mapping * |
| 751 | mappingByLabel(const bt_field_class * const libObjPtr, const char * const label) noexcept |
| 752 | { |
| 753 | return bt_field_class_enumeration_signed_borrow_mapping_by_label_const(libObjPtr, label); |
| 754 | } |
| 755 | |
| 756 | static bt_field_class_enumeration_add_mapping_status |
| 757 | addMapping(bt_field_class * const libObjPtr, const char * const label, |
| 758 | const bt_integer_range_set_signed * const libRanges) noexcept |
| 759 | { |
| 760 | return bt_field_class_enumeration_signed_add_mapping(libObjPtr, label, libRanges); |
| 761 | } |
| 762 | }; |
| 763 | |
| 764 | } /* namespace internal */ |
| 765 | |
| 766 | template <typename LibObjT> |
| 767 | class CommonBaseEnumerationFieldClass : public CommonIntegerFieldClass<LibObjT> |
| 768 | { |
| 769 | private: |
| 770 | using typename CommonIntegerFieldClass<LibObjT>::_ThisCommonIntegerFieldClass; |
| 771 | |
| 772 | protected: |
| 773 | using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>; |
| 774 | |
| 775 | public: |
| 776 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 777 | using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>; |
| 778 | |
| 779 | explicit CommonBaseEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 780 | _ThisCommonIntegerFieldClass {libObjPtr} |
| 781 | { |
| 782 | BT_ASSERT_DBG(this->isEnumeration()); |
| 783 | } |
| 784 | |
| 785 | template <typename OtherLibObjT> |
| 786 | CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept |
| 787 | : |
| 788 | _ThisCommonIntegerFieldClass {fc} |
| 789 | { |
| 790 | } |
| 791 | |
| 792 | template <typename OtherLibObjT> |
| 793 | CommonBaseEnumerationFieldClass |
| 794 | operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept |
| 795 | { |
| 796 | _ThisCommonIntegerFieldClass::operator=(fc); |
| 797 | return *this; |
| 798 | } |
| 799 | |
| 800 | CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept |
| 801 | { |
| 802 | return CommonBaseEnumerationFieldClass<const bt_field_class> {*this}; |
| 803 | } |
| 804 | |
| 805 | std::uint64_t length() const noexcept |
| 806 | { |
| 807 | return bt_field_class_enumeration_get_mapping_count(this->libObjPtr()); |
| 808 | } |
| 809 | |
| 810 | Shared shared() const noexcept |
| 811 | { |
| 812 | return Shared::createWithRef(*this); |
| 813 | } |
| 814 | }; |
| 815 | |
| 816 | template <typename LibObjT, typename MappingT> |
| 817 | class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass<LibObjT> |
| 818 | { |
| 819 | private: |
| 820 | using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass; |
| 821 | |
| 822 | public: |
| 823 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 824 | using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>; |
| 825 | using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>; |
| 826 | using Mapping = MappingT; |
| 827 | |
| 828 | explicit CommonEnumerationFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 829 | _ThisCommonBaseEnumerationFieldClass {libObjPtr} |
| 830 | { |
| 831 | BT_ASSERT_DBG(this->isEnumeration()); |
| 832 | } |
| 833 | |
| 834 | template <typename OtherLibObjT> |
| 835 | CommonEnumerationFieldClass( |
| 836 | const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept : |
| 837 | CommonEnumerationFieldClass {fc} |
| 838 | { |
| 839 | } |
| 840 | |
| 841 | template <typename OtherLibObjT> |
| 842 | CommonEnumerationFieldClass |
| 843 | operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept |
| 844 | { |
| 845 | CommonEnumerationFieldClass::operator=(fc); |
| 846 | return *this; |
| 847 | } |
| 848 | |
| 849 | Mapping operator[](const std::uint64_t index) const noexcept |
| 850 | { |
| 851 | return Mapping {internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByIndex( |
| 852 | this->libObjPtr(), index)}; |
| 853 | } |
| 854 | |
| 855 | OptionalBorrowedObject<Mapping> operator[](const char * const label) const noexcept |
| 856 | { |
| 857 | return internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel( |
| 858 | this->libObjPtr(), label); |
| 859 | } |
| 860 | |
| 861 | OptionalBorrowedObject<Mapping> operator[](const std::string& label) const noexcept |
| 862 | { |
| 863 | return (*this)[label.data()]; |
| 864 | } |
| 865 | |
| 866 | void addMapping(const char * const label, const typename Mapping::RangeSet ranges) const |
| 867 | { |
| 868 | const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping( |
| 869 | this->libObjPtr(), label, ranges.libObjPtr()); |
| 870 | |
| 871 | if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) { |
| 872 | throw MemoryError {}; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | void addMapping(const std::string& label, const typename Mapping::RangeSet ranges) const |
| 877 | { |
| 878 | this->addMapping(label.data(), ranges); |
| 879 | } |
| 880 | |
| 881 | Iterator begin() const noexcept |
| 882 | { |
| 883 | return Iterator {*this, 0}; |
| 884 | } |
| 885 | |
| 886 | Iterator end() const noexcept |
| 887 | { |
| 888 | return Iterator {*this, this->length()}; |
| 889 | } |
| 890 | |
| 891 | Shared shared() const noexcept |
| 892 | { |
| 893 | return Shared::createWithRef(*this); |
| 894 | } |
| 895 | }; |
| 896 | |
| 897 | using EnumerationFieldClass = CommonBaseEnumerationFieldClass<bt_field_class>; |
| 898 | using ConstEnumerationFieldClass = CommonBaseEnumerationFieldClass<const bt_field_class>; |
| 899 | |
| 900 | using UnsignedEnumerationFieldClass = |
| 901 | CommonEnumerationFieldClass<bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; |
| 902 | |
| 903 | using ConstUnsignedEnumerationFieldClass = |
| 904 | CommonEnumerationFieldClass<const bt_field_class, ConstUnsignedEnumerationFieldClassMapping>; |
| 905 | |
| 906 | using SignedEnumerationFieldClass = |
| 907 | CommonEnumerationFieldClass<bt_field_class, ConstSignedEnumerationFieldClassMapping>; |
| 908 | |
| 909 | using ConstSignedEnumerationFieldClass = |
| 910 | CommonEnumerationFieldClass<const bt_field_class, ConstSignedEnumerationFieldClassMapping>; |
| 911 | |
| 912 | namespace internal { |
| 913 | |
| 914 | struct UnsignedEnumerationFieldClassTypeDescr |
| 915 | { |
| 916 | using Const = ConstUnsignedEnumerationFieldClass; |
| 917 | using NonConst = UnsignedEnumerationFieldClass; |
| 918 | }; |
| 919 | |
| 920 | template <> |
| 921 | struct TypeDescr<UnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr |
| 922 | { |
| 923 | }; |
| 924 | |
| 925 | template <> |
| 926 | struct TypeDescr<ConstUnsignedEnumerationFieldClass> : public UnsignedEnumerationFieldClassTypeDescr |
| 927 | { |
| 928 | }; |
| 929 | |
| 930 | struct SignedEnumerationFieldClassTypeDescr |
| 931 | { |
| 932 | using Const = ConstSignedEnumerationFieldClass; |
| 933 | using NonConst = SignedEnumerationFieldClass; |
| 934 | }; |
| 935 | |
| 936 | template <> |
| 937 | struct TypeDescr<SignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr |
| 938 | { |
| 939 | }; |
| 940 | |
| 941 | template <> |
| 942 | struct TypeDescr<ConstSignedEnumerationFieldClass> : public SignedEnumerationFieldClassTypeDescr |
| 943 | { |
| 944 | }; |
| 945 | |
| 946 | template <typename LibObjT> |
| 947 | struct CommonStructureFieldClassMemberSpec; |
| 948 | |
| 949 | /* Functions specific to mutable structure field class members */ |
| 950 | template <> |
| 951 | struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> final |
| 952 | { |
| 953 | static bt_field_class *fieldClass(bt_field_class_structure_member * const libObjPtr) noexcept |
| 954 | { |
| 955 | return bt_field_class_structure_member_borrow_field_class(libObjPtr); |
| 956 | } |
| 957 | |
| 958 | static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept |
| 959 | { |
| 960 | return bt_field_class_structure_member_borrow_user_attributes(libObjPtr); |
| 961 | } |
| 962 | }; |
| 963 | |
| 964 | /* Functions specific to constant structure field class members */ |
| 965 | template <> |
| 966 | struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member> final |
| 967 | { |
| 968 | static const bt_field_class * |
| 969 | fieldClass(const bt_field_class_structure_member * const libObjPtr) noexcept |
| 970 | { |
| 971 | return bt_field_class_structure_member_borrow_field_class_const(libObjPtr); |
| 972 | } |
| 973 | |
| 974 | static const bt_value * |
| 975 | userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept |
| 976 | { |
| 977 | return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr); |
| 978 | } |
| 979 | }; |
| 980 | |
| 981 | } /* namespace internal */ |
| 982 | |
| 983 | template <typename LibObjT> |
| 984 | class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT> |
| 985 | { |
| 986 | private: |
| 987 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 988 | using _FieldClass = internal::DepFc<LibObjT>; |
| 989 | |
| 990 | public: |
| 991 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 992 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 993 | |
| 994 | explicit CommonStructureFieldClassMember(const LibObjPtr libObjPtr) noexcept : |
| 995 | _ThisBorrowedObject {libObjPtr} |
| 996 | { |
| 997 | } |
| 998 | |
| 999 | template <typename OtherLibObjT> |
| 1000 | CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
| 1001 | : |
| 1002 | _ThisBorrowedObject {fc} |
| 1003 | { |
| 1004 | } |
| 1005 | |
| 1006 | template <typename OtherLibObjT> |
| 1007 | CommonStructureFieldClassMember<LibObjT> |
| 1008 | operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept |
| 1009 | { |
| 1010 | _ThisBorrowedObject::operator=(fc); |
| 1011 | return *this; |
| 1012 | } |
| 1013 | |
| 1014 | CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept |
| 1015 | { |
| 1016 | return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this}; |
| 1017 | } |
| 1018 | |
| 1019 | const char *name() const noexcept |
| 1020 | { |
| 1021 | return bt_field_class_structure_member_get_name(this->libObjPtr()); |
| 1022 | } |
| 1023 | |
| 1024 | _FieldClass fieldClass() const noexcept |
| 1025 | { |
| 1026 | return _FieldClass { |
| 1027 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
| 1028 | } |
| 1029 | |
| 1030 | template <typename LibValT> |
| 1031 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1032 | { |
| 1033 | static_assert(!std::is_const<LibObjT>::value, |
| 1034 | "Not available with `bt2::ConstStructureFieldClassMember`."); |
| 1035 | |
| 1036 | bt_field_class_structure_member_set_user_attributes(this->libObjPtr(), |
| 1037 | userAttrs.libObjPtr()); |
| 1038 | } |
| 1039 | |
| 1040 | UserAttributes userAttributes() const noexcept |
| 1041 | { |
| 1042 | return UserAttributes { |
| 1043 | internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes( |
| 1044 | this->libObjPtr())}; |
| 1045 | } |
| 1046 | }; |
| 1047 | |
| 1048 | using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>; |
| 1049 | |
| 1050 | using ConstStructureFieldClassMember = |
| 1051 | CommonStructureFieldClassMember<const bt_field_class_structure_member>; |
| 1052 | |
| 1053 | namespace internal { |
| 1054 | |
| 1055 | struct StructureFieldClassMemberTypeDescr |
| 1056 | { |
| 1057 | using Const = ConstStructureFieldClassMember; |
| 1058 | using NonConst = StructureFieldClassMember; |
| 1059 | }; |
| 1060 | |
| 1061 | template <> |
| 1062 | struct TypeDescr<StructureFieldClassMember> : public StructureFieldClassMemberTypeDescr |
| 1063 | { |
| 1064 | }; |
| 1065 | |
| 1066 | template <> |
| 1067 | struct TypeDescr<ConstStructureFieldClassMember> : public StructureFieldClassMemberTypeDescr |
| 1068 | { |
| 1069 | }; |
| 1070 | |
| 1071 | template <typename LibObjT> |
| 1072 | struct CommonStructureFieldClassSpec; |
| 1073 | |
| 1074 | /* Functions specific to mutable structure field classes */ |
| 1075 | template <> |
| 1076 | struct CommonStructureFieldClassSpec<bt_field_class> final |
| 1077 | { |
| 1078 | static bt_field_class_structure_member *memberByIndex(bt_field_class * const libObjPtr, |
| 1079 | const std::uint64_t index) noexcept |
| 1080 | { |
| 1081 | return bt_field_class_structure_borrow_member_by_index(libObjPtr, index); |
| 1082 | } |
| 1083 | |
| 1084 | static bt_field_class_structure_member *memberByName(bt_field_class * const libObjPtr, |
| 1085 | const char * const name) noexcept |
| 1086 | { |
| 1087 | return bt_field_class_structure_borrow_member_by_name(libObjPtr, name); |
| 1088 | } |
| 1089 | }; |
| 1090 | |
| 1091 | /* Functions specific to constant structure field classes */ |
| 1092 | template <> |
| 1093 | struct CommonStructureFieldClassSpec<const bt_field_class> final |
| 1094 | { |
| 1095 | static const bt_field_class_structure_member * |
| 1096 | memberByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 1097 | { |
| 1098 | return bt_field_class_structure_borrow_member_by_index_const(libObjPtr, index); |
| 1099 | } |
| 1100 | |
| 1101 | static const bt_field_class_structure_member * |
| 1102 | memberByName(const bt_field_class * const libObjPtr, const char * const name) noexcept |
| 1103 | { |
| 1104 | return bt_field_class_structure_borrow_member_by_name_const(libObjPtr, name); |
| 1105 | } |
| 1106 | }; |
| 1107 | |
| 1108 | } /* namespace internal */ |
| 1109 | |
| 1110 | template <typename LibObjT> |
| 1111 | class CommonStructureFieldClass final : public CommonFieldClass<LibObjT> |
| 1112 | { |
| 1113 | private: |
| 1114 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 1115 | |
| 1116 | public: |
| 1117 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1118 | using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>; |
| 1119 | using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>; |
| 1120 | |
| 1121 | using Member = |
| 1122 | internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>; |
| 1123 | |
| 1124 | explicit CommonStructureFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1125 | _ThisCommonFieldClass {libObjPtr} |
| 1126 | { |
| 1127 | BT_ASSERT_DBG(this->isStructure()); |
| 1128 | } |
| 1129 | |
| 1130 | template <typename OtherLibObjT> |
| 1131 | CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept : |
| 1132 | _ThisCommonFieldClass {fc} |
| 1133 | { |
| 1134 | } |
| 1135 | |
| 1136 | template <typename OtherLibObjT> |
| 1137 | CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept |
| 1138 | { |
| 1139 | _ThisCommonFieldClass::operator=(fc); |
| 1140 | return *this; |
| 1141 | } |
| 1142 | |
| 1143 | CommonStructureFieldClass<const bt_field_class> asConst() const noexcept |
| 1144 | { |
| 1145 | return CommonStructureFieldClass<const bt_field_class> {*this}; |
| 1146 | } |
| 1147 | |
| 1148 | void appendMember(const char * const name, const FieldClass fc) const |
| 1149 | { |
| 1150 | static_assert(!std::is_const<LibObjT>::value, |
| 1151 | "Not available with `bt2::ConstStructureFieldClass`."); |
| 1152 | |
| 1153 | const auto status = |
| 1154 | bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr()); |
| 1155 | |
| 1156 | if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) { |
| 1157 | throw MemoryError {}; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | void appendMember(const std::string& name, const FieldClass fc) const |
| 1162 | { |
| 1163 | this->appendMember(name.data(), fc); |
| 1164 | } |
| 1165 | |
| 1166 | std::uint64_t length() const noexcept |
| 1167 | { |
| 1168 | return bt_field_class_structure_get_member_count(this->libObjPtr()); |
| 1169 | } |
| 1170 | |
| 1171 | Iterator begin() const noexcept |
| 1172 | { |
| 1173 | return Iterator {*this, 0}; |
| 1174 | } |
| 1175 | |
| 1176 | Iterator end() const noexcept |
| 1177 | { |
| 1178 | return Iterator {*this, this->length()}; |
| 1179 | } |
| 1180 | |
| 1181 | Member operator[](const std::uint64_t index) const noexcept |
| 1182 | { |
| 1183 | return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex( |
| 1184 | this->libObjPtr(), index)}; |
| 1185 | } |
| 1186 | |
| 1187 | OptionalBorrowedObject<Member> operator[](const char * const name) const noexcept |
| 1188 | { |
| 1189 | return internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), |
| 1190 | name); |
| 1191 | } |
| 1192 | |
| 1193 | OptionalBorrowedObject<Member> operator[](const std::string& name) const noexcept |
| 1194 | { |
| 1195 | return (*this)[name.data()]; |
| 1196 | } |
| 1197 | |
| 1198 | Shared shared() const noexcept |
| 1199 | { |
| 1200 | return Shared::createWithRef(*this); |
| 1201 | } |
| 1202 | }; |
| 1203 | |
| 1204 | using StructureFieldClass = CommonStructureFieldClass<bt_field_class>; |
| 1205 | using ConstStructureFieldClass = CommonStructureFieldClass<const bt_field_class>; |
| 1206 | |
| 1207 | namespace internal { |
| 1208 | |
| 1209 | struct StructureFieldClassTypeDescr |
| 1210 | { |
| 1211 | using Const = ConstStructureFieldClass; |
| 1212 | using NonConst = StructureFieldClass; |
| 1213 | }; |
| 1214 | |
| 1215 | template <> |
| 1216 | struct TypeDescr<StructureFieldClass> : public StructureFieldClassTypeDescr |
| 1217 | { |
| 1218 | }; |
| 1219 | |
| 1220 | template <> |
| 1221 | struct TypeDescr<ConstStructureFieldClass> : public StructureFieldClassTypeDescr |
| 1222 | { |
| 1223 | }; |
| 1224 | |
| 1225 | template <typename LibObjT> |
| 1226 | struct CommonArrayFieldClassSpec; |
| 1227 | |
| 1228 | /* Functions specific to mutable array field classes */ |
| 1229 | template <> |
| 1230 | struct CommonArrayFieldClassSpec<bt_field_class> final |
| 1231 | { |
| 1232 | static bt_field_class *elementFieldClass(bt_field_class * const libObjPtr) noexcept |
| 1233 | { |
| 1234 | return bt_field_class_array_borrow_element_field_class(libObjPtr); |
| 1235 | } |
| 1236 | }; |
| 1237 | |
| 1238 | /* Functions specific to constant array field classes */ |
| 1239 | template <> |
| 1240 | struct CommonArrayFieldClassSpec<const bt_field_class> final |
| 1241 | { |
| 1242 | static const bt_field_class *elementFieldClass(const bt_field_class * const libObjPtr) noexcept |
| 1243 | { |
| 1244 | return bt_field_class_array_borrow_element_field_class_const(libObjPtr); |
| 1245 | } |
| 1246 | }; |
| 1247 | |
| 1248 | } /* namespace internal */ |
| 1249 | |
| 1250 | template <typename LibObjT> |
| 1251 | class CommonArrayFieldClass : public CommonFieldClass<LibObjT> |
| 1252 | { |
| 1253 | private: |
| 1254 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 1255 | using _FieldClass = internal::DepFc<LibObjT>; |
| 1256 | |
| 1257 | protected: |
| 1258 | using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>; |
| 1259 | |
| 1260 | public: |
| 1261 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1262 | using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>; |
| 1263 | |
| 1264 | explicit CommonArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1265 | _ThisCommonFieldClass {libObjPtr} |
| 1266 | { |
| 1267 | BT_ASSERT_DBG(this->isArray()); |
| 1268 | } |
| 1269 | |
| 1270 | template <typename OtherLibObjT> |
| 1271 | CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept : |
| 1272 | _ThisCommonFieldClass {fc} |
| 1273 | { |
| 1274 | } |
| 1275 | |
| 1276 | template <typename OtherLibObjT> |
| 1277 | CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept |
| 1278 | { |
| 1279 | _ThisCommonFieldClass::operator=(fc); |
| 1280 | return *this; |
| 1281 | } |
| 1282 | |
| 1283 | CommonArrayFieldClass<const bt_field_class> asConst() const noexcept |
| 1284 | { |
| 1285 | return CommonArrayFieldClass<const bt_field_class> {*this}; |
| 1286 | } |
| 1287 | |
| 1288 | _FieldClass elementFieldClass() const noexcept |
| 1289 | { |
| 1290 | return _FieldClass { |
| 1291 | internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())}; |
| 1292 | } |
| 1293 | |
| 1294 | Shared shared() const noexcept |
| 1295 | { |
| 1296 | return Shared::createWithRef(*this); |
| 1297 | } |
| 1298 | }; |
| 1299 | |
| 1300 | using ArrayFieldClass = CommonArrayFieldClass<bt_field_class>; |
| 1301 | using ConstArrayFieldClass = CommonArrayFieldClass<const bt_field_class>; |
| 1302 | |
| 1303 | namespace internal { |
| 1304 | |
| 1305 | struct ArrayFieldClassTypeDescr |
| 1306 | { |
| 1307 | using Const = ConstArrayFieldClass; |
| 1308 | using NonConst = ArrayFieldClass; |
| 1309 | }; |
| 1310 | |
| 1311 | template <> |
| 1312 | struct TypeDescr<ArrayFieldClass> : public ArrayFieldClassTypeDescr |
| 1313 | { |
| 1314 | }; |
| 1315 | |
| 1316 | template <> |
| 1317 | struct TypeDescr<ConstArrayFieldClass> : public ArrayFieldClassTypeDescr |
| 1318 | { |
| 1319 | }; |
| 1320 | |
| 1321 | } /* namespace internal */ |
| 1322 | |
| 1323 | template <typename LibObjT> |
| 1324 | class CommonStaticArrayFieldClass final : public CommonArrayFieldClass<LibObjT> |
| 1325 | { |
| 1326 | private: |
| 1327 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; |
| 1328 | |
| 1329 | public: |
| 1330 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1331 | using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>; |
| 1332 | |
| 1333 | explicit CommonStaticArrayFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1334 | _ThisCommonArrayFieldClass {libObjPtr} |
| 1335 | { |
| 1336 | BT_ASSERT_DBG(this->isStaticArray()); |
| 1337 | } |
| 1338 | |
| 1339 | template <typename OtherLibObjT> |
| 1340 | CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept : |
| 1341 | _ThisCommonArrayFieldClass {fc} |
| 1342 | { |
| 1343 | } |
| 1344 | |
| 1345 | template <typename OtherLibObjT> |
| 1346 | CommonStaticArrayFieldClass |
| 1347 | operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept |
| 1348 | { |
| 1349 | _ThisCommonArrayFieldClass::operator=(fc); |
| 1350 | return *this; |
| 1351 | } |
| 1352 | |
| 1353 | CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept |
| 1354 | { |
| 1355 | return CommonStaticArrayFieldClass<const bt_field_class> {*this}; |
| 1356 | } |
| 1357 | |
| 1358 | std::uint64_t length() const noexcept |
| 1359 | { |
| 1360 | return bt_field_class_array_static_get_length(this->libObjPtr()); |
| 1361 | } |
| 1362 | |
| 1363 | Shared shared() const noexcept |
| 1364 | { |
| 1365 | return Shared::createWithRef(*this); |
| 1366 | } |
| 1367 | }; |
| 1368 | |
| 1369 | using StaticArrayFieldClass = CommonStaticArrayFieldClass<bt_field_class>; |
| 1370 | using ConstStaticArrayFieldClass = CommonStaticArrayFieldClass<const bt_field_class>; |
| 1371 | |
| 1372 | namespace internal { |
| 1373 | |
| 1374 | struct StaticArrayFieldClassTypeDescr |
| 1375 | { |
| 1376 | using Const = ConstStaticArrayFieldClass; |
| 1377 | using NonConst = StaticArrayFieldClass; |
| 1378 | }; |
| 1379 | |
| 1380 | template <> |
| 1381 | struct TypeDescr<StaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr |
| 1382 | { |
| 1383 | }; |
| 1384 | |
| 1385 | template <> |
| 1386 | struct TypeDescr<ConstStaticArrayFieldClass> : public StaticArrayFieldClassTypeDescr |
| 1387 | { |
| 1388 | }; |
| 1389 | |
| 1390 | } /* namespace internal */ |
| 1391 | |
| 1392 | template <typename LibObjT> |
| 1393 | class CommonDynamicArrayWithLengthFieldClass final : public CommonArrayFieldClass<LibObjT> |
| 1394 | { |
| 1395 | private: |
| 1396 | using typename CommonArrayFieldClass<LibObjT>::_ThisCommonArrayFieldClass; |
| 1397 | |
| 1398 | public: |
| 1399 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1400 | using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>; |
| 1401 | |
| 1402 | explicit CommonDynamicArrayWithLengthFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1403 | _ThisCommonArrayFieldClass {libObjPtr} |
| 1404 | { |
| 1405 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); |
| 1406 | } |
| 1407 | |
| 1408 | template <typename OtherLibObjT> |
| 1409 | CommonDynamicArrayWithLengthFieldClass( |
| 1410 | const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept : |
| 1411 | _ThisCommonArrayFieldClass {fc} |
| 1412 | { |
| 1413 | } |
| 1414 | |
| 1415 | template <typename OtherLibObjT> |
| 1416 | CommonDynamicArrayWithLengthFieldClass |
| 1417 | operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept |
| 1418 | { |
| 1419 | _ThisCommonArrayFieldClass::operator=(fc); |
| 1420 | return *this; |
| 1421 | } |
| 1422 | |
| 1423 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept |
| 1424 | { |
| 1425 | return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this}; |
| 1426 | } |
| 1427 | |
| 1428 | ConstFieldPath lengthFieldPath() const noexcept |
| 1429 | { |
| 1430 | return ConstFieldPath { |
| 1431 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( |
| 1432 | this->libObjPtr())}; |
| 1433 | } |
| 1434 | |
| 1435 | Shared shared() const noexcept |
| 1436 | { |
| 1437 | return Shared::createWithRef(*this); |
| 1438 | } |
| 1439 | }; |
| 1440 | |
| 1441 | using DynamicArrayWithLengthFieldClass = CommonDynamicArrayWithLengthFieldClass<bt_field_class>; |
| 1442 | |
| 1443 | using ConstDynamicArrayWithLengthFieldClass = |
| 1444 | CommonDynamicArrayWithLengthFieldClass<const bt_field_class>; |
| 1445 | |
| 1446 | namespace internal { |
| 1447 | |
| 1448 | struct DynamicArrayWithLengthFieldClassTypeDescr |
| 1449 | { |
| 1450 | using Const = ConstDynamicArrayWithLengthFieldClass; |
| 1451 | using NonConst = DynamicArrayWithLengthFieldClass; |
| 1452 | }; |
| 1453 | |
| 1454 | template <> |
| 1455 | struct TypeDescr<DynamicArrayWithLengthFieldClass> : |
| 1456 | public DynamicArrayWithLengthFieldClassTypeDescr |
| 1457 | { |
| 1458 | }; |
| 1459 | |
| 1460 | template <> |
| 1461 | struct TypeDescr<ConstDynamicArrayWithLengthFieldClass> : |
| 1462 | public DynamicArrayWithLengthFieldClassTypeDescr |
| 1463 | { |
| 1464 | }; |
| 1465 | |
| 1466 | template <typename LibObjT> |
| 1467 | struct CommonOptionFieldClassSpec; |
| 1468 | |
| 1469 | /* Functions specific to mutable option field classes */ |
| 1470 | template <> |
| 1471 | struct CommonOptionFieldClassSpec<bt_field_class> final |
| 1472 | { |
| 1473 | static bt_field_class *fieldClass(bt_field_class * const libObjPtr) noexcept |
| 1474 | { |
| 1475 | return bt_field_class_option_borrow_field_class(libObjPtr); |
| 1476 | } |
| 1477 | }; |
| 1478 | |
| 1479 | /* Functions specific to constant option field classes */ |
| 1480 | template <> |
| 1481 | struct CommonOptionFieldClassSpec<const bt_field_class> final |
| 1482 | { |
| 1483 | static const bt_field_class *fieldClass(const bt_field_class * const libObjPtr) noexcept |
| 1484 | { |
| 1485 | return bt_field_class_option_borrow_field_class_const(libObjPtr); |
| 1486 | } |
| 1487 | }; |
| 1488 | |
| 1489 | } /* namespace internal */ |
| 1490 | |
| 1491 | template <typename LibObjT> |
| 1492 | class CommonOptionFieldClass : public CommonFieldClass<LibObjT> |
| 1493 | { |
| 1494 | private: |
| 1495 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 1496 | using _FieldClass = internal::DepFc<LibObjT>; |
| 1497 | |
| 1498 | protected: |
| 1499 | using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>; |
| 1500 | |
| 1501 | public: |
| 1502 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1503 | using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>; |
| 1504 | |
| 1505 | explicit CommonOptionFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1506 | _ThisCommonFieldClass {libObjPtr} |
| 1507 | { |
| 1508 | BT_ASSERT_DBG(this->isOption()); |
| 1509 | } |
| 1510 | |
| 1511 | template <typename OtherLibObjT> |
| 1512 | CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept : |
| 1513 | _ThisCommonFieldClass {fc} |
| 1514 | { |
| 1515 | } |
| 1516 | |
| 1517 | template <typename OtherLibObjT> |
| 1518 | CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept |
| 1519 | { |
| 1520 | _ThisCommonFieldClass::operator=(fc); |
| 1521 | return *this; |
| 1522 | } |
| 1523 | |
| 1524 | CommonOptionFieldClass<const bt_field_class> asConst() const noexcept |
| 1525 | { |
| 1526 | return CommonOptionFieldClass<const bt_field_class> {*this}; |
| 1527 | } |
| 1528 | |
| 1529 | _FieldClass fieldClass() const noexcept |
| 1530 | { |
| 1531 | return _FieldClass { |
| 1532 | internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
| 1533 | } |
| 1534 | |
| 1535 | Shared shared() const noexcept |
| 1536 | { |
| 1537 | return Shared::createWithRef(*this); |
| 1538 | } |
| 1539 | }; |
| 1540 | |
| 1541 | using OptionFieldClass = CommonOptionFieldClass<bt_field_class>; |
| 1542 | using ConstOptionFieldClass = CommonOptionFieldClass<const bt_field_class>; |
| 1543 | |
| 1544 | namespace internal { |
| 1545 | |
| 1546 | struct OptionFieldClassTypeDescr |
| 1547 | { |
| 1548 | using Const = ConstOptionFieldClass; |
| 1549 | using NonConst = OptionFieldClass; |
| 1550 | }; |
| 1551 | |
| 1552 | template <> |
| 1553 | struct TypeDescr<OptionFieldClass> : public OptionFieldClassTypeDescr |
| 1554 | { |
| 1555 | }; |
| 1556 | |
| 1557 | template <> |
| 1558 | struct TypeDescr<ConstOptionFieldClass> : public OptionFieldClassTypeDescr |
| 1559 | { |
| 1560 | }; |
| 1561 | |
| 1562 | } /* namespace internal */ |
| 1563 | |
| 1564 | template <typename LibObjT> |
| 1565 | class CommonOptionWithSelectorFieldClass : public CommonOptionFieldClass<LibObjT> |
| 1566 | { |
| 1567 | private: |
| 1568 | using typename CommonOptionFieldClass<LibObjT>::_ThisCommonOptionFieldClass; |
| 1569 | |
| 1570 | protected: |
| 1571 | using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>; |
| 1572 | |
| 1573 | public: |
| 1574 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1575 | using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>; |
| 1576 | |
| 1577 | explicit CommonOptionWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1578 | _ThisCommonOptionFieldClass {libObjPtr} |
| 1579 | { |
| 1580 | BT_ASSERT_DBG(this->isOptionWithSelector()); |
| 1581 | } |
| 1582 | |
| 1583 | template <typename OtherLibObjT> |
| 1584 | CommonOptionWithSelectorFieldClass( |
| 1585 | const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 1586 | _ThisCommonOptionFieldClass {fc} |
| 1587 | { |
| 1588 | } |
| 1589 | |
| 1590 | template <typename OtherLibObjT> |
| 1591 | CommonOptionWithSelectorFieldClass |
| 1592 | operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 1593 | { |
| 1594 | _ThisCommonOptionFieldClass::operator=(fc); |
| 1595 | return *this; |
| 1596 | } |
| 1597 | |
| 1598 | CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 1599 | { |
| 1600 | return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this}; |
| 1601 | } |
| 1602 | |
| 1603 | ConstFieldPath selectorFieldPath() const noexcept |
| 1604 | { |
| 1605 | return ConstFieldPath { |
| 1606 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( |
| 1607 | this->libObjPtr())}; |
| 1608 | } |
| 1609 | |
| 1610 | Shared shared() const noexcept |
| 1611 | { |
| 1612 | return Shared::createWithRef(*this); |
| 1613 | } |
| 1614 | }; |
| 1615 | |
| 1616 | using OptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<bt_field_class>; |
| 1617 | using ConstOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<const bt_field_class>; |
| 1618 | |
| 1619 | namespace internal { |
| 1620 | |
| 1621 | struct OptionWithSelectorFieldClassTypeDescr |
| 1622 | { |
| 1623 | using Const = ConstOptionWithSelectorFieldClass; |
| 1624 | using NonConst = OptionWithSelectorFieldClass; |
| 1625 | }; |
| 1626 | |
| 1627 | template <> |
| 1628 | struct TypeDescr<OptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr |
| 1629 | { |
| 1630 | }; |
| 1631 | |
| 1632 | template <> |
| 1633 | struct TypeDescr<ConstOptionWithSelectorFieldClass> : public OptionWithSelectorFieldClassTypeDescr |
| 1634 | { |
| 1635 | }; |
| 1636 | |
| 1637 | } /* namespace internal */ |
| 1638 | |
| 1639 | template <typename LibObjT> |
| 1640 | class CommonOptionWithBoolSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> |
| 1641 | { |
| 1642 | private: |
| 1643 | using typename CommonOptionWithSelectorFieldClass< |
| 1644 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; |
| 1645 | |
| 1646 | public: |
| 1647 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1648 | using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>; |
| 1649 | |
| 1650 | explicit CommonOptionWithBoolSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1651 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
| 1652 | { |
| 1653 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); |
| 1654 | } |
| 1655 | |
| 1656 | template <typename OtherLibObjT> |
| 1657 | CommonOptionWithBoolSelectorFieldClass( |
| 1658 | const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 1659 | _ThisCommonOptionWithSelectorFieldClass {fc} |
| 1660 | { |
| 1661 | } |
| 1662 | |
| 1663 | template <typename OtherLibObjT> |
| 1664 | CommonOptionWithBoolSelectorFieldClass |
| 1665 | operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 1666 | { |
| 1667 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); |
| 1668 | return *this; |
| 1669 | } |
| 1670 | |
| 1671 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 1672 | { |
| 1673 | return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this}; |
| 1674 | } |
| 1675 | |
| 1676 | bool selectorIsReversed() const noexcept |
| 1677 | { |
| 1678 | return bt_field_class_option_with_selector_field_bool_selector_is_reversed( |
| 1679 | this->libObjPtr()); |
| 1680 | } |
| 1681 | |
| 1682 | Shared shared() const noexcept |
| 1683 | { |
| 1684 | return Shared::createWithRef(*this); |
| 1685 | } |
| 1686 | }; |
| 1687 | |
| 1688 | using OptionWithBoolSelectorFieldClass = CommonOptionWithBoolSelectorFieldClass<bt_field_class>; |
| 1689 | |
| 1690 | using ConstOptionWithBoolSelectorFieldClass = |
| 1691 | CommonOptionWithBoolSelectorFieldClass<const bt_field_class>; |
| 1692 | |
| 1693 | namespace internal { |
| 1694 | |
| 1695 | struct OptionWithBoolSelectorFieldClassTypeDescr |
| 1696 | { |
| 1697 | using Const = ConstOptionWithBoolSelectorFieldClass; |
| 1698 | using NonConst = OptionWithBoolSelectorFieldClass; |
| 1699 | }; |
| 1700 | |
| 1701 | template <> |
| 1702 | struct TypeDescr<OptionWithBoolSelectorFieldClass> : |
| 1703 | public OptionWithBoolSelectorFieldClassTypeDescr |
| 1704 | { |
| 1705 | }; |
| 1706 | |
| 1707 | template <> |
| 1708 | struct TypeDescr<ConstOptionWithBoolSelectorFieldClass> : |
| 1709 | public OptionWithBoolSelectorFieldClassTypeDescr |
| 1710 | { |
| 1711 | }; |
| 1712 | |
| 1713 | template <typename RangeSetT> |
| 1714 | struct CommonOptionWithIntegerSelectorFieldClassSpec; |
| 1715 | |
| 1716 | /* Functions specific to option field classes with unsigned integer ranges */ |
| 1717 | template <> |
| 1718 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstUnsignedIntegerRangeSet> final |
| 1719 | { |
| 1720 | static const bt_integer_range_set_unsigned * |
| 1721 | ranges(const bt_field_class * const libObjPtr) noexcept |
| 1722 | { |
| 1723 | return bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( |
| 1724 | libObjPtr); |
| 1725 | } |
| 1726 | }; |
| 1727 | |
| 1728 | /* Functions specific to option field classes with signed ranges */ |
| 1729 | template <> |
| 1730 | struct CommonOptionWithIntegerSelectorFieldClassSpec<ConstSignedIntegerRangeSet> final |
| 1731 | { |
| 1732 | static const bt_integer_range_set_signed * |
| 1733 | ranges(const bt_field_class * const libObjPtr) noexcept |
| 1734 | { |
| 1735 | return bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( |
| 1736 | libObjPtr); |
| 1737 | } |
| 1738 | }; |
| 1739 | |
| 1740 | } /* namespace internal */ |
| 1741 | |
| 1742 | template <typename LibObjT, typename RangeSetT> |
| 1743 | class CommonOptionWithIntegerSelectorFieldClass : public CommonOptionWithSelectorFieldClass<LibObjT> |
| 1744 | { |
| 1745 | private: |
| 1746 | using typename CommonOptionWithSelectorFieldClass< |
| 1747 | LibObjT>::_ThisCommonOptionWithSelectorFieldClass; |
| 1748 | |
| 1749 | public: |
| 1750 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 1751 | using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>; |
| 1752 | using RangeSet = RangeSetT; |
| 1753 | |
| 1754 | explicit CommonOptionWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 1755 | _ThisCommonOptionWithSelectorFieldClass {libObjPtr} |
| 1756 | { |
| 1757 | BT_ASSERT_DBG(this->isOptionWithIntegerSelector()); |
| 1758 | } |
| 1759 | |
| 1760 | template <typename OtherLibObjT> |
| 1761 | CommonOptionWithIntegerSelectorFieldClass( |
| 1762 | const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept : |
| 1763 | _ThisCommonOptionWithSelectorFieldClass {fc} |
| 1764 | { |
| 1765 | } |
| 1766 | |
| 1767 | template <typename OtherLibObjT> |
| 1768 | CommonOptionWithIntegerSelectorFieldClass |
| 1769 | operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept |
| 1770 | { |
| 1771 | _ThisCommonOptionWithSelectorFieldClass::operator=(fc); |
| 1772 | return *this; |
| 1773 | } |
| 1774 | |
| 1775 | RangeSet ranges() const noexcept |
| 1776 | { |
| 1777 | return RangeSet {internal::CommonOptionWithIntegerSelectorFieldClassSpec<RangeSetT>::ranges( |
| 1778 | this->libObjPtr())}; |
| 1779 | } |
| 1780 | |
| 1781 | Shared shared() const noexcept |
| 1782 | { |
| 1783 | return Shared::createWithRef(*this); |
| 1784 | } |
| 1785 | }; |
| 1786 | |
| 1787 | using OptionWithUnsignedIntegerSelectorFieldClass = |
| 1788 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstUnsignedIntegerRangeSet>; |
| 1789 | |
| 1790 | using ConstOptionWithUnsignedIntegerSelectorFieldClass = |
| 1791 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstUnsignedIntegerRangeSet>; |
| 1792 | |
| 1793 | using OptionWithSignedIntegerSelectorFieldClass = |
| 1794 | CommonOptionWithIntegerSelectorFieldClass<bt_field_class, ConstSignedIntegerRangeSet>; |
| 1795 | |
| 1796 | using ConstOptionWithSignedIntegerSelectorFieldClass = |
| 1797 | CommonOptionWithIntegerSelectorFieldClass<const bt_field_class, ConstSignedIntegerRangeSet>; |
| 1798 | |
| 1799 | namespace internal { |
| 1800 | |
| 1801 | struct OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 1802 | { |
| 1803 | using Const = ConstOptionWithUnsignedIntegerSelectorFieldClass; |
| 1804 | using NonConst = OptionWithUnsignedIntegerSelectorFieldClass; |
| 1805 | }; |
| 1806 | |
| 1807 | template <> |
| 1808 | struct TypeDescr<OptionWithUnsignedIntegerSelectorFieldClass> : |
| 1809 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 1810 | { |
| 1811 | }; |
| 1812 | |
| 1813 | template <> |
| 1814 | struct TypeDescr<ConstOptionWithUnsignedIntegerSelectorFieldClass> : |
| 1815 | public OptionWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 1816 | { |
| 1817 | }; |
| 1818 | |
| 1819 | struct OptionWithSignedIntegerSelectorFieldClassTypeDescr |
| 1820 | { |
| 1821 | using Const = ConstOptionWithSignedIntegerSelectorFieldClass; |
| 1822 | using NonConst = OptionWithSignedIntegerSelectorFieldClass; |
| 1823 | }; |
| 1824 | |
| 1825 | template <> |
| 1826 | struct TypeDescr<OptionWithSignedIntegerSelectorFieldClass> : |
| 1827 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr |
| 1828 | { |
| 1829 | }; |
| 1830 | |
| 1831 | template <> |
| 1832 | struct TypeDescr<ConstOptionWithSignedIntegerSelectorFieldClass> : |
| 1833 | public OptionWithSignedIntegerSelectorFieldClassTypeDescr |
| 1834 | { |
| 1835 | }; |
| 1836 | |
| 1837 | template <typename LibObjT> |
| 1838 | struct CommonVariantFieldClassOptionSpec; |
| 1839 | |
| 1840 | /* Functions specific to mutable variant field class options */ |
| 1841 | template <> |
| 1842 | struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final |
| 1843 | { |
| 1844 | static bt_field_class *fieldClass(bt_field_class_variant_option * const libObjPtr) noexcept |
| 1845 | { |
| 1846 | return bt_field_class_variant_option_borrow_field_class(libObjPtr); |
| 1847 | } |
| 1848 | |
| 1849 | static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept |
| 1850 | { |
| 1851 | return bt_field_class_variant_option_borrow_user_attributes(libObjPtr); |
| 1852 | } |
| 1853 | }; |
| 1854 | |
| 1855 | /* Functions specific to constant variant field class options */ |
| 1856 | template <> |
| 1857 | struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> final |
| 1858 | { |
| 1859 | static const bt_field_class * |
| 1860 | fieldClass(const bt_field_class_variant_option * const libObjPtr) noexcept |
| 1861 | { |
| 1862 | return bt_field_class_variant_option_borrow_field_class_const(libObjPtr); |
| 1863 | } |
| 1864 | |
| 1865 | static const bt_value * |
| 1866 | userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept |
| 1867 | { |
| 1868 | return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr); |
| 1869 | } |
| 1870 | }; |
| 1871 | |
| 1872 | } /* namespace internal */ |
| 1873 | |
| 1874 | template <typename LibObjT> |
| 1875 | class CommonVariantFieldClassOption : public BorrowedObject<LibObjT> |
| 1876 | { |
| 1877 | private: |
| 1878 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 1879 | using _FieldClass = internal::DepFc<LibObjT>; |
| 1880 | |
| 1881 | public: |
| 1882 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 1883 | using UserAttributes = internal::DepUserAttrs<LibObjT>; |
| 1884 | |
| 1885 | explicit CommonVariantFieldClassOption(const LibObjPtr libObjPtr) noexcept : |
| 1886 | _ThisBorrowedObject {libObjPtr} |
| 1887 | { |
| 1888 | } |
| 1889 | |
| 1890 | template <typename OtherLibObjT> |
| 1891 | CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept : |
| 1892 | _ThisBorrowedObject {fc} |
| 1893 | { |
| 1894 | } |
| 1895 | |
| 1896 | template <typename OtherLibObjT> |
| 1897 | CommonVariantFieldClassOption |
| 1898 | operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept |
| 1899 | { |
| 1900 | _ThisBorrowedObject::operator=(fc); |
| 1901 | return *this; |
| 1902 | } |
| 1903 | |
| 1904 | CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept |
| 1905 | { |
| 1906 | return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this}; |
| 1907 | } |
| 1908 | |
| 1909 | const char *name() const noexcept |
| 1910 | { |
| 1911 | return bt_field_class_variant_option_get_name(this->libObjPtr()); |
| 1912 | } |
| 1913 | |
| 1914 | _FieldClass fieldClass() const noexcept |
| 1915 | { |
| 1916 | return _FieldClass { |
| 1917 | internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())}; |
| 1918 | } |
| 1919 | |
| 1920 | template <typename LibValT> |
| 1921 | void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept |
| 1922 | { |
| 1923 | static_assert(!std::is_const<LibObjT>::value, |
| 1924 | "Not available with `bt2::ConstVariantFieldClassOption`."); |
| 1925 | |
| 1926 | bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr()); |
| 1927 | } |
| 1928 | |
| 1929 | UserAttributes userAttributes() const noexcept |
| 1930 | { |
| 1931 | return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes( |
| 1932 | this->libObjPtr())}; |
| 1933 | } |
| 1934 | }; |
| 1935 | |
| 1936 | using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>; |
| 1937 | |
| 1938 | using ConstVariantFieldClassOption = |
| 1939 | CommonVariantFieldClassOption<const bt_field_class_variant_option>; |
| 1940 | |
| 1941 | namespace internal { |
| 1942 | |
| 1943 | struct VariantFieldClassOptionTypeDescr |
| 1944 | { |
| 1945 | using Const = ConstVariantFieldClassOption; |
| 1946 | using NonConst = VariantFieldClassOption; |
| 1947 | }; |
| 1948 | |
| 1949 | template <> |
| 1950 | struct TypeDescr<VariantFieldClassOption> : public VariantFieldClassOptionTypeDescr |
| 1951 | { |
| 1952 | }; |
| 1953 | |
| 1954 | template <> |
| 1955 | struct TypeDescr<ConstVariantFieldClassOption> : public VariantFieldClassOptionTypeDescr |
| 1956 | { |
| 1957 | }; |
| 1958 | |
| 1959 | template <typename LibObjT> |
| 1960 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec; |
| 1961 | |
| 1962 | /* Functions specific to variant field class options with unsigned integer selector */ |
| 1963 | template <> |
| 1964 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< |
| 1965 | const bt_field_class_variant_with_selector_field_integer_unsigned_option> |
| 1966 | final |
| 1967 | { |
| 1968 | static const bt_integer_range_set_unsigned * |
| 1969 | ranges(const bt_field_class_variant_with_selector_field_integer_unsigned_option |
| 1970 | * const libObjPtr) noexcept |
| 1971 | { |
| 1972 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( |
| 1973 | libObjPtr); |
| 1974 | } |
| 1975 | |
| 1976 | static const bt_field_class_variant_option * |
| 1977 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_unsigned_option |
| 1978 | * const libObjPtr) noexcept |
| 1979 | { |
| 1980 | return bt_field_class_variant_with_selector_field_integer_unsigned_option_as_option_const( |
| 1981 | libObjPtr); |
| 1982 | } |
| 1983 | }; |
| 1984 | |
| 1985 | /* Functions specific to variant field class options with signed integer selector */ |
| 1986 | template <> |
| 1987 | struct ConstVariantWithIntegerSelectorFieldClassOptionSpec< |
| 1988 | const bt_field_class_variant_with_selector_field_integer_signed_option> |
| 1989 | final |
| 1990 | { |
| 1991 | static const bt_integer_range_set_signed * |
| 1992 | ranges(const bt_field_class_variant_with_selector_field_integer_signed_option |
| 1993 | * const libObjPtr) noexcept |
| 1994 | { |
| 1995 | return bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( |
| 1996 | libObjPtr); |
| 1997 | } |
| 1998 | |
| 1999 | static const bt_field_class_variant_option * |
| 2000 | asBaseOption(const bt_field_class_variant_with_selector_field_integer_signed_option |
| 2001 | * const libObjPtr) noexcept |
| 2002 | { |
| 2003 | return bt_field_class_variant_with_selector_field_integer_signed_option_as_option_const( |
| 2004 | libObjPtr); |
| 2005 | } |
| 2006 | }; |
| 2007 | |
| 2008 | } /* namespace internal */ |
| 2009 | |
| 2010 | template <typename LibObjT> |
| 2011 | class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT> |
| 2012 | { |
| 2013 | private: |
| 2014 | using typename BorrowedObject<LibObjT>::_ThisBorrowedObject; |
| 2015 | using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>; |
| 2016 | |
| 2017 | public: |
| 2018 | using typename BorrowedObject<LibObjT>::LibObjPtr; |
| 2019 | |
| 2020 | using RangeSet = typename std::conditional< |
| 2021 | std::is_same< |
| 2022 | LibObjT, |
| 2023 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>::value, |
| 2024 | ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type; |
| 2025 | |
| 2026 | explicit ConstVariantWithIntegerSelectorFieldClassOption(const LibObjPtr libObjPtr) noexcept : |
| 2027 | _ThisBorrowedObject {libObjPtr} |
| 2028 | { |
| 2029 | } |
| 2030 | |
| 2031 | template <typename OtherLibObjT> |
| 2032 | ConstVariantWithIntegerSelectorFieldClassOption( |
| 2033 | const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept : |
| 2034 | _ThisBorrowedObject {fc} |
| 2035 | { |
| 2036 | } |
| 2037 | |
| 2038 | template <typename OtherLibObjT> |
| 2039 | ConstVariantWithIntegerSelectorFieldClassOption |
| 2040 | operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept |
| 2041 | { |
| 2042 | _ThisBorrowedObject::operator=(fc); |
| 2043 | return *this; |
| 2044 | } |
| 2045 | |
| 2046 | ConstVariantFieldClassOption asBaseOption() const noexcept |
| 2047 | { |
| 2048 | return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())}; |
| 2049 | } |
| 2050 | |
| 2051 | const char *name() const noexcept |
| 2052 | { |
| 2053 | return this->asBaseOption().name(); |
| 2054 | } |
| 2055 | |
| 2056 | ConstFieldClass fieldClass() const noexcept |
| 2057 | { |
| 2058 | return this->asBaseOption().fieldClass(); |
| 2059 | } |
| 2060 | |
| 2061 | RangeSet ranges() const noexcept |
| 2062 | { |
| 2063 | return RangeSet {_Spec::ranges(this->libObjPtr())}; |
| 2064 | } |
| 2065 | }; |
| 2066 | |
| 2067 | using ConstVariantWithUnsignedIntegerSelectorFieldClassOption = |
| 2068 | ConstVariantWithIntegerSelectorFieldClassOption< |
| 2069 | const bt_field_class_variant_with_selector_field_integer_unsigned_option>; |
| 2070 | |
| 2071 | using ConstVariantWithSignedIntegerSelectorFieldClassOption = |
| 2072 | ConstVariantWithIntegerSelectorFieldClassOption< |
| 2073 | const bt_field_class_variant_with_selector_field_integer_signed_option>; |
| 2074 | |
| 2075 | namespace internal { |
| 2076 | |
| 2077 | template <typename LibObjT> |
| 2078 | struct CommonVariantFieldClassSpec; |
| 2079 | |
| 2080 | /* Functions specific to mutable variant field classes */ |
| 2081 | template <> |
| 2082 | struct CommonVariantFieldClassSpec<bt_field_class> final |
| 2083 | { |
| 2084 | static bt_field_class_variant_option *optionByIndex(bt_field_class * const libObjPtr, |
| 2085 | const std::uint64_t index) noexcept |
| 2086 | { |
| 2087 | return bt_field_class_variant_borrow_option_by_index(libObjPtr, index); |
| 2088 | } |
| 2089 | |
| 2090 | static bt_field_class_variant_option *optionByName(bt_field_class * const libObjPtr, |
| 2091 | const char * const name) noexcept |
| 2092 | { |
| 2093 | return bt_field_class_variant_borrow_option_by_name(libObjPtr, name); |
| 2094 | } |
| 2095 | }; |
| 2096 | |
| 2097 | /* Functions specific to constant variant field classes */ |
| 2098 | template <> |
| 2099 | struct CommonVariantFieldClassSpec<const bt_field_class> final |
| 2100 | { |
| 2101 | static const bt_field_class_variant_option * |
| 2102 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 2103 | { |
| 2104 | return bt_field_class_variant_borrow_option_by_index_const(libObjPtr, index); |
| 2105 | } |
| 2106 | |
| 2107 | static const bt_field_class_variant_option *optionByName(const bt_field_class * const libObjPtr, |
| 2108 | const char * const name) noexcept |
| 2109 | { |
| 2110 | return bt_field_class_variant_borrow_option_by_name_const(libObjPtr, name); |
| 2111 | } |
| 2112 | }; |
| 2113 | |
| 2114 | } /* namespace internal */ |
| 2115 | |
| 2116 | template <typename LibObjT> |
| 2117 | class CommonVariantFieldClass : public CommonFieldClass<LibObjT> |
| 2118 | { |
| 2119 | private: |
| 2120 | using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass; |
| 2121 | |
| 2122 | protected: |
| 2123 | using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>; |
| 2124 | |
| 2125 | public: |
| 2126 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 2127 | using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>; |
| 2128 | using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>; |
| 2129 | |
| 2130 | using Option = |
| 2131 | internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>; |
| 2132 | |
| 2133 | explicit CommonVariantFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 2134 | _ThisCommonFieldClass {libObjPtr} |
| 2135 | { |
| 2136 | BT_ASSERT_DBG(this->isVariant()); |
| 2137 | } |
| 2138 | |
| 2139 | template <typename OtherLibObjT> |
| 2140 | CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept : |
| 2141 | _ThisCommonFieldClass {fc} |
| 2142 | { |
| 2143 | } |
| 2144 | |
| 2145 | template <typename OtherLibObjT> |
| 2146 | CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept |
| 2147 | { |
| 2148 | _ThisCommonFieldClass::operator=(fc); |
| 2149 | return *this; |
| 2150 | } |
| 2151 | |
| 2152 | CommonVariantFieldClass<const bt_field_class> asConst() const noexcept |
| 2153 | { |
| 2154 | return CommonVariantFieldClass<const bt_field_class> {*this}; |
| 2155 | } |
| 2156 | |
| 2157 | std::uint64_t length() const noexcept |
| 2158 | { |
| 2159 | return bt_field_class_variant_get_option_count(this->libObjPtr()); |
| 2160 | } |
| 2161 | |
| 2162 | Iterator begin() const noexcept |
| 2163 | { |
| 2164 | return Iterator {*this, 0}; |
| 2165 | } |
| 2166 | |
| 2167 | Iterator end() const noexcept |
| 2168 | { |
| 2169 | return Iterator {*this, this->length()}; |
| 2170 | } |
| 2171 | |
| 2172 | Option operator[](const std::uint64_t index) const noexcept |
| 2173 | { |
| 2174 | return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex( |
| 2175 | this->libObjPtr(), index)}; |
| 2176 | } |
| 2177 | |
| 2178 | OptionalBorrowedObject<Option> operator[](const char * const name) const noexcept |
| 2179 | { |
| 2180 | return internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), |
| 2181 | name); |
| 2182 | } |
| 2183 | |
| 2184 | OptionalBorrowedObject<Option> operator[](const std::string& name) const noexcept |
| 2185 | { |
| 2186 | return (*this)[name.data()]; |
| 2187 | } |
| 2188 | |
| 2189 | Shared shared() const noexcept |
| 2190 | { |
| 2191 | return Shared::createWithRef(*this); |
| 2192 | } |
| 2193 | }; |
| 2194 | |
| 2195 | using VariantFieldClass = CommonVariantFieldClass<bt_field_class>; |
| 2196 | using ConstVariantFieldClass = CommonVariantFieldClass<const bt_field_class>; |
| 2197 | |
| 2198 | namespace internal { |
| 2199 | |
| 2200 | struct VariantFieldClassTypeDescr |
| 2201 | { |
| 2202 | using Const = ConstVariantFieldClass; |
| 2203 | using NonConst = VariantFieldClass; |
| 2204 | }; |
| 2205 | |
| 2206 | template <> |
| 2207 | struct TypeDescr<VariantFieldClass> : public VariantFieldClassTypeDescr |
| 2208 | { |
| 2209 | }; |
| 2210 | |
| 2211 | template <> |
| 2212 | struct TypeDescr<ConstVariantFieldClass> : public VariantFieldClassTypeDescr |
| 2213 | { |
| 2214 | }; |
| 2215 | |
| 2216 | } /* namespace internal */ |
| 2217 | |
| 2218 | template <typename LibObjT> |
| 2219 | class CommonVariantWithoutSelectorFieldClass : public CommonVariantFieldClass<LibObjT> |
| 2220 | { |
| 2221 | private: |
| 2222 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; |
| 2223 | |
| 2224 | public: |
| 2225 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 2226 | using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>; |
| 2227 | |
| 2228 | explicit CommonVariantWithoutSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 2229 | _ThisCommonVariantFieldClass {libObjPtr} |
| 2230 | { |
| 2231 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); |
| 2232 | } |
| 2233 | |
| 2234 | template <typename OtherLibObjT> |
| 2235 | CommonVariantWithoutSelectorFieldClass( |
| 2236 | const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 2237 | _ThisCommonVariantFieldClass {fc} |
| 2238 | { |
| 2239 | } |
| 2240 | |
| 2241 | template <typename OtherLibObjT> |
| 2242 | CommonVariantWithoutSelectorFieldClass |
| 2243 | operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 2244 | { |
| 2245 | _ThisCommonVariantFieldClass::operator=(fc); |
| 2246 | return *this; |
| 2247 | } |
| 2248 | |
| 2249 | CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 2250 | { |
| 2251 | return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this}; |
| 2252 | } |
| 2253 | |
| 2254 | void appendOption(const char * const name, const FieldClass fc) const |
| 2255 | { |
| 2256 | static_assert(!std::is_const<LibObjT>::value, |
| 2257 | "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`."); |
| 2258 | |
| 2259 | const auto status = bt_field_class_variant_without_selector_append_option( |
| 2260 | this->libObjPtr(), name, fc.libObjPtr()); |
| 2261 | |
| 2262 | if (status == |
| 2263 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { |
| 2264 | throw MemoryError {}; |
| 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc) const |
| 2269 | { |
| 2270 | this->appendOption(name ? name->data() : nullptr, fc); |
| 2271 | } |
| 2272 | |
| 2273 | Shared shared() const noexcept |
| 2274 | { |
| 2275 | return Shared::createWithRef(*this); |
| 2276 | } |
| 2277 | }; |
| 2278 | |
| 2279 | using VariantWithoutSelectorFieldClass = CommonVariantWithoutSelectorFieldClass<bt_field_class>; |
| 2280 | using ConstVariantWithoutSelectorFieldClass = |
| 2281 | CommonVariantWithoutSelectorFieldClass<const bt_field_class>; |
| 2282 | |
| 2283 | namespace internal { |
| 2284 | |
| 2285 | struct VariantWithoutSelectorFieldClassTypeDescr |
| 2286 | { |
| 2287 | using Const = ConstVariantWithoutSelectorFieldClass; |
| 2288 | using NonConst = VariantWithoutSelectorFieldClass; |
| 2289 | }; |
| 2290 | |
| 2291 | template <> |
| 2292 | struct TypeDescr<VariantWithoutSelectorFieldClass> : |
| 2293 | public VariantWithoutSelectorFieldClassTypeDescr |
| 2294 | { |
| 2295 | }; |
| 2296 | |
| 2297 | template <> |
| 2298 | struct TypeDescr<ConstVariantWithoutSelectorFieldClass> : |
| 2299 | public VariantWithoutSelectorFieldClassTypeDescr |
| 2300 | { |
| 2301 | }; |
| 2302 | |
| 2303 | template <typename OptionT> |
| 2304 | struct CommonVariantWithIntegerSelectorFieldClassSpec; |
| 2305 | |
| 2306 | /* Functions specific to variant field classes with unsigned integer selector */ |
| 2307 | template <> |
| 2308 | struct CommonVariantWithIntegerSelectorFieldClassSpec< |
| 2309 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> |
| 2310 | final |
| 2311 | { |
| 2312 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * |
| 2313 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 2314 | { |
| 2315 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( |
| 2316 | libObjPtr, index); |
| 2317 | } |
| 2318 | |
| 2319 | static const bt_field_class_variant_with_selector_field_integer_unsigned_option * |
| 2320 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept |
| 2321 | { |
| 2322 | return bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const( |
| 2323 | libObjPtr, name); |
| 2324 | } |
| 2325 | |
| 2326 | static bt_field_class_variant_with_selector_field_integer_append_option_status |
| 2327 | appendOption(bt_field_class * const libObjPtr, const char * const name, |
| 2328 | bt_field_class * const libOptFcPtr, |
| 2329 | const bt_integer_range_set_unsigned * const libRangesPtr) |
| 2330 | { |
| 2331 | return bt_field_class_variant_with_selector_field_integer_unsigned_append_option( |
| 2332 | libObjPtr, name, libOptFcPtr, libRangesPtr); |
| 2333 | } |
| 2334 | }; |
| 2335 | |
| 2336 | /* Functions specific to variant field classes with signed integer selector */ |
| 2337 | template <> |
| 2338 | struct CommonVariantWithIntegerSelectorFieldClassSpec< |
| 2339 | ConstVariantWithSignedIntegerSelectorFieldClassOption> |
| 2340 | final |
| 2341 | { |
| 2342 | static const bt_field_class_variant_with_selector_field_integer_signed_option * |
| 2343 | optionByIndex(const bt_field_class * const libObjPtr, const std::uint64_t index) noexcept |
| 2344 | { |
| 2345 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( |
| 2346 | libObjPtr, index); |
| 2347 | } |
| 2348 | |
| 2349 | static const bt_field_class_variant_with_selector_field_integer_signed_option * |
| 2350 | optionByName(const bt_field_class * const libObjPtr, const char * const name) noexcept |
| 2351 | { |
| 2352 | return bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const( |
| 2353 | libObjPtr, name); |
| 2354 | } |
| 2355 | |
| 2356 | static bt_field_class_variant_with_selector_field_integer_append_option_status |
| 2357 | appendOption(bt_field_class * const libObjPtr, const char * const name, |
| 2358 | bt_field_class * const libOptFcPtr, |
| 2359 | const bt_integer_range_set_signed * const libRangesPtr) |
| 2360 | { |
| 2361 | return bt_field_class_variant_with_selector_field_integer_signed_append_option( |
| 2362 | libObjPtr, name, libOptFcPtr, libRangesPtr); |
| 2363 | } |
| 2364 | }; |
| 2365 | |
| 2366 | } /* namespace internal */ |
| 2367 | |
| 2368 | template <typename LibObjT> |
| 2369 | class CommonVariantWithSelectorFieldClass : public CommonVariantFieldClass<LibObjT> |
| 2370 | { |
| 2371 | private: |
| 2372 | using typename CommonVariantFieldClass<LibObjT>::_ThisCommonVariantFieldClass; |
| 2373 | |
| 2374 | protected: |
| 2375 | using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>; |
| 2376 | |
| 2377 | public: |
| 2378 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 2379 | using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>; |
| 2380 | |
| 2381 | explicit CommonVariantWithSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 2382 | _ThisCommonVariantFieldClass {libObjPtr} |
| 2383 | { |
| 2384 | BT_ASSERT_DBG(this->isVariantWithSelector()); |
| 2385 | } |
| 2386 | |
| 2387 | template <typename OtherLibObjT> |
| 2388 | CommonVariantWithSelectorFieldClass( |
| 2389 | const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept : |
| 2390 | _ThisCommonVariantFieldClass {fc} |
| 2391 | { |
| 2392 | } |
| 2393 | |
| 2394 | template <typename OtherLibObjT> |
| 2395 | CommonVariantWithSelectorFieldClass |
| 2396 | operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept |
| 2397 | { |
| 2398 | _ThisCommonVariantFieldClass::operator=(fc); |
| 2399 | return *this; |
| 2400 | } |
| 2401 | |
| 2402 | CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept |
| 2403 | { |
| 2404 | return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this}; |
| 2405 | } |
| 2406 | |
| 2407 | ConstFieldPath selectorFieldPath() const noexcept |
| 2408 | { |
| 2409 | return ConstFieldPath { |
| 2410 | bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( |
| 2411 | this->libObjPtr())}; |
| 2412 | } |
| 2413 | |
| 2414 | Shared shared() const noexcept |
| 2415 | { |
| 2416 | return Shared::createWithRef(*this); |
| 2417 | } |
| 2418 | }; |
| 2419 | |
| 2420 | using VariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<bt_field_class>; |
| 2421 | using ConstVariantWithSelectorFieldClass = |
| 2422 | CommonVariantWithSelectorFieldClass<const bt_field_class>; |
| 2423 | |
| 2424 | template <typename LibObjT, typename OptionT> |
| 2425 | class CommonVariantWithIntegerSelectorFieldClass : |
| 2426 | public CommonVariantWithSelectorFieldClass<LibObjT> |
| 2427 | { |
| 2428 | private: |
| 2429 | using typename CommonVariantWithSelectorFieldClass< |
| 2430 | LibObjT>::_ThisCommonVariantWithSelectorFieldClass; |
| 2431 | |
| 2432 | using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>; |
| 2433 | |
| 2434 | public: |
| 2435 | using typename CommonFieldClass<LibObjT>::LibObjPtr; |
| 2436 | using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>; |
| 2437 | using Option = OptionT; |
| 2438 | |
| 2439 | using Iterator = |
| 2440 | BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>; |
| 2441 | |
| 2442 | explicit CommonVariantWithIntegerSelectorFieldClass(const LibObjPtr libObjPtr) noexcept : |
| 2443 | _ThisCommonVariantWithSelectorFieldClass {libObjPtr} |
| 2444 | { |
| 2445 | BT_ASSERT_DBG(this->isVariant()); |
| 2446 | } |
| 2447 | |
| 2448 | template <typename OtherLibObjT> |
| 2449 | CommonVariantWithIntegerSelectorFieldClass( |
| 2450 | const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept : |
| 2451 | _ThisCommonVariantWithSelectorFieldClass {fc} |
| 2452 | { |
| 2453 | } |
| 2454 | |
| 2455 | template <typename OtherLibObjT> |
| 2456 | CommonVariantWithIntegerSelectorFieldClass |
| 2457 | operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept |
| 2458 | { |
| 2459 | _ThisCommonVariantWithSelectorFieldClass::operator=(fc); |
| 2460 | return *this; |
| 2461 | } |
| 2462 | |
| 2463 | Option operator[](const std::uint64_t index) const noexcept |
| 2464 | { |
| 2465 | return Option {_Spec::optionByIndex(this->libObjPtr(), index)}; |
| 2466 | } |
| 2467 | |
| 2468 | OptionalBorrowedObject<Option> operator[](const char * const name) const noexcept |
| 2469 | { |
| 2470 | return _Spec::optionByName(this->libObjPtr(), name); |
| 2471 | } |
| 2472 | |
| 2473 | OptionalBorrowedObject<Option> operator[](const std::string& name) const noexcept |
| 2474 | { |
| 2475 | return (*this)[name.data()]; |
| 2476 | } |
| 2477 | |
| 2478 | void appendOption(const char * const name, const FieldClass fc, |
| 2479 | const typename Option::RangeSet ranges) const |
| 2480 | { |
| 2481 | static_assert( |
| 2482 | !std::is_const<LibObjT>::value, |
| 2483 | "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`."); |
| 2484 | |
| 2485 | const auto status = |
| 2486 | _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr()); |
| 2487 | |
| 2488 | if (status == |
| 2489 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) { |
| 2490 | throw MemoryError {}; |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc, |
| 2495 | const typename Option::RangeSet ranges) const |
| 2496 | { |
| 2497 | this->appendOption(name ? name->data() : nullptr, fc, ranges); |
| 2498 | } |
| 2499 | |
| 2500 | Iterator begin() const noexcept |
| 2501 | { |
| 2502 | return Iterator {*this, 0}; |
| 2503 | } |
| 2504 | |
| 2505 | Iterator end() const noexcept |
| 2506 | { |
| 2507 | return Iterator {*this, this->length()}; |
| 2508 | } |
| 2509 | |
| 2510 | Shared shared() const noexcept |
| 2511 | { |
| 2512 | return Shared::createWithRef(*this); |
| 2513 | } |
| 2514 | }; |
| 2515 | |
| 2516 | using VariantWithUnsignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< |
| 2517 | bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; |
| 2518 | |
| 2519 | using ConstVariantWithUnsignedIntegerSelectorFieldClass = |
| 2520 | CommonVariantWithIntegerSelectorFieldClass< |
| 2521 | const bt_field_class, ConstVariantWithUnsignedIntegerSelectorFieldClassOption>; |
| 2522 | |
| 2523 | using VariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< |
| 2524 | bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; |
| 2525 | |
| 2526 | using ConstVariantWithSignedIntegerSelectorFieldClass = CommonVariantWithIntegerSelectorFieldClass< |
| 2527 | const bt_field_class, ConstVariantWithSignedIntegerSelectorFieldClassOption>; |
| 2528 | |
| 2529 | namespace internal { |
| 2530 | |
| 2531 | struct VariantWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 2532 | { |
| 2533 | using Const = ConstVariantWithUnsignedIntegerSelectorFieldClass; |
| 2534 | using NonConst = VariantWithUnsignedIntegerSelectorFieldClass; |
| 2535 | }; |
| 2536 | |
| 2537 | template <> |
| 2538 | struct TypeDescr<VariantWithUnsignedIntegerSelectorFieldClass> : |
| 2539 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 2540 | { |
| 2541 | }; |
| 2542 | |
| 2543 | template <> |
| 2544 | struct TypeDescr<ConstVariantWithUnsignedIntegerSelectorFieldClass> : |
| 2545 | public VariantWithUnsignedIntegerSelectorFieldClassTypeDescr |
| 2546 | { |
| 2547 | }; |
| 2548 | |
| 2549 | struct VariantWithSignedIntegerSelectorFieldClassTypeDescr |
| 2550 | { |
| 2551 | using Const = ConstVariantWithSignedIntegerSelectorFieldClass; |
| 2552 | using NonConst = VariantWithSignedIntegerSelectorFieldClass; |
| 2553 | }; |
| 2554 | |
| 2555 | template <> |
| 2556 | struct TypeDescr<VariantWithSignedIntegerSelectorFieldClass> : |
| 2557 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr |
| 2558 | { |
| 2559 | }; |
| 2560 | |
| 2561 | template <> |
| 2562 | struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> : |
| 2563 | public VariantWithSignedIntegerSelectorFieldClassTypeDescr |
| 2564 | { |
| 2565 | }; |
| 2566 | |
| 2567 | } /* namespace internal */ |
| 2568 | |
| 2569 | template <typename LibObjT> |
| 2570 | CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept |
| 2571 | { |
| 2572 | BT_ASSERT_DBG(this->isBitArray()); |
| 2573 | return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()}; |
| 2574 | } |
| 2575 | |
| 2576 | template <typename LibObjT> |
| 2577 | CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept |
| 2578 | { |
| 2579 | BT_ASSERT_DBG(this->isInteger()); |
| 2580 | return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()}; |
| 2581 | } |
| 2582 | |
| 2583 | template <typename LibObjT> |
| 2584 | CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept |
| 2585 | { |
| 2586 | BT_ASSERT_DBG(this->isEnumeration()); |
| 2587 | return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()}; |
| 2588 | } |
| 2589 | |
| 2590 | template <typename LibObjT> |
| 2591 | CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> |
| 2592 | CommonFieldClass<LibObjT>::asUnsignedEnumeration() const noexcept |
| 2593 | { |
| 2594 | BT_ASSERT_DBG(this->isUnsignedEnumeration()); |
| 2595 | return CommonEnumerationFieldClass<LibObjT, ConstUnsignedEnumerationFieldClassMapping> { |
| 2596 | this->libObjPtr()}; |
| 2597 | } |
| 2598 | |
| 2599 | template <typename LibObjT> |
| 2600 | CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> |
| 2601 | CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept |
| 2602 | { |
| 2603 | BT_ASSERT_DBG(this->isSignedEnumeration()); |
| 2604 | return CommonEnumerationFieldClass<LibObjT, ConstSignedEnumerationFieldClassMapping> { |
| 2605 | this->libObjPtr()}; |
| 2606 | } |
| 2607 | |
| 2608 | template <typename LibObjT> |
| 2609 | CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept |
| 2610 | { |
| 2611 | BT_ASSERT_DBG(this->isStructure()); |
| 2612 | return CommonStructureFieldClass<LibObjT> {this->libObjPtr()}; |
| 2613 | } |
| 2614 | |
| 2615 | template <typename LibObjT> |
| 2616 | CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept |
| 2617 | { |
| 2618 | BT_ASSERT_DBG(this->isArray()); |
| 2619 | return CommonArrayFieldClass<LibObjT> {this->libObjPtr()}; |
| 2620 | } |
| 2621 | |
| 2622 | template <typename LibObjT> |
| 2623 | CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept |
| 2624 | { |
| 2625 | BT_ASSERT_DBG(this->isStaticArray()); |
| 2626 | return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()}; |
| 2627 | } |
| 2628 | |
| 2629 | template <typename LibObjT> |
| 2630 | CommonDynamicArrayWithLengthFieldClass<LibObjT> |
| 2631 | CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept |
| 2632 | { |
| 2633 | BT_ASSERT_DBG(this->isDynamicArrayWithLength()); |
| 2634 | return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()}; |
| 2635 | } |
| 2636 | |
| 2637 | template <typename LibObjT> |
| 2638 | CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept |
| 2639 | { |
| 2640 | BT_ASSERT_DBG(this->isOption()); |
| 2641 | return CommonOptionFieldClass<LibObjT> {this->libObjPtr()}; |
| 2642 | } |
| 2643 | |
| 2644 | template <typename LibObjT> |
| 2645 | CommonOptionWithSelectorFieldClass<LibObjT> |
| 2646 | CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept |
| 2647 | { |
| 2648 | BT_ASSERT_DBG(this->isOptionWithSelector()); |
| 2649 | return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2650 | } |
| 2651 | |
| 2652 | template <typename LibObjT> |
| 2653 | CommonOptionWithBoolSelectorFieldClass<LibObjT> |
| 2654 | CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept |
| 2655 | { |
| 2656 | BT_ASSERT_DBG(this->isOptionWithBoolSelector()); |
| 2657 | return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2658 | } |
| 2659 | |
| 2660 | template <typename LibObjT> |
| 2661 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> |
| 2662 | CommonFieldClass<LibObjT>::asOptionWithUnsignedIntegerSelector() const noexcept |
| 2663 | { |
| 2664 | BT_ASSERT_DBG(this->isOptionWithUnsignedIntegerSelector()); |
| 2665 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstUnsignedIntegerRangeSet> { |
| 2666 | this->libObjPtr()}; |
| 2667 | } |
| 2668 | |
| 2669 | template <typename LibObjT> |
| 2670 | CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> |
| 2671 | CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept |
| 2672 | { |
| 2673 | BT_ASSERT_DBG(this->isOptionWithSignedIntegerSelector()); |
| 2674 | return CommonOptionWithIntegerSelectorFieldClass<LibObjT, ConstSignedIntegerRangeSet> { |
| 2675 | this->libObjPtr()}; |
| 2676 | } |
| 2677 | |
| 2678 | template <typename LibObjT> |
| 2679 | CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept |
| 2680 | { |
| 2681 | BT_ASSERT_DBG(this->isVariant()); |
| 2682 | return CommonVariantFieldClass<LibObjT> {this->libObjPtr()}; |
| 2683 | } |
| 2684 | |
| 2685 | template <typename LibObjT> |
| 2686 | CommonVariantWithoutSelectorFieldClass<LibObjT> |
| 2687 | CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept |
| 2688 | { |
| 2689 | BT_ASSERT_DBG(this->isVariantWithoutSelector()); |
| 2690 | return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2691 | } |
| 2692 | |
| 2693 | template <typename LibObjT> |
| 2694 | CommonVariantWithSelectorFieldClass<LibObjT> |
| 2695 | CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept |
| 2696 | { |
| 2697 | BT_ASSERT_DBG(this->isVariantWithSelector()); |
| 2698 | return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()}; |
| 2699 | } |
| 2700 | |
| 2701 | template <typename LibObjT> |
| 2702 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, |
| 2703 | ConstVariantWithUnsignedIntegerSelectorFieldClassOption> |
| 2704 | CommonFieldClass<LibObjT>::asVariantWithUnsignedIntegerSelector() const noexcept |
| 2705 | { |
| 2706 | BT_ASSERT_DBG(this->isVariantWithUnsignedIntegerSelector()); |
| 2707 | return CommonVariantWithIntegerSelectorFieldClass< |
| 2708 | LibObjT, ConstVariantWithUnsignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
| 2709 | } |
| 2710 | |
| 2711 | template <typename LibObjT> |
| 2712 | CommonVariantWithIntegerSelectorFieldClass<LibObjT, |
| 2713 | ConstVariantWithSignedIntegerSelectorFieldClassOption> |
| 2714 | CommonFieldClass<LibObjT>::asVariantWithSignedIntegerSelector() const noexcept |
| 2715 | { |
| 2716 | BT_ASSERT_DBG(this->isVariantWithSignedIntegerSelector()); |
| 2717 | return CommonVariantWithIntegerSelectorFieldClass< |
| 2718 | LibObjT, ConstVariantWithSignedIntegerSelectorFieldClassOption> {this->libObjPtr()}; |
| 2719 | } |
| 2720 | |
| 2721 | } /* namespace bt2 */ |
| 2722 | |
| 2723 | #endif /* BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP */ |