Aspect-Oriented Programming & C++
by Christopher Diggins

Listing One
class FuBar {
  Fu() {
    // do fu
  }
  Bar() {
    // do bar
  }
}

Listing Two
class FuBar {
  Fu() {
    DumpState();
    // do fu
    DumpState();
  }
  Bar() {
    DumpState();
    // do bar
    DumpState();
  }
}

Listing Three
class FuBar {
  Fu() {
    DumpState();
    // do fu
    DumpState();
  }
  Bar() {
    DumpState();
    if (!prevent_bar_flag) {
      // do bar
    }
    DumpState();
  }
}

Listing Four
class FuBar {
  Fu() {
    DumpState();
    SetThreadPriorityCritical();
    // do fu
    RestoreThreadPriority();
    DumpState();
  }
  Bar() {
    DumpState();
    SetThreadPriorityCritical();
    if (!prevent_bar_flag) {
      // do bar
    }
    RestoreThreadPriority();
    DumpState();
  }
}

Listing Five

class FuBar {
    Fu() {
      TestInvariant();
      DumpState();
      SetThreadPriorityCritical();
      // do fu
      RestoreThreadPriority();
      DumpState();
      TestInvariant();
    }
    Bar() {
      TestInvariant();
      DumpState();
      SetThreadPriorityCritical();
      if (!prevent_bar_flag) {
        // do bar
      }
      RestoreThreadPriority();
      DumpState();
      TestInvariant();
    }
  }


Listing Six
class FuBar {
    Fu() {
      Lock();
      TestInvariant();
      DumpState();
      SetThreadPriorityCritical();
      // do fu
      RestoreThreadPriority();
      DumpState();
      TestInvariant();
      Unlock();
    }
    Bar() {
      Lock();
      TestInvariant();
      DumpState();
      SetThreadPriorityCritical();
      if (!prevent_bar_flag) {
        // do bar
      }
      RestoreThreadPriority();
      DumpState();
      TestInvariant();
      Unlock();
    }
  }

Listing Seven
class BaseAspect {
  virtual void OnBefore() { /* do nothing */ };
  virtual void OnAfter() { /* do nothing */ };
  virtual bool OnProceedQuery() { return true; };
  virtual void OnException() { throw; };
  virtual void OnFinally() { /* do nothing */ };
};

Listing Eight
class StateDumpingAspect : public BaseAspect {
  virtual void OnBefore() {
    DumpState();
  }
  virtual void OnAfter() {
    DumpState();
  }
};

Listing Nine
typedef
  CROSSCUT(
    CROSSCUT(
      CROSSCUT(
        CROSSCUT(
          CROSSCUT(FuBar, FuBarPointCut, StateDumpingAspect),
        BarPointCut, BarPreventingAspect),
      FuBarPointCut, RealTimeAspect),
    FuBarPointCut, InvariantAspect),
  FuBarPointCut, SynchronizeAspect)
NewFuBar;


Listing Ten
class BarPreventingAspect : public BaseAspect {
  virtual bool OnProceedQuery() {
    return (!global_prevent_bar_flag);
  }
};
class RealTimeAspect : public BaseAspect {
  virtual void OnBefore() {
    SetThreadPriorityCritical();
  }
  virtual void OnAfter() {
    RestoreThreadPriority();
  }
};
class InvariantAspect : public BaseAspect {
  virtual void OnBefore() {
    TestInvariant();
  }
  virtual void OnAfter() {
    TestInvariant();
  }
};
class SynchronizeAspect : public BaseAspect {
  virtual void OnBefore()
    Lock();
  }
  virtual void OnAfter()
    Unlock();
  }
};





