66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#include "ShadeRepository.h"
|
|
#include "Shade.h"
|
|
|
|
void ShadeRepository::upsert(Shade shade)
|
|
{
|
|
for (Shade &existing_shade : shades)
|
|
{
|
|
if (existing_shade.key == shade.key)
|
|
{
|
|
existing_shade.friendlyName = shade.friendlyName;
|
|
existing_shade.ID = shade.ID;
|
|
for (auto &callback : shadeChangedCallbacks) {
|
|
callback(shade);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Didn't find it in the repository, add it
|
|
shades.push_back(shade);
|
|
for (auto &callback : shadeAddedCallbacks) {
|
|
callback(shade);
|
|
}
|
|
}
|
|
|
|
Shade* ShadeRepository::findById(const uint16_t id)
|
|
{
|
|
for (Shade &shade : shades)
|
|
{
|
|
if (shade.ID == id)
|
|
{
|
|
return &shade;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
Shade* ShadeRepository::findByKey(const std::string &key)
|
|
{
|
|
for (Shade &shade : shades)
|
|
{
|
|
if (shade.key == key)
|
|
{
|
|
return &shade;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
std::vector<Shade>::iterator ShadeRepository::begin()
|
|
{
|
|
return shades.begin();
|
|
}
|
|
|
|
std::vector<Shade>::iterator ShadeRepository::end()
|
|
{
|
|
return shades.end();
|
|
}
|
|
|
|
void ShadeRepository::addShadeAddedCallback(std::function<void(Shade&)> callback) {
|
|
shadeAddedCallbacks.push_back(callback);
|
|
}
|
|
|
|
void ShadeRepository::addShadeChangedCallback(std::function<void(Shade&)> callback) {
|
|
shadeChangedCallbacks.push_back(callback);
|
|
} |