From 38202b1396d7716905113010fd1744c942930041 Mon Sep 17 00:00:00 2001 From: skyjake Date: Tue, 11 Jun 2013 21:28:54 +0300 Subject: [PATCH] libdeng2|RuleBank: Added a 'zero' rule When requesting a rule with an empty string, RuleBank now returns the shared zero rule. --- doomsday/libdeng2/src/widgets/rulebank.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doomsday/libdeng2/src/widgets/rulebank.cpp b/doomsday/libdeng2/src/widgets/rulebank.cpp index 405cfea757..e331710111 100644 --- a/doomsday/libdeng2/src/widgets/rulebank.cpp +++ b/doomsday/libdeng2/src/widgets/rulebank.cpp @@ -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)) @@ -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(data(path)).rule; }