aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/compositors/driver.cxx
blob: a9f96d8d4af8ec7c249b229eebb55c4c083298c8 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// file      : examples/cxx/hybrid/compositors/driver.cxx
// copyright : not copyrighted - public domain

#include "compositors.hxx"

int
main (int, char*[])
{
  // Simple choice.
  //
  simple_choice sc;

  sc.a (123); // Automatically sets arm to a_tag.

  switch (sc.choice_arm ())
  {
  case simple_choice::a_tag:
    {
      sc.a ()++;
      break;
    }
  case simple_choice::b_tag:
    {
      // The b element is optional so we first need to check
      // if it is present.
      //
      if (sc.b_present ())
      {
        sc.b_present (false);
      }

      break;
    }
  case simple_choice::c_tag:
    {
      // The c element is a sequence.
      //
      simple_choice::c_sequence& s = sc.c ();

      for (simple_choice::c_iterator i = s.begin (); i != s.end(); ++i)
      {
        *i += 10;
      }

      break;
    }
  }


  // Nested choice.
  //
  nested_choice nc;

  // Initialize the choice with the 'sequence' arm.
  //
  nc.choice_present (true);
  nested_choice::choice_type& c = nc.choice ();
  c.choice_arm (nested_choice::choice_type::sequence_tag);
  c.sequence ().b (123);
  c.sequence ().c (true);

  nc.d (456);


  // Nested sequence.
  //
  nested_sequence ns;
  nested_sequence::sequence_sequence& s = ns.sequence ();

  for (int i = 0; i < 10; ++i)
  {
    nested_sequence::sequence_type x;
    x.a (i);

    if (i % 2)
    {
      // Initialize the nested sequence.
      //
      x.sequence1_present (true);
      x.sequence1 ().b (i);
      x.sequence1 ().c (true);
    }

    s.push_back (x);
  }

  return 0;
}