summaryrefslogtreecommitdiff
path: root/project2/basics/aggregates/min.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-03-28 17:51:07 +0000
committerrandomdan <randomdan@localhost>2013-03-28 17:51:07 +0000
commit69fbeed3ad3812f66db21bce52ef06f1f0549579 (patch)
treec0beaf7e9aad6fd55bfd6a88203f874e188b126b /project2/basics/aggregates/min.cpp
parentA stream processing module that reads sets of name=value pairs (diff)
downloadproject2-69fbeed3ad3812f66db21bce52ef06f1f0549579.tar.bz2
project2-69fbeed3ad3812f66db21bce52ef06f1f0549579.tar.xz
project2-69fbeed3ad3812f66db21bce52ef06f1f0549579.zip
skip 1 shuffle of code out of common
Diffstat (limited to 'project2/basics/aggregates/min.cpp')
-rw-r--r--project2/basics/aggregates/min.cpp32
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);
+