Add default features to existing features array if they don’t already exist
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(feature_collection_t), | intent(inout), | allocatable | :: | features(:) |
Instance of the feature collections array (will be resized) |
|
| type(error_t), | intent(out), | allocatable | :: | error |
Error handling |
subroutine add_default_features(features, error) !> Instance of the feature collections array (will be resized) type(feature_collection_t), allocatable, intent(inout) :: features(:) !> Error handling type(error_t), allocatable, intent(out) :: error type(feature_collection_t), allocatable :: temp_features(:) type(feature_collection_t), allocatable :: default_features(:) logical :: debug_exists, release_exists integer :: i, current_size, new_size ! Get default features call get_default_features(default_features, error) if (allocated(error)) return ! Check if debug and release features already exist debug_exists = .false. release_exists = .false. if (allocated(features)) then do i = 1, size(features) if (allocated(features(i)%base%name)) then if (features(i)%base%name == "debug") debug_exists = .true. if (features(i)%base%name == "release") release_exists = .true. end if end do current_size = size(features) else current_size = 0 end if ! Calculate how many features to add new_size = current_size if (.not. debug_exists) new_size = new_size + 1 if (.not. release_exists) new_size = new_size + 1 ! If nothing to add, return if (new_size == current_size) return ! Create new array with existing + missing defaults allocate(temp_features(new_size)) ! Copy existing features if (current_size > 0) then temp_features(1:current_size) = features(1:current_size) end if ! Add missing defaults i = current_size if (.not. debug_exists) then i = i + 1 temp_features(i) = default_features(1) ! debug feature end if if (.not. release_exists) then i = i + 1 temp_features(i) = default_features(2) ! release feature end if ! Replace the features array call move_alloc(temp_features, features) end subroutine add_default_features