mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-10-28 11:29:53 -05:00
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#include "variable-usage.hpp"
|
|
#include "macro-helpers.hpp"
|
|
#include "macro.hpp"
|
|
#include "sync-helpers.hpp"
|
|
#include "variable-ref.hpp"
|
|
|
|
#include <obs.hpp>
|
|
|
|
namespace advss {
|
|
|
|
static std::unordered_map<std::string, int> collectReferences(Macro *macro)
|
|
{
|
|
VariableRefCollector collector;
|
|
OBSDataAutoRelease data = obs_data_create();
|
|
macro->Save(data);
|
|
return collector.Counts();
|
|
}
|
|
|
|
std::unordered_map<std::string, VariableUsage> GetVariableUsage()
|
|
{
|
|
std::unordered_map<std::string, VariableUsage> result;
|
|
auto lock = LockContext();
|
|
// Nested macros are saved as part of their parent macro
|
|
for (const auto ¯o : GetTopLevelMacros()) {
|
|
for (const auto &[name, count] :
|
|
collectReferences(macro.get())) {
|
|
auto &usage = result[name];
|
|
usage.referenceCount += count;
|
|
usage.macroNames.emplace_back(macro->Name());
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::unordered_map<std::string, int> GetVariablesUsedByMacro(Macro *macro)
|
|
{
|
|
if (!macro) {
|
|
return {};
|
|
}
|
|
|
|
return collectReferences(macro);
|
|
}
|
|
|
|
std::unordered_map<std::string, int>
|
|
GetVariablesUsedByMacros(const std::vector<std::shared_ptr<Macro>> ¯os)
|
|
{
|
|
std::unordered_map<std::string, int> result;
|
|
auto lock = LockContext();
|
|
for (const auto ¯o : macros) {
|
|
for (const auto &[name, count] :
|
|
collectReferences(macro.get())) {
|
|
result[name] += count;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} // namespace advss
|