Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:44:42+00:00 2026-06-13T08:44:42+00:00

I am working on an event manager where events are represented by a key

  • 0

I am working on an event manager where events are represented by a key out of a string and an integer. That means that an event is not represented by a class or object. This way components can communicate through events but stay independent. It is an important guideline for the event manager that events don’t need to be registered but everyone can just listen to them or fire them.

(The integer part of the event key is for grouping phases of contentual the same event. E.g. a grenade triggers the events for throwing, flying, landing, exploding. They should be represented as “Grenade” 0, “Grenade” 1, … “Grenade” 4.)

Optionally events can contain a void pointer to send data referring the event. That could be the velocity of a crash, the id of the killed player.

Every component contains a pointer to the event namager named Event. I want to let them register methods or delegates to events.

// ideally registering for an event would look like that
Event.Listen("eventname", 0, this->Method);
Event.Listen("eventname", 0, [](){ ... });

// receiving data is optional
Event.Listen("eventname", 0, [](void* Data){ ... });

Firing events would ideally work similar.

Event.Fire("eventname", 0);
Event.Fire("eventname", 0, Data);

// fires events "eventname" 0, "eventname" 1, ... "eventname" 5
Event.FireRange("eventname", 0, 5);

The event manager holds a list of the events. That means the event key and a vector of all registered functions.

typedef unordered_map<pair<string, int>, vector<function>> ListEvent;
ListEvent List;

The vector stores all functions registered to a specific event. I tried using function pointers, member function pointers and std::functions. But nothing worked the way I wanted. Here are some of my questions related to this event manager: Check if two std::function are Equal, Store Function Pointers to any Member Function, Check if the Type of an Object is inherited from a specific Class.

It is important for a listening function to have access to the member of it’s class. And I would like to register lambda functions in one line of code.

Do you have any idea or technique to approach coding such an event manager?

I tried to present my problem in a general manner but if you need additional explanation or code please feel free to comment.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:44:43+00:00Added an answer on June 13, 2026 at 8:44 am

    Here is quick working sketch:

    #include <vector>
    #include <functional>
    #include <iostream>
    
    typedef std::function<void(int param)> callback;
    
    struct Event {
      std::vector<callback> subs;//criptions  
    
      void subscribe(callback cb) { subs.push_back(cb); }
      void fire(int param = 0) { for(callback& cb : subs) cb(param); }
    };
    
    void some_free_func(int param) { std::cout << "some_free_func got signal" << std::endl; }
    
    int main(int argc, char* argv[])
    {
      Event evt0; 
      evt0.subscribe(some_free_func);
    
      evt0.subscribe([](int p) { std::cout << "some_lambda got signal" << std::endl; } );
    
      evt0.fire();
        return 0;
    }
    

    Conceptually it roughly does what you need but you should think of ownership policy here. Check my question above.

    EDIT: if you say that ownership is not an issue then this may work:

    void my_object::firstCry() { 
       evt0.subscribe([=](int p) { this->got_signal(p); }); // inst/method thunk 
    }
    
    void my_object::got_signal(int param) {...}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following key event is not working. Any idea? class Frame(wx.Frame): def __init__(self): wx.Frame.__init__(self,
In onchange event is not working in jquery.selectbox-05, i am using two dropdown box
I am working on creating a web app that will query event logs on
I am working on a php program that needs to store many Event objects
I've searched all over and I can't figure this one out. I am working
Context I'm working on an app that displays events in the area and calculates
I'm working on an event manager project and I'd like to make it so
Ok I am still working on this jquery photo manager which you can see
I've been working with some event handling in Javascript and recently decided to migrate
I'm trying to play a random sound onTouch event (currently working), but the sound

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.