Redo API for notifiers.

There's now an notifier::Modifiable interface class that class
supposed to signal modifications are to be derived from. This takes
the place of the former MutableValue class and also unifies how Val
and IDs signal modifications.
This commit is contained in:
Robin Sommer 2019-06-06 23:13:43 +00:00
parent f8262b65c4
commit 062a1ee6b3
8 changed files with 126 additions and 163 deletions

View file

@ -328,6 +328,8 @@ public:
void Describe(ODesc* d) const override;
virtual void DescribeReST(ODesc* d) const;
virtual notifier::Modifiable* Modifiable() { return 0; }
#ifdef DEBUG
// For debugging, we keep a reference to the global ID to which a
// value has been bound *last*.
@ -490,8 +492,6 @@ protected:
MutableVal() {}
~MutableVal() override;
void Modified() { notifiers.Modified(this); }
};
#define Microseconds 1e-6
@ -764,7 +764,7 @@ protected:
};
class CompositeHash;
class TableVal : public MutableVal {
class TableVal : public Val, public notifier::Modifiable {
public:
explicit TableVal(TableType* t, Attributes* attrs = 0);
~TableVal() override;
@ -877,6 +877,8 @@ public:
HashKey* ComputeHash(const Val* index) const
{ return table_hash->ComputeHash(index, 1); }
notifier::Modifiable* Modifiable() override { return this; }
protected:
friend class Val;
TableVal() {}
@ -915,7 +917,7 @@ protected:
Val* def_val;
};
class RecordVal : public MutableVal {
class RecordVal : public Val, public notifier::Modifiable {
public:
explicit RecordVal(RecordType* t, bool init_fields = true);
~RecordVal() override;
@ -962,6 +964,8 @@ public:
unsigned int MemoryAllocation() const override;
void DescribeReST(ODesc* d) const override;
notifier::Modifiable* Modifiable() override { return this; }
// Extend the underlying arrays of record instances created during
// parsing to match the number of fields in the record type (they may
// mismatch as a result of parse-time record type redefinitions.
@ -1006,7 +1010,7 @@ protected:
};
class VectorVal : public MutableVal {
class VectorVal : public Val, public notifier::Modifiable {
public:
explicit VectorVal(VectorType* t);
~VectorVal() override;
@ -1054,6 +1058,8 @@ public:
// Won't shrink size.
unsigned int ResizeAtLeast(unsigned int new_num_elements);
notifier::Modifiable* Modifiable() override { return this; }
protected:
friend class Val;
VectorVal() { }