From d6634fcd2433e18eea1a9bf31da6d7e531817d77 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 22 Oct 2012 19:54:10 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system sanitized param block code to accept isValid and isProvided at any point added predicates to control serialization --- indra/llcommon/llpredicate.h | 173 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 indra/llcommon/llpredicate.h (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h new file mode 100644 index 0000000000..ad5ab363fa --- /dev/null +++ b/indra/llcommon/llpredicate.h @@ -0,0 +1,173 @@ +/** + * @file llpredicate.h + * @brief abstraction for filtering objects by predicates, with arbitrary boolean expressions + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLPREDICATE_H +#define LL_LLPREDICATE_H + +#include "llerror.h" + +namespace LLPredicate +{ + template class Rule; + + template + struct Value + { + friend Rule; + public: + Value(ENUM e) + : mPredicateFlags(0x1), + mPredicateCombinationFlags(0x1) + { + set(e); + } + + Value() + : mPredicateFlags(0x1), + mPredicateCombinationFlags(0x1) + {} + + void set(ENUM predicate) + { + llassert(predicate <= 5); + int predicate_flag = 0x1 << (0x1 << (int)predicate); + if (!(mPredicateFlags & predicate_flag)) + { + mPredicateCombinationFlags *= predicate_flag; + mPredicateFlags |= predicate_flag; + } + } + + bool get(ENUM predicate) + { + int predicate_flag = 0x1 << (0x1 << (int)predicate); + return (mPredicateFlags & predicate_flag) != 0; + } + + void clear(ENUM predicate) + { + llassert(predicate <= 5); + int predicate_flag = 0x1 << (0x1 << (int)predicate); + if (mPredicateFlags & predicate_flag) + { + mPredicateCombinationFlags /= predicate_flag; + mPredicateFlags &= ~predicate_flag; + } + } + + private: + int mPredicateCombinationFlags; + int mPredicateFlags; + }; + + struct EmptyRule {}; + + template + class Rule + { + public: + Rule(EmptyRule e) + : mPredicateRequirements(0x1) + {} + + Rule(ENUM value) + : mPredicateRequirements(predicateFromValue(value)) + {} + + Rule() + : mPredicateRequirements(0x1) + {} + + Rule operator~() + { + Rule new_rule; + new_rule.mPredicateRequirements = ~mPredicateRequirements; + return new_rule; + } + + Rule operator &&(const Rule& other) + { + Rule new_rule; + new_rule.mPredicateRequirements = mPredicateRequirements & other.mPredicateRequirements; + return new_rule; + } + + Rule operator ||(const Rule& other) + { + Rule new_rule; + new_rule.mPredicateRequirements = mPredicateRequirements | other.mPredicateRequirements; + return new_rule; + } + + bool check(const Value& value) const + { + return ((value.mPredicateCombinationFlags | 0x1) & mPredicateRequirements) != 0; + } + + static int predicateFromValue(ENUM value) + { + int countdown = value; + bool bit_val = false; + + int predicate = 0x0; + + for (int bit_index = 0; bit_index < 32; bit_index++) + { + if (bit_val) + { + predicate |= 0x1 << bit_index; + } + + if (countdown-- == 0) + { + countdown = value; + bit_val = !bit_val; + } + } + return predicate; + } + + bool isTriviallyTrue() const + { + return mPredicateRequirements & 0x1; + } + + bool isTriviallyFalse() const + { + return mPredicateRequirements == 0; + } + + private: + int mPredicateRequirements; + }; + + template + Rule make_rule(ENUM e) { return Rule(e);} + + EmptyRule make_rule(); + +} +#endif // LL_LLPREDICATE_H -- cgit v1.2.3 From 638a16eedd12fe03b85703fb821bc05f40aab355 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 23 Oct 2012 22:35:47 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system improved predicate system, added uncertain/unknown predicates --- indra/llcommon/llpredicate.h | 71 ++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index ad5ab363fa..35ef22138c 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -42,34 +42,28 @@ namespace LLPredicate : mPredicateFlags(0x1), mPredicateCombinationFlags(0x1) { - set(e); + add(e); } Value() - : mPredicateFlags(0x1), + : mPredicateFlags(0x1), mPredicateCombinationFlags(0x1) {} - void set(ENUM predicate) + void add(ENUM predicate) { - llassert(predicate <= 5); - int predicate_flag = 0x1 << (0x1 << (int)predicate); - if (!(mPredicateFlags & predicate_flag)) + llassert(predicate < 5); + if (!has(predicate)) { + int predicate_flag = 0x1 << (0x1 << (int)predicate); mPredicateCombinationFlags *= predicate_flag; mPredicateFlags |= predicate_flag; } } - bool get(ENUM predicate) - { - int predicate_flag = 0x1 << (0x1 << (int)predicate); - return (mPredicateFlags & predicate_flag) != 0; - } - - void clear(ENUM predicate) + void remove(ENUM predicate) { - llassert(predicate <= 5); + llassert(predicate < 5); int predicate_flag = 0x1 << (0x1 << (int)predicate); if (mPredicateFlags & predicate_flag) { @@ -78,6 +72,19 @@ namespace LLPredicate } } + void unknown(ENUM predicate) + { + add(predicate); + int predicate_shift = 0x1 << (int)predicate; + mPredicateCombinationFlags |= mPredicateCombinationFlags << predicate_shift; + } + + bool has(ENUM predicate) + { + int predicate_flag = 0x1 << (0x1 << (int)predicate); + return (mPredicateFlags & predicate_flag) != 0; + } + private: int mPredicateCombinationFlags; int mPredicateFlags; @@ -89,16 +96,12 @@ namespace LLPredicate class Rule { public: - Rule(EmptyRule e) - : mPredicateRequirements(0x1) - {} - Rule(ENUM value) - : mPredicateRequirements(predicateFromValue(value)) + : mPredicateRequirements(predicateFromValue(value)) {} Rule() - : mPredicateRequirements(0x1) + : mPredicateRequirements(0x1) {} Rule operator~() @@ -129,25 +132,16 @@ namespace LLPredicate static int predicateFromValue(ENUM value) { - int countdown = value; - bool bit_val = false; - - int predicate = 0x0; - - for (int bit_index = 0; bit_index < 32; bit_index++) + llassert(value < 5); + static const int predicates[5] = { - if (bit_val) - { - predicate |= 0x1 << bit_index; - } - - if (countdown-- == 0) - { - countdown = value; - bit_val = !bit_val; - } - } - return predicate; + 0xAAAAaaaa, // 10101010101010101010101010101010 + 0xCCCCcccc, // 11001100110011001100110011001100 + 0xF0F0F0F0, // 11110000111100001111000011110000 + 0xFF00FF00, // 11111111000000001111111100000000 + 0xFFFF0000 // 11111111111111110000000000000000 + }; + return predicates[value]; } bool isTriviallyTrue() const @@ -167,6 +161,7 @@ namespace LLPredicate template Rule make_rule(ENUM e) { return Rule(e);} + // return generic empty rule class to avoid requiring template argument to create an empty rule EmptyRule make_rule(); } -- cgit v1.2.3 From 28179ab0070a1c13193808bc1493761a8fed167f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 23 Oct 2012 23:12:33 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system cleaned up predicate system, made unknown work with remove --- indra/llcommon/llpredicate.h | 55 ++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 35ef22138c..096238713c 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -33,21 +33,21 @@ namespace LLPredicate { template class Rule; + int predicateFlagsFromValue(int value); + template struct Value { friend Rule; public: Value(ENUM e) - : mPredicateFlags(0x1), - mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0x1) { add(e); } Value() - : mPredicateFlags(0x1), - mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0x1) {} void add(ENUM predicate) @@ -55,39 +55,42 @@ namespace LLPredicate llassert(predicate < 5); if (!has(predicate)) { - int predicate_flag = 0x1 << (0x1 << (int)predicate); - mPredicateCombinationFlags *= predicate_flag; - mPredicateFlags |= predicate_flag; + int predicate_shift = 0x1 << (int)predicate; + mPredicateCombinationFlags <<= predicate_shift; } } void remove(ENUM predicate) { llassert(predicate < 5); - int predicate_flag = 0x1 << (0x1 << (int)predicate); - if (mPredicateFlags & predicate_flag) - { - mPredicateCombinationFlags /= predicate_flag; - mPredicateFlags &= ~predicate_flag; - } + int predicate_shift = 0x1 << (int)predicate; + int flag_mask = predicateFlagsFromValue(predicate); + int flags_to_modify = mPredicateCombinationFlags & flag_mask; + // clear flags containing predicate to be removed + mPredicateCombinationFlags &= ~flag_mask; + // shift flags, in effect removing predicate + flags_to_modify >>= predicate_shift; + // put modified flags back + mPredicateCombinationFlags |= flags_to_modify; } void unknown(ENUM predicate) { add(predicate); - int predicate_shift = 0x1 << (int)predicate; - mPredicateCombinationFlags |= mPredicateCombinationFlags << predicate_shift; + int flags_with_predicate = mPredicateCombinationFlags; + remove(predicate); + // unknown is result of adding and removing predicate at the same time! + mPredicateCombinationFlags |= flags_with_predicate; } bool has(ENUM predicate) { - int predicate_flag = 0x1 << (0x1 << (int)predicate); - return (mPredicateFlags & predicate_flag) != 0; + int flag_mask = predicateFlagsFromValue(predicate); + return (mPredicateCombinationFlags & flag_mask) != 0; } private: int mPredicateCombinationFlags; - int mPredicateFlags; }; struct EmptyRule {}; @@ -97,7 +100,7 @@ namespace LLPredicate { public: Rule(ENUM value) - : mPredicateRequirements(predicateFromValue(value)) + : mPredicateRequirements(predicateFlagsFromValue(value)) {} Rule() @@ -130,20 +133,6 @@ namespace LLPredicate return ((value.mPredicateCombinationFlags | 0x1) & mPredicateRequirements) != 0; } - static int predicateFromValue(ENUM value) - { - llassert(value < 5); - static const int predicates[5] = - { - 0xAAAAaaaa, // 10101010101010101010101010101010 - 0xCCCCcccc, // 11001100110011001100110011001100 - 0xF0F0F0F0, // 11110000111100001111000011110000 - 0xFF00FF00, // 11111111000000001111111100000000 - 0xFFFF0000 // 11111111111111110000000000000000 - }; - return predicates[value]; - } - bool isTriviallyTrue() const { return mPredicateRequirements & 0x1; -- cgit v1.2.3 From 1de6ecb23851e0784016a2c4c9f691c976c6bda7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 23 Oct 2012 23:35:15 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system converted "int" to "S32" --- indra/llcommon/llpredicate.h | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 096238713c..5fd1d30295 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -33,7 +33,7 @@ namespace LLPredicate { template class Rule; - int predicateFlagsFromValue(int value); + S32 predicateFlagsFromValue(S32 value); template struct Value @@ -41,31 +41,35 @@ namespace LLPredicate friend Rule; public: Value(ENUM e) - : mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0xFFFFffff) { add(e); } Value() - : mPredicateCombinationFlags(0x1) + : mPredicateCombinationFlags(0xFFFFffff) {} void add(ENUM predicate) { llassert(predicate < 5); - if (!has(predicate)) - { - int predicate_shift = 0x1 << (int)predicate; - mPredicateCombinationFlags <<= predicate_shift; - } + S32 predicate_shift = 0x1 << (S32)predicate; + S32 flag_mask = predicateFlagsFromValue(predicate); + S32 flags_to_modify = mPredicateCombinationFlags & ~flag_mask; + // clear flags containing predicate to be removed + mPredicateCombinationFlags &= ~flag_mask; + // shift flags, in effect removing predicate + flags_to_modify <<= predicate_shift; + // put modified flags back + mPredicateCombinationFlags |= flags_to_modify; } void remove(ENUM predicate) { llassert(predicate < 5); - int predicate_shift = 0x1 << (int)predicate; - int flag_mask = predicateFlagsFromValue(predicate); - int flags_to_modify = mPredicateCombinationFlags & flag_mask; + S32 predicate_shift = 0x1 << (S32)predicate; + S32 flag_mask = predicateFlagsFromValue(predicate); + S32 flags_to_modify = mPredicateCombinationFlags & flag_mask; // clear flags containing predicate to be removed mPredicateCombinationFlags &= ~flag_mask; // shift flags, in effect removing predicate @@ -77,7 +81,7 @@ namespace LLPredicate void unknown(ENUM predicate) { add(predicate); - int flags_with_predicate = mPredicateCombinationFlags; + S32 flags_with_predicate = mPredicateCombinationFlags; remove(predicate); // unknown is result of adding and removing predicate at the same time! mPredicateCombinationFlags |= flags_with_predicate; @@ -85,12 +89,12 @@ namespace LLPredicate bool has(ENUM predicate) { - int flag_mask = predicateFlagsFromValue(predicate); + S32 flag_mask = predicateFlagsFromValue(predicate); return (mPredicateCombinationFlags & flag_mask) != 0; } private: - int mPredicateCombinationFlags; + S32 mPredicateCombinationFlags; }; struct EmptyRule {}; @@ -144,7 +148,7 @@ namespace LLPredicate } private: - int mPredicateRequirements; + S32 mPredicateRequirements; }; template -- cgit v1.2.3 From 3ffd0be53af0c5338e6fdc77d240e976aeb10451 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 26 Oct 2012 20:03:33 -0700 Subject: SH-3405 WIP convert existing stats to lltrace system fixed llpredicate so that values and rules work uniformly with predicate logic and/or/negate works in parallel with set/clear --- indra/llcommon/llpredicate.h | 199 +++++++++++++++++++++++++++---------------- 1 file changed, 125 insertions(+), 74 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 5fd1d30295..3f1bf1c8e6 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -33,129 +33,180 @@ namespace LLPredicate { template class Rule; - S32 predicateFlagsFromValue(S32 value); + extern const U32 cPredicateFlagsFromEnum[5]; template - struct Value + class Literal { friend Rule; + public: - Value(ENUM e) - : mPredicateCombinationFlags(0xFFFFffff) + typedef U32 predicate_flag_t; + static const S32 cMaxEnum = 5; + + Literal(ENUM e) + : mPredicateFlags(cPredicateFlagsFromEnum[e]) { - add(e); + llassert(0 <= e && e < cMaxEnum); } - Value() - : mPredicateCombinationFlags(0xFFFFffff) + Literal() + : mPredicateFlags(0xFFFFffff) {} - void add(ENUM predicate) + Literal operator~() { - llassert(predicate < 5); - S32 predicate_shift = 0x1 << (S32)predicate; - S32 flag_mask = predicateFlagsFromValue(predicate); - S32 flags_to_modify = mPredicateCombinationFlags & ~flag_mask; - // clear flags containing predicate to be removed - mPredicateCombinationFlags &= ~flag_mask; - // shift flags, in effect removing predicate - flags_to_modify <<= predicate_shift; - // put modified flags back - mPredicateCombinationFlags |= flags_to_modify; + Literal new_rule; + new_rule.mPredicateFlags = ~mPredicateFlags; + return new_rule; } - void remove(ENUM predicate) + Literal operator &&(const Literal& other) { - llassert(predicate < 5); - S32 predicate_shift = 0x1 << (S32)predicate; - S32 flag_mask = predicateFlagsFromValue(predicate); - S32 flags_to_modify = mPredicateCombinationFlags & flag_mask; - // clear flags containing predicate to be removed - mPredicateCombinationFlags &= ~flag_mask; - // shift flags, in effect removing predicate - flags_to_modify >>= predicate_shift; - // put modified flags back - mPredicateCombinationFlags |= flags_to_modify; + Literal new_rule; + new_rule.mPredicateFlags = mPredicateFlags & other.mPredicateFlags; + return new_rule; } - void unknown(ENUM predicate) + Literal operator ||(const Literal& other) { - add(predicate); - S32 flags_with_predicate = mPredicateCombinationFlags; - remove(predicate); - // unknown is result of adding and removing predicate at the same time! - mPredicateCombinationFlags |= flags_with_predicate; + Literal new_rule; + new_rule.mPredicateFlags = mPredicateFlags | other.mPredicateFlags; + return new_rule; } - bool has(ENUM predicate) + void set(ENUM e, bool value) { - S32 flag_mask = predicateFlagsFromValue(predicate); - return (mPredicateCombinationFlags & flag_mask) != 0; + llassert(0 <= e && e < cMaxEnum); + modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value); + } + + void set(const Literal& 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(lsb_flag, mask, value); + + predicate_flags = next_flags; + } + } + + void forget(ENUM e) + { + set(e, true); + U32 flags_with_predicate = mPredicateFlags; + set(e, false); + // ambiguous value is result of adding and removing predicate at the same time! + mPredicateFlags |= flags_with_predicate; + } + + void forget(const Literal& literal) + { + set(literal, true); + U32 flags_with_predicate = mPredicateFlags; + set(literal, false); + // ambiguous value is result of adding and removing predicate at the same time! + mPredicateFlags |= flags_with_predicate; } private: - S32 mPredicateCombinationFlags; + + predicate_flag_t clearLSB(predicate_flag_t value) + { + return value & (value - 1); + } + + void modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, bool value) + { + llassert(clearLSB(predicate_flag) == 0); + predicate_flag_t flags_to_modify; + + if (value) + { + flags_to_modify = (mPredicateFlags & ~mask); + // clear flags not containing predicate to be added + mPredicateFlags &= mask; + // shift flags, in effect adding predicate + flags_to_modify *= predicate_flag; + } + else + { + flags_to_modify = mPredicateFlags & mask; + // clear flags containing predicate to be removed + mPredicateFlags &= ~mask; + // shift flags, in effect removing predicate + flags_to_modify /= predicate_flag; + } + // put modified flags back + mPredicateFlags |= flags_to_modify; + } + + predicate_flag_t mPredicateFlags; }; - struct EmptyRule {}; + template + struct Value + : public Literal + { + public: + Value(ENUM e) + : Literal(e) + {} + + Value() + {} + }; template class Rule + : public Literal { public: Rule(ENUM value) - : mPredicateRequirements(predicateFlagsFromValue(value)) + : Literal(value) {} - Rule() - : mPredicateRequirements(0x1) + Rule(const Literal other) + : Literal(other) {} - Rule operator~() - { - Rule new_rule; - new_rule.mPredicateRequirements = ~mPredicateRequirements; - return new_rule; - } - - Rule operator &&(const Rule& other) - { - Rule new_rule; - new_rule.mPredicateRequirements = mPredicateRequirements & other.mPredicateRequirements; - return new_rule; - } - - Rule operator ||(const Rule& other) - { - Rule new_rule; - new_rule.mPredicateRequirements = mPredicateRequirements | other.mPredicateRequirements; - return new_rule; - } + Rule() + {} bool check(const Value& value) const { - return ((value.mPredicateCombinationFlags | 0x1) & mPredicateRequirements) != 0; + return (value.mPredicateFlags & mPredicateFlags) != 0; } bool isTriviallyTrue() const { - return mPredicateRequirements & 0x1; + return mPredicateFlags == 0xFFFFffff; } bool isTriviallyFalse() const { - return mPredicateRequirements == 0; + return mPredicateFlags == 0; } - - private: - S32 mPredicateRequirements; }; +} - template - Rule make_rule(ENUM e) { return Rule(e);} +template +LLPredicate::Literal ll_predicate(ENUM e) +{ + return LLPredicate::Literal(e); +} - // return generic empty rule class to avoid requiring template argument to create an empty rule - EmptyRule make_rule(); -} #endif // LL_LLPREDICATE_H -- cgit v1.2.3 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 From bb6bda9eef48f5b08b56af46321b79fe7f1d49d7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 1 Nov 2012 19:55:06 -0700 Subject: SH-3499 Ensure asset stats output is correct added support for specifying predicates for xui and llsd serialization --- indra/llcommon/llpredicate.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index a13172da68..3f7abe67f1 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -42,8 +42,8 @@ namespace LLPredicate typedef U32 predicate_flag_t; static const S32 cMaxEnum = 5; - Value(ENUM e) - : mPredicateFlags(cPredicateFlagsFromEnum[e]) + Value(ENUM e, bool predicate_value = true) + : mPredicateFlags(predicate_value ? cPredicateFlagsFromEnum[e] : ~cPredicateFlagsFromEnum[e]) { llassert(0 <= e && e < cMaxEnum); } @@ -227,9 +227,9 @@ namespace LLPredicate } template -LLPredicate::Value ll_predicate(ENUM e) +LLPredicate::Value ll_make_predicate(ENUM e, bool predicate_value = true) { - return LLPredicate::Value(e); + return LLPredicate::Value(e, predicate_value); } -- cgit v1.2.3 From f8eaee753174d0cab4e4edcf795f422706d6f302 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 2 Nov 2012 20:03:44 -0700 Subject: SH-3499 Ensure asset stats output is correct improvements to predicate API default rules encapsulated in LLInitParam removed empty flag from viewer asset stats --- indra/llcommon/llpredicate.h | 80 ++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 32 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 3f7abe67f1..6c9e5fc145 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -73,43 +73,37 @@ namespace LLPredicate return new_value; } - void set(ENUM e, bool value) + void set(ENUM e, bool value = true) { llassert(0 <= e && e < cMaxEnum); - modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value); + mPredicateFlags = modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value, mPredicateFlags); } void set(const Value other, bool value) { - U32 predicate_flags = other.mPredicateFlags; - while(predicate_flags) + predicate_flag_t predicate_flags_to_set = other.mPredicateFlags; + predicate_flag_t cumulative_flags = 0; + while(predicate_flags_to_set) { - U32 next_flags = clearLSB(predicate_flags); - lsb_flag = predicate_flags ^ next_flags; + predicate_flag_t next_flags = clearLSB(predicate_flags_to_set); + predicate_flag_t lsb_flag = predicate_flags_to_set ^ next_flags; - U32 mask = 0; + predicate_flag_t mask = 0; + predicate_flag_t cur_flags = mPredicateFlags; for (S32 i = 0; i < cMaxEnum; i++) { if (cPredicateFlagsFromEnum[i] & lsb_flag) { mask |= cPredicateFlagsFromEnum[i]; - modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value); + cur_flags = modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value, cur_flags); } } - modifyPredicate(lsb_flag, mask, value); + cumulative_flags |= modifyPredicate(lsb_flag, mask, value, cur_flags); - predicate_flags = next_flags; - } - } - - void forget(ENUM e) - { - set(e, true); - U32 flags_with_predicate = mPredicateFlags; - set(e, false); - // ambiguous value is result of adding and removing predicate at the same time! - mPredicateFlags |= flags_with_predicate; + predicate_flags_to_set = next_flags; + } + mPredicateFlags = cumulative_flags; } void forget(const Value value) @@ -131,6 +125,11 @@ namespace LLPredicate return mPredicateFlags == 0; } + bool someSet() const + { + return mPredicateFlags != 0; + } + private: predicate_flag_t clearLSB(predicate_flag_t value) @@ -138,16 +137,16 @@ namespace LLPredicate return value & (value - 1); } - void modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, bool value) + predicate_flag_t modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, predicate_flag_t value, bool set) { llassert(clearLSB(predicate_flag) == 0); predicate_flag_t flags_to_modify; - if (value) + if (set) { flags_to_modify = (mPredicateFlags & ~mask); // clear flags not containing predicate to be added - mPredicateFlags &= mask; + value &= mask; // shift flags, in effect adding predicate flags_to_modify *= predicate_flag; } @@ -155,12 +154,13 @@ namespace LLPredicate { flags_to_modify = mPredicateFlags & mask; // clear flags containing predicate to be removed - mPredicateFlags &= ~mask; + value &= ~mask; // shift flags, in effect removing predicate flags_to_modify /= predicate_flag; } // put modified flags back - mPredicateFlags |= flags_to_modify; + value |= flags_to_modify; + return value; } predicate_flag_t mPredicateFlags; @@ -174,10 +174,6 @@ namespace LLPredicate : mRule(value) {} - Rule(const Rule& other) - : mRule(other.mRule) - {} - Rule(const Value other) : mRule(other) {} @@ -185,17 +181,37 @@ namespace LLPredicate Rule() {} + void require(const Value value) + { + mRule.set(value, require); + } + + void allow(const Value value) + { + mRule.forget(value); + } + bool check(const Value value) const { - return !(mRule && value).noneSet(); + return (mRule && value).someSet(); + } + + bool requires(const Value value) const + { + return (mRule && value).someSet() && (!mRule && value).noneSet(); + } + + bool isAmbivalent(const Value value) const + { + return (mRule && value).someSet() && (!mRule && value).someSet(); } - bool isTriviallyTrue() const + bool acceptsAll() const { return mRule.allSet(); } - bool isTriviallyFalse() const + bool acceptsNone() const { return mRule.noneSet(); } -- cgit v1.2.3 From 0007114cf5a60779319ab8cbd0a23a0d462b8010 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 5 Nov 2012 16:10:57 -0800 Subject: SH-3499 WIP Ensure asset stats output is correct fixed copy behavior of recordings and accumulator buffers --- indra/llcommon/llpredicate.h | 90 ++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 66 deletions(-) (limited to 'indra/llcommon/llpredicate.h') diff --git a/indra/llcommon/llpredicate.h b/indra/llcommon/llpredicate.h index 6c9e5fc145..a0e970a799 100644 --- a/indra/llcommon/llpredicate.h +++ b/indra/llcommon/llpredicate.h @@ -76,41 +76,31 @@ namespace LLPredicate void set(ENUM e, bool value = true) { llassert(0 <= e && e < cMaxEnum); - mPredicateFlags = modifyPredicate(0x1 << (S32)e, cPredicateFlagsFromEnum[e], value, mPredicateFlags); - } - - void set(const Value other, bool value) - { - predicate_flag_t predicate_flags_to_set = other.mPredicateFlags; - predicate_flag_t cumulative_flags = 0; - while(predicate_flags_to_set) - { - predicate_flag_t next_flags = clearLSB(predicate_flags_to_set); - predicate_flag_t lsb_flag = predicate_flags_to_set ^ next_flags; - - predicate_flag_t mask = 0; - predicate_flag_t cur_flags = mPredicateFlags; - for (S32 i = 0; i < cMaxEnum; i++) - { - if (cPredicateFlagsFromEnum[i] & lsb_flag) - { - mask |= cPredicateFlagsFromEnum[i]; - cur_flags = modifyPredicate(0x1 << (0x1 << i ), cPredicateFlagsFromEnum[i], !value, cur_flags); - } - } - - cumulative_flags |= modifyPredicate(lsb_flag, mask, value, cur_flags); - - predicate_flags_to_set = next_flags; + predicate_flag_t flags_to_modify; + predicate_flag_t mask = cPredicateFlagsFromEnum[e]; + if (value) + { // add predicate "e" to flags that don't contain it already + flags_to_modify = (mPredicateFlags & ~mask); + // clear flags not containing e + mPredicateFlags &= mask; + // add back flags shifted to contain e + mPredicateFlags |= flags_to_modify << (0x1 << e); + } + else + { // remove predicate "e" from flags that contain it + flags_to_modify = (mPredicateFlags & mask); + // clear flags containing e + mPredicateFlags &= ~mask; + // add back flags shifted to not contain e + mPredicateFlags |= flags_to_modify >> (0x1 << e); } - mPredicateFlags = cumulative_flags; } - void forget(const Value value) + void forget(ENUM e) { - set(value, true); + set(e, true); U32 flags_with_predicate = mPredicateFlags; - set(value, false); + set(e, false); // ambiguous value is result of adding and removing predicate at the same time! mPredicateFlags |= flags_with_predicate; } @@ -131,38 +121,6 @@ namespace LLPredicate } private: - - predicate_flag_t clearLSB(predicate_flag_t value) - { - return value & (value - 1); - } - - predicate_flag_t modifyPredicate(predicate_flag_t predicate_flag, predicate_flag_t mask, predicate_flag_t value, bool set) - { - llassert(clearLSB(predicate_flag) == 0); - predicate_flag_t flags_to_modify; - - if (set) - { - flags_to_modify = (mPredicateFlags & ~mask); - // clear flags not containing predicate to be added - value &= mask; - // shift flags, in effect adding predicate - flags_to_modify *= predicate_flag; - } - else - { - flags_to_modify = mPredicateFlags & mask; - // clear flags containing predicate to be removed - value &= ~mask; - // shift flags, in effect removing predicate - flags_to_modify /= predicate_flag; - } - // put modified flags back - value |= flags_to_modify; - return value; - } - predicate_flag_t mPredicateFlags; }; @@ -181,14 +139,14 @@ namespace LLPredicate Rule() {} - void require(const Value value) + void require(ENUM e) { - mRule.set(value, require); + mRule.set(e, require); } - void allow(const Value value) + void allow(ENUM e) { - mRule.forget(value); + mRule.forget(e); } bool check(const Value value) const -- cgit v1.2.3