aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/streaming/object-simpl.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/hybrid/streaming/object-simpl.cxx')
-rw-r--r--examples/cxx/hybrid/streaming/object-simpl.cxx69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/cxx/hybrid/streaming/object-simpl.cxx b/examples/cxx/hybrid/streaming/object-simpl.cxx
new file mode 100644
index 0000000..f23e0d4
--- /dev/null
+++ b/examples/cxx/hybrid/streaming/object-simpl.cxx
@@ -0,0 +1,69 @@
+// file : examples/cxx/hybrid/streaming/object-simpl.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+// Include position-simpl.hxx (which includes object-simpl.hxx)
+// instead of object-simpl.hxx.
+//
+#include "position-simpl.hxx"
+
+// Position measurement instrument interface.
+//
+struct measurements
+{
+ float lat;
+ float lon;
+};
+
+measurements test_measurements [8] =
+{
+ {-33.8569F, 18.5083F},
+ {-33.8568F, 18.5083F},
+ {-33.8568F, 18.5082F},
+ {-33.8570F, 18.5083F},
+ {-33.8569F, 18.5084F},
+ {-33.8570F, 18.5084F},
+ {-33.8570F, 18.5082F},
+ {-33.8569F, 18.5082F}
+};
+
+static void
+measure_position (unsigned int n, float& lat, float& lon)
+{
+ // Call the instrument to measure the position.
+ //
+ lat = test_measurements[n].lat;
+ lon = test_measurements[n].lon;
+}
+
+// Serializer implementation.
+//
+void object_simpl::
+pre (const object& obj)
+{
+ // Cache the object id and determine how many position measuremenets
+ // we need to take.
+ //
+ id_ = obj.id ();
+ count_ = 8;
+}
+
+unsigned int object_simpl::
+id ()
+{
+ return id_;
+}
+
+bool object_simpl::
+position_next ()
+{
+ return count_ > 0;
+}
+
+const position& object_simpl::
+position ()
+{
+ count_--;
+ measure_position (count_, cur_pos_.lat (), cur_pos_.lon ());
+ return cur_pos_;
+}