Example #1
0
    def replace_trait_parameter_value(
            self,
            res_opt: 'ResolveOptions',
            to_trait: str,  # pylint: disable=unused-argument
            param_name: str,
            value_when: 'CdmArgumentValue',
            value_new: 'CdmArgumentValue') -> 'ResolvedTraitSet':
        trait_set_result = cast('ResolvedTraitSet', self)

        for idx_rt, rt in enumerate(trait_set_result.rt_set):
            if rt.trait.is_derived_from(to_trait,
                                        self.res_opt) and rt.parameter_values:
                av = rt.parameter_values.values
                idx = rt.parameter_values.pc.fetch_parameter_index(param_name)
                if idx is not None and av[idx] == value_when:
                    # Copy the set and make a deep copy of the trait being set.
                    trait_set_result = self.shallow_copy_with_exception(
                        rt.trait)
                    # Assume these are all still True for this copy.
                    rt = trait_set_result.rt_set[idx_rt]
                    av = rt.parameter_values.values
                    av[idx] = ParameterValue.fetch_replacement_value(
                        self.res_opt, av[idx], value_new, True)
                    break

        return trait_set_result
Example #2
0
    def merge(self, to_merge: 'ResolvedTrait', copy_on_write: bool) -> 'ResolvedTraitSet':
        trait_set_result = self
        trait = to_merge.trait
        av = to_merge.parameter_values.values if to_merge.parameter_values else None
        was_set = to_merge.parameter_values.was_set if to_merge.parameter_values else None

        if not self.has_elevated:
            self.has_elevated = trait.elevated

        if trait in trait_set_result.lookup_by_trait:
            rt_old = trait_set_result.lookup_by_trait[trait]
            av_old = rt_old.parameter_values.values if rt_old.parameter_values else None

            if av and av_old:
                # The new values take precedence.
                for i in range(len(av)):  # pylint: disable=consider-using-enumerate
                    if av[i] != av_old[i]:
                        if copy_on_write:
                            trait_set_result = trait_set_result.shallow_copy_with_exception(trait)
                            rt_old = trait_set_result.lookup_by_trait[trait]
                            av_old = rt_old.parameter_values.values
                            copy_on_write = False

                        av_old[i] = ParameterValue.fetch_replacement_value(self.res_opt, av_old[i], av[i], was_set[i])
        else:
            if copy_on_write:
                trait_set_result = trait_set_result.shallow_copy()

            to_merge = to_merge.copy()
            trait_set_result.rt_set.append(to_merge)
            trait_set_result.lookup_by_trait[trait] = to_merge

        return trait_set_result
Example #3
0
 def set_parameter_value_from_argument(self, trait: 'CdmTraitDefinition', arg: 'CdmArgumentDefinition') -> None:
     res_trait = self.get(trait)
     if res_trait and res_trait.parameter_values:
         av = res_trait.parameter_values.values
         new_val = arg.value
         # Get the value index from the parameter collection given the parameter that this argument is setting.
         idx = res_trait.parameter_values.index_of(arg.resolved_parameter)
         av[idx] = ParameterValue.fetch_replacement_value(self.res_opt, av[idx], new_val, True)
         res_trait.parameter_values.was_set[idx] = True
Example #4
0
 def set_parameter_value_from_argument(self, trait: 'CdmTraitDefinition', arg: 'CdmArgumentDefinition') -> None:
     res_trait = self.get(trait)
     if res_trait and res_trait.parameter_values:
         av = res_trait.parameter_values.values
         new_val = arg.value
         # Get the value index from the parameter collection given the parameter that this argument is setting.
         param_def = arg._get_parameter_def()
         if param_def is not None:
             i_param = res_trait.parameter_values.index_of(param_def)
             av[i_param] = ParameterValue.fetch_replacement_value(self.res_opt, av[i_param], new_val, True)
             res_trait.parameter_values.was_set[i_param] = True
         else:
             # debug
             param_def = arg._get_parameter_def()