URL:
  <http://gna.org/patch/?7490>

                 Summary: Qt client: Add class to ease wrapping the C API
                 Project: Freeciv
            Submitted by: louis94
            Submitted on: jeu. 21 juil. 2016 01:46:45 UTC
                Category: client-qt
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: 
 Contains string changes: None

    _______________________________________________________

Details:

The attached file adds a new template class designed to wrap the C API in an
event-like interface. Creating a wrapper is simple (declare an abstract class,
add a macro to .cpp). Subscribing to events is done through inheritance.

Excerpt from the doc:

This class is a helper to create Java-like "listeners" for "events" generated
in C code. If the C interface defines a callback foo() and you want to use it
as an event, you first declare a C++ interface:

class foo_helper : public helper<foo_helper>
{
public:
  virtual void foo() = 0;
};


The helper needs some static data. Declaring it is as simple as putting a
macro in some source file:

CPP_DECLARE_HELPER(foo_helper)


Then, you call the listeners from the implementation of the C interface:

void foo()
{
  foo_helper::invoke(&foo_helper::foo);
}


This will invoke foo() on all foo_helper objects. It does also work for
derived classes.




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: jeu. 21 juil. 2016 01:46:45 UTC  Name: cpputils.h  Size: 5 ko   By:
louis94

<http://gna.org/patch/download.php?file_id=27965>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?7490>

_______________________________________________
  Message posté via/par Gna!
  http://gna.org/


_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to