File: main.cc

package info (click to toggle)
aspectc%2B%2B 1.0pre4~svn.20080711-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 104,504 kB
  • ctags: 363,975
  • sloc: cpp: 1,645,814; ansic: 16,601; sh: 2,175; makefile: 1,043
file content (90 lines) | stat: -rw-r--r-- 1,773 bytes parent folder | download | duplicates (11)
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
#include <stdio.h>

aspect Calls {
  advice call ("% %::%(...)") : before () {
    printf ("call to %s\n", tjp->signature ());
  }
  advice call ("% %::%(...)") : around () {
    printf ("around1: call to %s\n", tjp->signature ());
    tjp->proceed ();
  }
  advice call ("% %::%(...)") : around () {
    printf ("around2: call to %s\n", tjp->signature ());
    tjp->proceed ();
  }
};

aspect Calls2 {
  advice call ("% HasFriend::h(...)") : around () {
    printf ("Calls2: call to %s\n", tjp->signature ());
    tjp->proceed ();
  }
};

aspect Calls3 {
  advice call ("% HasFriend::h(...)") : around () {
    printf ("Calls3: call to %s\n", tjp->signature ());
    tjp->proceed ();
  }
};

class Base {
protected:
  Base () {}
  void f ();
public:
  void x ();
};

class HasFriend {
  friend void Base::x ();
  static void h () {
    printf (" --> access for friend Base::x() only\n");
  }
};
  
void Base::f () {
  printf (" --> protected in base\n");
  x ();
}

// need because starting with g++ 3.4.1 a friend has to be accessible
void Base::x () {
  HasFriend::h ();
}

class Derived : private Base {
  int _attr;
  void p () {
    printf (" --> private in same class\n");
  }
  int val () { return 4711; }
public:
  Derived ();
  void g1 () {
    printf (" --> public\n");
    p ();
    f ();
  }
  void g2 ();
};

Derived::Derived () : _attr (val ()) {
  printf (" --> call to private member from constructor init list\n");
}

void Derived::g2 () {
  printf (" --> public\n");
  p ();
  f ();
}

int main () {
  printf ("AccessControl: advice for calls with special privileges\n");
  printf ("=======================================================\n");

  Derived d;
  d.g1 ();
  d.g2 ();
  printf ("=======================================================\n");
}