Skip to content

Another Signal/Slot with a focus on automatic connection handling

License

Notifications You must be signed in to change notification settings

michaelcowan/ass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Another Signal Slot

Signal/Slot implementation with a focus on automatic connection handling

Try online GitHub Github Releases Build Status Coverage Status

Features

  • Automatic connection handling
    • when a Signal or Slot goes out of scope, the connection is severed
    • no need to implement an interface or inherit a base class
  • Type-safe
  • Header only

Limitations

  • Not thread-safe
  • Not reentrant-safe

Usage Examples

Observer Pattern Example

Slot<std::string> observer([](std::string s) {
    std::cout << s << std::endl;
});

Signal<std::string> subject;

subject.connect(observer);

subject.emit("Hello World");

Class Decoupling Example

class Button {
public:

    Signal<> pressed;

private:
    void onMouseButtonDownInsideButtonArea() {
        pressed.emit();
    }
};

class Popup {
public:

    const Slot<> show = Slot<>(this, &Popup::render);

private:
    void render() { }
};


Button button;
Popup popup;

button.pressed.connect(popup.show);