Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.brendan/ptolemy2.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
3 // GROUPS passed ptolemy-bugs
4 #include <iostream>
5
6 class PTcl {
7 public:
8 int dispatcher(int which,int argc,char** argv);
9 // fns in the table
10 int one(int argc, char** argv);
11 int two(int argc, char** argv);
12 int three(int argc, char** argv);
13 };
14
15 // An InterpFuncP is a pointer to an PTcl function that takes an argc-argv
16 // argument list and returns TCL_OK or TCL_ERROR.
17
18 typedef int (PTcl::*InterpFuncP)(int,char**);
19
20 struct InterpTableEntry {
21 const char* name;
22 InterpFuncP func;
23 };
24
25 // Here is the function table and dispatcher function.
26 // These macros define entries for the table
27
28 #define quote(x) #x
29 #define ENTRY(verb) { quote(verb), &PTcl::verb }
30
31 static InterpTableEntry funcTable[] = {
32 ENTRY(one),
33 ENTRY(two),
34 ENTRY(three),
35 {0, 0}
36 };
37
38 int PTcl::dispatcher(int which, int argc, char** argv) {
39 return (this->*(funcTable[which].func))(argc, argv);
40 }
41
42 void printargs(char** argv) {
43 // while (*argv) {
44 // cout << " " << *argv++;
45 // }
46 // cout << "\n";
47 }
48
49 int PTcl::one(int, char** argv) {
50 std::cout << "FAIL\n";
51 printargs(argv);
52 return 1;
53 }
54
55 int PTcl::two(int, char** argv) {
56 std::cout << "PASS\n";
57 printargs(argv);
58 return 0;
59 }
60
61 int PTcl::three(int, char** argv) {
62 std::cout << "FAIL\n";
63 printargs(argv);
64 return 1;
65 }
66
67 int main (int argc, char** argv) {
68 PTcl obj;
69 return obj.dispatcher(1,argc,argv);
70 }