This source file includes following definitions.
- reverse_strcmp
- action
- is_at_most
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include "gl_oset.hh"
21 #include "gl_array_oset.h"
22
23 #include <string.h>
24
25 #include "macros.h"
26
27 static int
28 reverse_strcmp (const char *str1, const char *str2)
29 {
30 int cmp = strcmp (str1, str2);
31 return (cmp > 0 ? -1 : cmp < 0 ? 1 : 0);
32 }
33
34 static void
35 action (const char *str, int *data)
36 {
37 const_cast<char *> (str) [0] += *data;
38 }
39
40 static bool
41 is_at_most (const char *str, const char *threshold)
42 {
43 return strcmp (str, threshold) <= 0;
44 }
45
46 int
47 main (int argc, char *argv[])
48 {
49 char A[2] = "A";
50 gl_OSet<const char *> set1;
51
52 set1 = gl_OSet<const char *> (GL_ARRAY_OSET, reverse_strcmp, NULL);
53 set1.add (A);
54 set1.add ("C");
55 set1.add ("D");
56 set1.add ("C");
57 ASSERT (set1.size () == 3);
58
59 {
60 gl_OSet<const char *>::iterator iter1 = set1.begin ();
61 const char *elt;
62 ASSERT (iter1.next (elt));
63 ASSERT (strcmp (elt, "D") == 0);
64 ASSERT (iter1.next (elt));
65 ASSERT (strcmp (elt, "C") == 0);
66 ASSERT (iter1.next (elt));
67 ASSERT (strcmp (elt, "A") == 0);
68 ASSERT (!iter1.next (elt));
69 }
70
71 int data = 'Z' - 'A';
72 ASSERT (set1.update (A, action, &data) == 1);
73
74 {
75 gl_OSet<const char *>::iterator iter2 = set1.begin ();
76 const char *elt;
77 ASSERT (iter2.next (elt));
78 ASSERT (strcmp (elt, "Z") == 0);
79 ASSERT (iter2.next (elt));
80 ASSERT (strcmp (elt, "D") == 0);
81 ASSERT (iter2.next (elt));
82 ASSERT (strcmp (elt, "C") == 0);
83 ASSERT (!iter2.next (elt));
84 }
85
86 {
87 gl_OSet<const char *>::iterator iter3 = set1.begin_atleast (is_at_most, "R");
88 const char *elt;
89 ASSERT (iter3.next (elt));
90 ASSERT (strcmp (elt, "D") == 0);
91 ASSERT (iter3.next (elt));
92 ASSERT (strcmp (elt, "C") == 0);
93 ASSERT (!iter3.next (elt));
94 }
95
96 set1.free ();
97
98 return 0;
99 }