aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/serializer/minimal/people-simpl-tiein.hxx
blob: ce7a70d67e65de0a0f2b21d9fe65ac8be4e372f7 (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
89
90
// file      : examples/cxx/serializer/people/people-simpl-tiein.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : not copyrighted - public domain

#ifndef PEOPLE_SIMPL_HXX
#define PEOPLE_SIMPL_HXX

#include "people.hxx"
#include "people-sskel.hxx"

struct gender_simpl: gender_sskel
{
  gender_simpl ()
      : gender_sskel (&base_impl_)
  {
  }

  virtual void
  pre (gender g)
  {
    base_impl_.pre (g == male ? "male" : "female");
  }

private:
  xml_schema::string_simpl base_impl_;
};

struct person_simpl: person_sskel
{
  virtual void
  pre (const person& p)
  {
    person_ = &p;
  }

  virtual const char*
  first_name ()
  {
    return person_->first_name_;
  }

  virtual const char*
  last_name ()
  {
    return person_->last_name_;
  }

  virtual ::gender
  gender ()
  {
    return person_->gender_;
  }

  virtual unsigned short
  age ()
  {
    return person_->age_;
  }

private:
  const person* person_;
};

struct people_simpl: people_sskel
{
  virtual void
  pre (const people& p)
  {
    i_ = 0;
    people_ = &p;
  }

  virtual bool
  person_next ()
  {
    return i_ < people_->size_;
  }

  virtual const ::person&
  person ()
  {
    return people_->people_[i_++];
  }

private:
  size_t i_;
  const people* people_;
};

#endif // PEOPLE_SIMPL_HXX