summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorRichard Linden <none@none>2012-11-02 20:03:44 -0700
committerRichard Linden <none@none>2012-11-02 20:03:44 -0700
commitf8eaee753174d0cab4e4edcf795f422706d6f302 (patch)
tree7f16a502c6a8c4df57dfa74303a04d66eed74fa7 /indra/llcommon
parentbb6bda9eef48f5b08b56af46321b79fe7f1d49d7 (diff)
SH-3499 Ensure asset stats output is correct
improvements to predicate API default rules encapsulated in LLInitParam removed empty flag from viewer asset stats
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llinitparam.cpp10
-rw-r--r--indra/llcommon/llinitparam.h25
-rw-r--r--indra/llcommon/llpredicate.h80
-rw-r--r--indra/llcommon/llsdparam.cpp4
-rw-r--r--indra/llcommon/llsdparam.h19
5 files changed, 101 insertions, 37 deletions
diff --git a/indra/llcommon/llinitparam.cpp b/indra/llcommon/llinitparam.cpp
index 53254c3b56..d20fc03227 100644
--- a/indra/llcommon/llinitparam.cpp
+++ b/indra/llcommon/llinitparam.cpp
@@ -32,6 +32,12 @@
namespace LLInitParam
{
+
+ predicate_rule_t default_parse_rules()
+ {
+ return ll_make_predicate(PROVIDED) && !ll_make_predicate(EMPTY) && !ll_make_predicate(HAS_DEFAULT_VALUE);
+ }
+
//
// Param
//
@@ -247,6 +253,10 @@ namespace LLInitParam
}
}
+ if (!serialized && predicate_rule.check(ll_make_predicate(EMPTY)))
+ {
+ serialized |= parser.writeValue(Flag(), name_stack);
+ }
// was anything serialized in this block?
return serialized;
}
diff --git a/indra/llcommon/llinitparam.h b/indra/llcommon/llinitparam.h
index c82b1226ee..6177cc7d12 100644
--- a/indra/llcommon/llinitparam.h
+++ b/indra/llcommon/llinitparam.h
@@ -297,11 +297,13 @@ namespace LLInitParam
PROVIDED,
REQUIRED,
VALID,
- NON_DEFAULT
+ HAS_DEFAULT_VALUE,
+ EMPTY
};
typedef LLPredicate::Rule<ESerializePredicates> predicate_rule_t;
+ predicate_rule_t default_parse_rules();
// various callbacks and constraints associated with an individual param
struct LL_COMMON_API ParamDescriptor
@@ -912,7 +914,10 @@ namespace LLInitParam
const self_t* diff_typed_param = static_cast<const self_t*>(diff_param);
LLPredicate::Value<ESerializePredicates> predicate;
- predicate.set(NON_DEFAULT, !diff_typed_param || ParamCompare<T>::equals(typed_param.getValue(), diff_typed_param->getValue()));
+ if (diff_typed_param && ParamCompare<T>::equals(typed_param.getValue(), diff_typed_param->getValue()))
+ {
+ predicate.set(HAS_DEFAULT_VALUE);
+ }
if (typed_param.isValid())
{
@@ -925,6 +930,8 @@ namespace LLInitParam
predicate.set(PROVIDED, false);
}
+ predicate.set(EMPTY, false);
+
if (!predicate_rule.check(predicate)) return false;
if (!name_stack.empty())
@@ -1285,6 +1292,8 @@ namespace LLInitParam
predicate.set(PROVIDED, false);
}
+ predicate.set(EMPTY, typed_param.mValues.empty());
+
if (!predicate_rule.check(predicate)) return false;
for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end();
@@ -1325,6 +1334,12 @@ namespace LLInitParam
name_stack.pop_back();
}
+
+ if (!serialized && predicate_rule.check(ll_make_predicate(EMPTY)))
+ {
+ serialized |= parser.writeValue(Flag(), name_stack);
+ }
+
return serialized;
}
@@ -1567,6 +1582,12 @@ namespace LLInitParam
name_stack.pop_back();
}
+
+ if (!serialized && predicate_rule.check(ll_make_predicate(EMPTY)))
+ {
+ serialized |= parser.writeValue(Flag(), name_stack);
+ }
+
return serialized;
}
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<ENUM> other)
: mRule(other)
{}
@@ -185,17 +181,37 @@ namespace LLPredicate
Rule()
{}
+ void require(const Value<ENUM> value)
+ {
+ mRule.set(value, require);
+ }
+
+ void allow(const Value<ENUM> value)
+ {
+ mRule.forget(value);
+ }
+
bool check(const Value<ENUM> value) const
{
- return !(mRule && value).noneSet();
+ return (mRule && value).someSet();
+ }
+
+ bool requires(const Value<ENUM> value) const
+ {
+ return (mRule && value).someSet() && (!mRule && value).noneSet();
+ }
+
+ bool isAmbivalent(const Value<ENUM> 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();
}
diff --git a/indra/llcommon/llsdparam.cpp b/indra/llcommon/llsdparam.cpp
index c10e1b1e20..345e30f4b4 100644
--- a/indra/llcommon/llsdparam.cpp
+++ b/indra/llcommon/llsdparam.cpp
@@ -102,13 +102,13 @@ void LLParamSDParser::readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool
//readSDValues(sd, block);
}
-void LLParamSDParser::writeSD(LLSD& sd, const LLInitParam::BaseBlock& block, LLInitParam::predicate_rule_t rules)
+void LLParamSDParser::writeSDImpl(LLSD& sd, const LLInitParam::BaseBlock& block, const LLInitParam::predicate_rule_t rules, const LLInitParam::BaseBlock* diff_block)
{
mNameStack.clear();
mWriteRootSD = &sd;
name_stack_t name_stack;
- block.serializeBlock(*this, name_stack, rules);
+ block.serializeBlock(*this, name_stack, rules, diff_block);
}
/*virtual*/ std::string LLParamSDParser::getCurrentElementName()
diff --git a/indra/llcommon/llsdparam.h b/indra/llcommon/llsdparam.h
index 032e506fd8..1181c2d433 100644
--- a/indra/llcommon/llsdparam.h
+++ b/indra/llcommon/llsdparam.h
@@ -50,11 +50,28 @@ typedef LLInitParam::Parser parser_t;
public:
LLParamSDParser();
void readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool silent = false);
- void writeSD(LLSD& sd, const LLInitParam::BaseBlock& block, LLInitParam::predicate_rule_t rules = LLInitParam::predicate_rule_t(LLInitParam::PROVIDED) && LLInitParam::NON_DEFAULT);
+ template<typename BLOCK>
+ void writeSD(LLSD& sd,
+ const BLOCK& block,
+ const LLInitParam::predicate_rule_t rules = LLInitParam::default_parse_rules(),
+ const LLInitParam::BaseBlock* diff_block = NULL)
+ {
+ if (!diff_block
+ && !rules.isAmbivalent(LLInitParam::HAS_DEFAULT_VALUE))
+ {
+ diff_block = &LLInitParam::defaultValue<BLOCK>();
+ }
+ writeSDImpl(sd, block, rules, diff_block);
+ }
/*virtual*/ std::string getCurrentElementName();
private:
+ void writeSDImpl(LLSD& sd,
+ const LLInitParam::BaseBlock& block,
+ const LLInitParam::predicate_rule_t,
+ const LLInitParam::BaseBlock* diff_block);
+
void submit(LLInitParam::BaseBlock& block, const LLSD& sd, LLInitParam::Parser::name_stack_t& name_stack);
template<typename T>