Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/ViewModelHelpers.h (C/C++)

Code before:
    }

    // template recursion base case: single dispatch
    void _NotifyChanges(const std::wstring_view name) { _NotifyChangeCore(name); }

    template<typename... Args>
    void _NotifyChanges(const std::wstring_view name, Args&&... more)
    {
        _NotifyChangeCore(name);
        _NotifyChanges(std::forward<Args>(more)...);
    }

private:
    winrt::event<::winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler> _propertyChangedHandlers;
};

#define _BASE_OBSERVABLE_PROJECTED_SETTING(target, name)                   \
public:                                                                    \
    auto name() const noexcept { return target.name(); };                  \
    template<typename T>                                                   \
    void name(const T& value)                                              \
    {                                                                      \
        if (name() != value)                                               \
        {                                                                  \
            target.name(value);                                            \
            _NotifyChanges(L"Has" #name, L#name, L#name "OverrideSource"); \
        }                                                                  \
    }                                                                      \
    bool Has##name() { return target.Has##name(); }

// Defines a setting that reflects another object's same-named
// setting.
#define OBSERVABLE_PROJECTED_SETTING(target, name)                         \
    _BASE_OBSERVABLE_PROJECTED_SETTING(target, name)                       \
    void Clear##name()                                                     \
    {                                                                      \
        const auto hadValue{ target.Has##name() };                         \
        target.Clear##name();                                              \
        if (hadValue)                                                      \
        {                                                                  \
            _NotifyChanges(L"Has" #name, L#name, L#name "OverrideSource"); \
        }                                                                  \
    }                                                                      \
    auto name##OverrideSource() { return target.name##OverrideSource(); }

// Defines a setting that reflects another object's same-named
// setting, but which cannot be erased.
#define PERMANENT_OBSERVABLE_PROJECTED_SETTING(target, name) \
    _BASE_OBSERVABLE_PROJECTED_SETTING(target, name)

// Defines a basic observable property that uses the _NotifyChanges

Review comment (suggestion):
Wait. These shouldn't be necessary right? "OverrideSource" is the deduced value from our parent. So changing any setting shouldn't affect the value we get from our parent.

Code after:
    }

    // template recursion base case: single dispatch
    void _NotifyChanges(const std::wstring_view name) { _NotifyChangeCore(name); }

    template<typename... Args>
    void _NotifyChanges(const std::wstring_view name, Args&&... more)
    {
        _NotifyChangeCore(name);
        _NotifyChanges(std::forward<Args>(more)...);
    }

private:
    winrt::event<::winrt::Windows::UI::Xaml::Data::PropertyChangedEventHandler> _propertyChangedHandlers;
};

#define _BASE_OBSERVABLE_PROJECTED_SETTING(target, name)  \
public:                                                   \
    auto name() const noexcept { return target.name(); }; \
    template<typename T>                                  \
    void name(const T& value)                             \
    {                                                     \
        if (name() != value)                              \
        {                                                 \
            target.name(value);                           \
            _NotifyChanges(L"Has" #name, L#name);         \
        }                                                 \
    }                                                     \
    bool Has##name() { return target.Has##name(); }

// Defines a setting that reflects another object's same-named
// setting.
#define OBSERVABLE_PROJECTED_SETTING(target, name)   \
    _BASE_OBSERVABLE_PROJECTED_SETTING(target, name) \
    void Clear##name()                               \
    {                                                \
        const auto hadValue{ target.Has##name() };   \
        target.Clear##name();                        \
        if (hadValue)                                \
        {                                            \
            _NotifyChanges(L"Has" #name, L#name);    \
        }                                            \
    }                                                \
    auto name##OverrideSource() { return target.name##OverrideSource(); }

// Defines a setting that reflects another object's same-named
// setting, but which cannot be erased.
#define PERMANENT_OBSERVABLE_PROJECTED_SETTING(target, name) \
    _BASE_OBSERVABLE_PROJECTED_SETTING(target, name)

// Defines a basic observable property that uses the _NotifyChanges