diff options
Diffstat (limited to 'project2/basics/aggregates/min.cpp')
-rw-r--r-- | project2/basics/aggregates/min.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/project2/basics/aggregates/min.cpp b/project2/basics/aggregates/min.cpp new file mode 100644 index 0000000..ee0bf3d --- /dev/null +++ b/project2/basics/aggregates/min.cpp @@ -0,0 +1,32 @@ +#include <aggregate.h> + +class Min : public ValueAggregate { + public: + Min(ScriptNodePtr s) : + ValueAggregate(s), + first(true) + { + } + void reset() const + { + result = VariableType(); + first = true; + } + void pushValue(const VariableType & v) const + { + if (first || v < result) { + result = v; + } + first = false; + } + VariableType resultValue() const + { + return result; + } + private: + mutable VariableType result; + mutable bool first; +}; + +DECLARE_LOADER("min", Min); + |