From b71e991c1860bbea0387f9434cc2b4b31a26469a Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 29 Oct 2012 18:44:37 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed predicate update logic and reduced to 2 classes --- indra/llcommon/llpredicate.h | 112 ++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 44 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 3f1bf1c8e6..a13172da68 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -36,43 +36,41 @@ namespace LLPredicate extern const U32 cPredicateFlagsFromEnum[5]; template - class Literal + class Value { - friend Rule; - public: typedef U32 predicate_flag_t; static const S32 cMaxEnum = 5; - Literal(ENUM e) + Value(ENUM e) : mPredicateFlags(cPredicateFlagsFromEnum[e]) { llassert(0 <= e && e < cMaxEnum); } - Literal() + Value() : mPredicateFlags(0xFFFFffff) {} - Literal operator~() + Value operator!() const { - Literal new_rule; - new_rule.mPredicateFlags = ~mPredicateFlags; - return new_rule; + Value new_value; + new_value.mPredicateFlags = ~mPredicateFlags; + return new_value; } - Literal operator &&(const Literal& other) + Value operator &&(const Value other) const { - Literal new_rule; - new_rule.mPredicateFlags = mPredicateFlags & other.mPredicateFlags; - return new_rule; + Value new_value; + new_value.mPredicateFlags = mPredicateFlags & other.mPredicateFlags; + return new_value; } - Literal operator ||(const Literal& other) + Value operator ||(const Value other) const { - Literal new_rule; - new_rule.mPredicateFlags = mPredicateFlags | other.mPredicateFlags; - return new_rule; + Value new_value; + new_value.mPredicateFlags = mPredicateFlags | other.mPredicateFlags; + return new_value; } void set(ENUM e, bool value) @@ -81,19 +79,21 @@ namespace LLPredicate modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value); } - void set(const Literal& other, bool value) + void set(const Value other, bool value) { U32 predicate_flags = other.mPredicateFlags; while(predicate_flags) { U32 next_flags = clearLSB(predicate_flags); lsb_flag = predicate_flags ^ next_flags; + U32 mask = 0; for (S32 i = 0; i < cMaxEnum; i++) { if (cPredicateFlagsFromEnum[i] & lsb_flag) { mask |= cPredicateFlagsFromEnum[i]; + modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value); } } @@ -112,15 +112,25 @@ namespace LLPredicate mPredicateFlags |= flags_with_predicate; } - void forget(const Literal& literal) + void forget(const Value value) { - set(literal, true); + set(value, true); U32 flags_with_predicate = mPredicateFlags; - set(literal, false); + set(value, false); // ambiguous value is result of adding and removing predicate at the same time! mPredicateFlags |= flags_with_predicate; } + bool allSet() const + { + return mPredicateFlags == ~0; + } + + bool noneSet() const + { + return mPredicateFlags == 0; + } + private: predicate_flag_t clearLSB(predicate_flag_t value) @@ -156,56 +166,70 @@ namespace LLPredicate predicate_flag_t mPredicateFlags; }; - template - struct Value - : public Literal - { - public: - Value(ENUM e) - : Literal(e) - {} - - Value() - {} - }; - template class Rule - : public Literal { public: Rule(ENUM value) - : Literal(value) + : mRule(value) + {} + + Rule(const Rule& other) + : mRule(other.mRule) {} - Rule(const Literal other) - : Literal(other) + Rule(const Value other) + : mRule(other) {} Rule() {} - bool check(const Value& value) const + bool check(const Value value) const { - return (value.mPredicateFlags & mPredicateFlags) != 0; + return !(mRule && value).noneSet(); } bool isTriviallyTrue() const { - return mPredicateFlags == 0xFFFFffff; + return mRule.allSet(); } bool isTriviallyFalse() const { - return mPredicateFlags == 0; + return mRule.noneSet(); + } + + Rule operator!() const + { + Rule new_rule; + new_rule.mRule = !mRule; + return new_rule; } + + Rule operator &&(const Rule other) const + { + Rule new_rule; + new_rule.mRule = mRule && other.mRule; + return new_rule; + } + + Rule operator ||(const Rule other) const + { + Rule new_rule; + new_rule.mRule = mRule || other.mRule; + return new_rule; + } + + private: + Value mRule; }; } template -LLPredicate::Literal ll_predicate(ENUM e) +LLPredicate::Value ll_predicate(ENUM e) { - return LLPredicate::Literal(e); + return LLPredicate::Value(e); } -- cgit v1.2.3