mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Deprecate Val(double, TypeTag) ctor, add TimeVal/DoubleVal subclasses
This also updates all usages of the deprecated Val ctor to use either IntervalVal, TimeVal, or DoubleVal ctors. The reason for doing away with the old constructor is that using it with TYPE_INTERVAL isn't strictly correct since there exists a more specific subclass, IntervalVal, with overriden ValDescribe() method that ought to be used to print such values in a more descriptive way.
This commit is contained in:
parent
a431f6b45d
commit
5b4313b593
76 changed files with 847 additions and 782 deletions
26
src/Val.cc
26
src/Val.cc
|
@ -271,14 +271,14 @@ IntrusivePtr<Val> Val::SizeVal() const
|
|||
return val_mgr->Count(val.uint_val);
|
||||
|
||||
case TYPE_INTERNAL_DOUBLE:
|
||||
return make_intrusive<Val>(fabs(val.double_val), TYPE_DOUBLE);
|
||||
return make_intrusive<DoubleVal>(fabs(val.double_val));
|
||||
|
||||
case TYPE_INTERNAL_OTHER:
|
||||
if ( type->Tag() == TYPE_FUNC )
|
||||
return val_mgr->Count(val.func_val->GetType()->ParamList()->Types().size());
|
||||
|
||||
if ( type->Tag() == TYPE_FILE )
|
||||
return make_intrusive<Val>(val.file_val->Size(), TYPE_DOUBLE);
|
||||
return make_intrusive<DoubleVal>(val.file_val->Size());
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -666,11 +666,6 @@ IntrusivePtr<StringVal> Val::ToJSON(bool only_loggable, RE_Matcher* re)
|
|||
return make_intrusive<StringVal>(buffer.GetString());
|
||||
}
|
||||
|
||||
IntervalVal::IntervalVal(double quantity, double units) :
|
||||
Val(quantity * units, TYPE_INTERVAL)
|
||||
{
|
||||
}
|
||||
|
||||
void IntervalVal::ValDescribe(ODesc* d) const
|
||||
{
|
||||
using unit_word = std::pair<double, const char*>;
|
||||
|
@ -925,7 +920,7 @@ unsigned int SubNetVal::MemoryAllocation() const
|
|||
IntrusivePtr<Val> SubNetVal::SizeVal() const
|
||||
{
|
||||
int retained = 128 - val.subnet_val->LengthIPv6();
|
||||
return make_intrusive<Val>(pow(2.0, double(retained)), TYPE_DOUBLE);
|
||||
return make_intrusive<DoubleVal>(pow(2.0, double(retained)));
|
||||
}
|
||||
|
||||
void SubNetVal::ValDescribe(ODesc* d) const
|
||||
|
@ -3287,7 +3282,20 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
|
|||
break;
|
||||
|
||||
case TYPE_INTERNAL_DOUBLE:
|
||||
promoted_v = make_intrusive<Val>(v->CoerceToDouble(), t_tag);
|
||||
switch ( t_tag ) {
|
||||
case TYPE_DOUBLE:
|
||||
promoted_v = make_intrusive<DoubleVal>(v->CoerceToDouble());
|
||||
break;
|
||||
case TYPE_INTERVAL:
|
||||
promoted_v = make_intrusive<IntervalVal>(v->CoerceToDouble());
|
||||
break;
|
||||
case TYPE_TIME:
|
||||
promoted_v = make_intrusive<TimeVal>(v->CoerceToDouble());
|
||||
break;
|
||||
default:
|
||||
reporter->InternalError("bad internal type in check_and_promote()");
|
||||
return nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue