1 | #include <stdlib.h> |
---|
2 | #include <iostream> |
---|
3 | #include <sstream> |
---|
4 | #include "rappture.h" |
---|
5 | #include "Lookup.h" |
---|
6 | |
---|
7 | class Foo { |
---|
8 | char *desc; |
---|
9 | |
---|
10 | public: |
---|
11 | Foo(char *d) : desc(d) { |
---|
12 | std::cout << "created " << desc << std::endl; |
---|
13 | } |
---|
14 | ~Foo() { |
---|
15 | std::cout << "destroyed " << desc << std::endl; |
---|
16 | } |
---|
17 | }; |
---|
18 | |
---|
19 | Rappture::Outcome |
---|
20 | foo(int code) { |
---|
21 | Rappture::Outcome status; |
---|
22 | if (code) { |
---|
23 | status.error("Bad status code"); |
---|
24 | status.addContext("while in foo"); |
---|
25 | } |
---|
26 | return status; |
---|
27 | } |
---|
28 | |
---|
29 | int |
---|
30 | main(int argc, char* argv[]) { |
---|
31 | Rappture::Ptr<Foo> ptr(new Foo("a")); |
---|
32 | Rappture::Ptr<Foo> ptr2(new Foo("barney")); |
---|
33 | |
---|
34 | std::cout << "copy ptr(barney) -> ptr(a)" << std::endl; |
---|
35 | ptr = ptr2; |
---|
36 | |
---|
37 | std::cout << "clear ptr(barney)" << std::endl; |
---|
38 | ptr2.clear(); |
---|
39 | std::cout << "clear ptr(barney)" << std::endl; |
---|
40 | ptr.clear(); |
---|
41 | |
---|
42 | Rappture::Lookup2<int,int> num2id; |
---|
43 | num2id.get(4,NULL).value() = 1; |
---|
44 | num2id.get(105,NULL).value() = 2; |
---|
45 | num2id.get(69,NULL).value() = 3; |
---|
46 | num2id.get(95,NULL).value() = 4; |
---|
47 | |
---|
48 | Rappture::Outcome err = foo(1); |
---|
49 | if (err) { |
---|
50 | std::cout << err.remark() << std::endl; |
---|
51 | std::cout << err.context() << std::endl; |
---|
52 | } else { |
---|
53 | std::cout << "foo ok" << std::endl; |
---|
54 | } |
---|
55 | |
---|
56 | std::cout << num2id.stats(); |
---|
57 | Rappture::LookupEntry2<int,int> entry = num2id.first(); |
---|
58 | while (!entry.isNull()) { |
---|
59 | std::cout << " " << entry.key() << " = " << entry.value() << std::endl; |
---|
60 | entry.next(); |
---|
61 | } |
---|
62 | |
---|
63 | Rappture::Lookup<double> str2dbl; |
---|
64 | const char *one = "testing"; |
---|
65 | const char *two = "another"; |
---|
66 | str2dbl[one] = 2.0; |
---|
67 | str2dbl[two] = 5.75; |
---|
68 | |
---|
69 | std::cout << str2dbl.stats(); |
---|
70 | Rappture::LookupEntry<double> entry2 = str2dbl.first(); |
---|
71 | while (!entry2.isNull()) { |
---|
72 | std::cout << " " << entry2.key() << " = " << entry2.value() << std::endl; |
---|
73 | entry2.next(); |
---|
74 | } |
---|
75 | |
---|
76 | exit(0); |
---|
77 | } |
---|