mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 01:28:20 +00:00
Some review cleanup in Val.cc
This commit is contained in:
parent
e652aff277
commit
42f2691251
2 changed files with 27 additions and 17 deletions
27
src/Val.cc
27
src/Val.cc
|
@ -1145,13 +1145,13 @@ ValPtr FileVal::DoClone(CloneState* state)
|
||||||
// I think we can just ref the file here - it is unclear what else
|
// I think we can just ref the file here - it is unclear what else
|
||||||
// to do. In the case of cached files, I think this is equivalent
|
// to do. In the case of cached files, I think this is equivalent
|
||||||
// to what happened before - serialization + unserialization just
|
// to what happened before - serialization + unserialization just
|
||||||
// have you the same pointer that you already had. In the case of
|
// gave you the same pointer that you already had. In the case of
|
||||||
// non-cached files, the behavior now is different; in the past,
|
// non-cached files, the behavior now is different; in the past,
|
||||||
// serialize + unserialize gave you a new file object because the
|
// serialize + unserialize gave you a new file object because the
|
||||||
// old one was not in the list anymore. This object was
|
// old one was not in the list anymore. This object was
|
||||||
// automatically opened. This does not happen anymore - instead you
|
// automatically opened. This does not happen anymore - instead you
|
||||||
// get the non-cached pointer back which is brought back into the
|
// get the non-cached pointer back which is brought back into the
|
||||||
// cache when written too.
|
// cache when written to.
|
||||||
return {NewRef{}, this};
|
return {NewRef{}, this};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3369,10 +3369,10 @@ ValPtr VectorVal::DoClone(CloneState* state)
|
||||||
vv->Reserve(vector_val->size());
|
vv->Reserve(vector_val->size());
|
||||||
state->NewClone(this, vv);
|
state->NewClone(this, vv);
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < vector_val->size(); ++i )
|
for ( const auto& e : *vector_val )
|
||||||
{
|
{
|
||||||
auto v = (*vector_val)[i]->Clone(state);
|
auto vc = e->Clone(state);
|
||||||
vv->Assign(vv->Size(), std::move(v));
|
vv->Append(std::move(vc));
|
||||||
}
|
}
|
||||||
|
|
||||||
return vv;
|
return vv;
|
||||||
|
@ -3382,17 +3382,20 @@ void VectorVal::ValDescribe(ODesc* d) const
|
||||||
{
|
{
|
||||||
d->Add("[");
|
d->Add("[");
|
||||||
|
|
||||||
if ( vector_val->size() > 0 )
|
size_t vector_size = vector_val->size();
|
||||||
for ( unsigned int i = 0; i < (vector_val->size() - 1); ++i )
|
|
||||||
|
if ( vector_size != 0)
|
||||||
{
|
{
|
||||||
if ( (*vector_val)[i] )
|
for ( unsigned int i = 0; i < (vector_size - 1); ++i )
|
||||||
(*vector_val)[i]->Describe(d);
|
{
|
||||||
|
if ( vector_val->at(i) )
|
||||||
|
vector_val->at(i)->Describe(d);
|
||||||
d->Add(", ");
|
d->Add(", ");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( vector_val->size() &&
|
if ( vector_size != 0 && vector_val->back() )
|
||||||
(*vector_val)[vector_val->size() - 1] )
|
vector_val->back()->Describe(d);
|
||||||
(*vector_val)[vector_val->size() - 1]->Describe(d);
|
|
||||||
|
|
||||||
d->Add("]");
|
d->Add("]");
|
||||||
}
|
}
|
||||||
|
|
17
src/Val.h
17
src/Val.h
|
@ -403,7 +403,7 @@ public:
|
||||||
: BoolVal(bro_int_t(b))
|
: BoolVal(bro_int_t(b))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool Get() const { return int_val; }
|
bool Get() const { return static_cast<bool>(int_val); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CountVal : public UnsignedValImplementation {
|
class CountVal : public UnsignedValImplementation {
|
||||||
|
@ -438,7 +438,7 @@ public:
|
||||||
quantity * units)
|
quantity * units)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
double Get() const { return double_val; }
|
// Same as for IntVal: no Get() method needed.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ValDescribe(ODesc* d) const override;
|
void ValDescribe(ODesc* d) const override;
|
||||||
|
@ -449,7 +449,7 @@ public:
|
||||||
TimeVal(double t) : DoubleValImplementation(base_type(TYPE_TIME), t)
|
TimeVal(double t) : DoubleValImplementation(base_type(TYPE_TIME), t)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
double Get() const { return double_val; }
|
// Same as for IntVal: no Get() method needed.
|
||||||
};
|
};
|
||||||
|
|
||||||
class PortVal final : public UnsignedValImplementation {
|
class PortVal final : public UnsignedValImplementation {
|
||||||
|
@ -1328,8 +1328,6 @@ class EnumVal final : public IntValImplementation {
|
||||||
public:
|
public:
|
||||||
ValPtr SizeVal() const override;
|
ValPtr SizeVal() const override;
|
||||||
|
|
||||||
int Get() const { return int_val; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Val;
|
friend class Val;
|
||||||
friend class EnumType;
|
friend class EnumType;
|
||||||
|
@ -1472,6 +1470,15 @@ public:
|
||||||
bool Insert(unsigned int index, Val* element)
|
bool Insert(unsigned int index, Val* element)
|
||||||
{ return Insert(index, {AdoptRef{}, element}); }
|
{ return Insert(index, {AdoptRef{}, element}); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts an element at the end of the vector.
|
||||||
|
* @param element The value to insert into the vector.
|
||||||
|
* @return True if the element was inserted or false if the element was
|
||||||
|
* the wrong type.
|
||||||
|
*/
|
||||||
|
bool Append(ValPtr element)
|
||||||
|
{ return Insert(Size(), element); }
|
||||||
|
|
||||||
// Removes an element at a specific position.
|
// Removes an element at a specific position.
|
||||||
bool Remove(unsigned int index);
|
bool Remove(unsigned int index);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue