Debian Codegraph @

AspectC++/tests/JPTL/TestAspect.ah

raw
1 #pragma once
2
3 #include "JPTL.h"
4
5 #include <iostream>
6 using namespace std;
7
8
9
10 template<typename TypeInfo, typename CONTEXT>
11 struct Printer {
12 template<typename T>
13 static void exec(T obj, bool* proceed) { if(*proceed) { cout << TypeInfo::signature() << endl; } *proceed = true; }
14
15 // EXEC is optional, and so is the specialization for void (initial EXEC)
16 struct EXEC {
17 enum { BASES = CONTEXT::BASES + TypeInfo::BASECLASSES };
18 };
19 };
20 template<typename TypeInfo>
21 struct Printer<TypeInfo, void> {
22 // initial EXEC
23 struct EXEC {
24 enum { BASES = 0 };
25 };
26 };
27
28
29 template<typename MemberInfo, typename CONTEXT>
30 struct MemberView {
31 struct EXEC {
32 enum { SIZE = CONTEXT::SIZE + sizeof(typename MemberInfo::ReferredType) };
33 };
34
35 template<typename T>
36 static void exec(T obj) { cout << "+ " << sizeof(*MemberInfo::pointer(obj)) << " = " << EXEC::SIZE << endl; }
37 };
38 template<typename MemberInfo>
39 struct MemberView<MemberInfo, void> {
40 // initial EXEC
41 struct EXEC {
42 enum { SIZE = 0 };
43 };
44 };
45
46
47 template<typename FunctionInfo, typename CONTEXT>
48 struct FunctionCount {
49 struct EXEC {
50 enum { COUNT = CONTEXT::COUNT + 1 };
51 };
52 };
53 template<typename FunctionInfo>
54 struct FunctionCount<FunctionInfo, void> {
55 struct EXEC {
56 enum { COUNT = 0 };
57 };
58 };
59
60
61
62 aspect TestAspect {
63
64 advice "%" && !"TestAspect" : slice class {
65 public:
66 //int should_not_work[AC::TypeInfo<JoinPoint::That>::MEMBERS]; //THIS yields the TypeInfo of the BASE CLASS :-( : FIXME!
67
68 typedef JPTL::BaseIterator<JoinPoint, Printer> bit;
69 typedef JPTL::MemberIterator<JoinPoint, MemberView> mit;
70 typedef JPTL::FunctionIterator<JoinPoint, FunctionCount> fit;
71 };
72
73 advice execution("%" && !"TestAspect") : after() {
74 cout << "*** BaseIterator ***" << endl;
75 bool result = true;
76 JoinPoint::That::bit::exec(tjp->that(), &result);
77
78 cout << "BASES: " << JoinPoint::That::bit::EXEC::BASES << endl;
79
80 cout << "*** MemberIterator ***" << endl;
81 JoinPoint::That::mit::exec(tjp->that());
82 cout << "SIZE: " << JoinPoint::That::mit::EXEC::SIZE << endl;
83
84 cout << "*** FunctionIterator ***" << endl;
85 cout << "COUNT: " << JoinPoint::That::fit::EXEC::COUNT << endl;
86 }
87
88 };