/**
 *  Config class for storing map lists.
 *      Copyright 2023 Anton Tarasenko
 *------------------------------------------------------------------------------
 * This file is part of Acedia.
 *
 * Acedia is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License, or
 * (at your option) any later version.
 *
 * Acedia is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Acedia.  If not, see <https://www.gnu.org/licenses/>.
 */
class FunctionReplacement extends AcediaObject;

var private Text replaced;
var private Text replacer;
var private SideEffect effect;

protected function Finalizer() {
    _.memory.Free(replaced);
    _.memory.Free(replacer);
    _.memory.Free(effect);
    replaced = none;
    replacer = none;
    effect = none;
}

public static final function FunctionReplacement Make(
    BaseText oldFunction,
    BaseText newFunction,
    SideEffect sideEffect
) {
    local FunctionReplacement newReplacement;

    if (oldFunction == none)    return none;
    if (newFunction == none)    return none;
    if (sideEffect == none)     return none;

    newReplacement = FunctionReplacement(__().memory.Allocate(class'FunctionReplacement'));
    newReplacement.replaced = oldFunction.Copy();
    newReplacement.replacer = newFunction.Copy();
    sideEffect.NewRef();
    newReplacement.effect = sideEffect;
    return newReplacement;
}

public final function Text GetReplacedFunctionName() {
    return replaced.Copy();
}

public final function string GetReplacedFunctionName_S() {
    return replaced.ToString();
}

public final function Text GetReplacerFunctionName() {
    return replacer.Copy();
}

public final function string GetReplacerFunctionName_S() {
    return replacer.ToString();
}

public final function SideEffect GetSideEffect() {
    effect.NewRef();
    return effect;
}

defaultproperties {
}