2026-03-03 03:04:10 +08:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
|
|
#include "BehaviorRegistry.h"
|
|
|
|
|
|
|
|
|
|
BehaviorRegistry::BehaviorRegistry(DispenseItemBehavior *defaultValue)
|
|
|
|
|
{
|
|
|
|
|
defaultBehavior = defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BehaviorRegistry::~BehaviorRegistry()
|
|
|
|
|
{
|
2026-03-06 02:11:18 +07:00
|
|
|
for( auto& it : storage )
|
2026-03-03 03:04:10 +08:00
|
|
|
{
|
2026-03-06 02:11:18 +07:00
|
|
|
delete it.second;
|
2026-03-03 03:04:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete defaultBehavior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DispenseItemBehavior *BehaviorRegistry::get(Item *key)
|
|
|
|
|
{
|
2026-03-06 02:11:18 +07:00
|
|
|
auto it = storage.find(key);
|
2026-03-03 03:04:10 +08:00
|
|
|
|
|
|
|
|
return (it == storage.end()) ? defaultBehavior : it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BehaviorRegistry::add(Item *key, DispenseItemBehavior *value)
|
|
|
|
|
{
|
|
|
|
|
storage.insert(make_pair(key, value));
|
|
|
|
|
}
|