Skip to content

Commit

Permalink
libdeng2|RuleBank: Added a 'zero' rule
Browse files Browse the repository at this point in the history
When requesting a rule with an empty string, RuleBank now returns the
shared zero rule.
  • Loading branch information
skyjake committed Jun 11, 2013
1 parent 6c3a2c0 commit 38202b1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doomsday/libdeng2/src/widgets/rulebank.cpp
Expand Up @@ -47,7 +47,17 @@ DENG2_PIMPL(RuleBank)
~RuleData() { releaseRef(rule); }
};

Instance(Public *i) : Base(i) {}
ConstantRule *zero;

Instance(Public *i) : Base(i)
{
zero = new ConstantRule(0);
}

~Instance()
{
releaseRef(zero);
}
};

RuleBank::RuleBank() : InfoBank(DisableHotStorage), d(new Instance(this))
Expand All @@ -62,6 +72,7 @@ void RuleBank::addFromInfo(File const &file)

Rule const &RuleBank::rule(DotPath const &path) const
{
if(path.isEmpty()) return *d->zero;
return *static_cast<Instance::RuleData &>(data(path)).rule;
}

Expand Down

0 comments on commit 38202b1

Please sign in to comment.