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