aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/streaming/object-simpl.cxx
blob: 9bf76a133f92b21d1900280b17190e30000d21d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// file      : examples/cxx/hybrid/streaming/object-simpl.cxx
// 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_;
}