@@ -55,8 +55,8 @@ struct Filter {
5555
5656 bool initialised () const { return n_ != 0 ; }
5757 Size size () const { return n_; }
58- bool operator [](const Size i) const ; // no bound check
59- bool at (const Size i) const ; // with bound check
58+ bool operator [](const Size i) const ; // undefined if uninitialized or i out of bounds
59+ bool at (const Size i) const ; // with checks for initialized, i within bounds
6060 //
6161 friend Filter operator &&(Filter, const Filter&);
6262 friend Filter operator ||(Filter, const Filter&);
@@ -68,6 +68,7 @@ struct Filter {
6868 void expand ();
6969
7070private:
71+ // for invariants see the corresponding section below in class RandomVariable
7172 Size n_;
7273 bool constantData_;
7374 bool * data_;
@@ -113,8 +114,8 @@ struct RandomVariable {
113114 void updateDeterministic ();
114115 bool initialised () const { return n_ != 0 ; }
115116 Size size () const { return n_; }
116- Real operator [](const Size i) const ; // no bound check
117- Real at (const Size i) const ; // with bound check
117+ Real operator [](const Size i) const ; // undefined if uninitialized or i out of bounds
118+ Real at (const Size i) const ; // with checks for initialized, i within bounds
118119 Real time () const { return time_; }
119120 RandomVariable& operator +=(const RandomVariable&);
120121 RandomVariable& operator -=(const RandomVariable&);
@@ -156,6 +157,21 @@ struct RandomVariable {
156157
157158private:
158159 void checkTimeConsistencyAndUpdate (const Real t);
160+ /* Invariants that hold at all times for instances of this class:
161+
162+ n_ = 0 means uninitialized, n_ > 0 means initialized.
163+
164+ For an uninitialized instance:
165+ - constantData_ = 0.0, data_ = nullptr, deterministic_ = false, time_ = Null<Real>()
166+
167+ For an initialized instance:
168+ - if deterministic = true a constant value is represented with
169+ - constantData_ the constant value
170+ - data_ = nullptr
171+ - if deterministic = false a possibly non-constant value is represented with
172+ - constantData_ initialized with last constant value that was set
173+ - data_ an array of size n_
174+ */
159175 Size n_;
160176 double constantData_;
161177 double * data_;
0 commit comments