The Sparta Modeling Framework
Loading...
Searching...
No Matches
SpartaHandler.hpp File Reference

File that contains the macro used to generate the class callbacks. More...

#include <iostream>
#include <cinttypes>
#include <limits>

Go to the source code of this file.

Namespaces

namespace  sparta
 Macros for handling exponential backoff.
 

Macros

#define CREATE_SPARTA_HANDLER(clname, meth)
 
#define CREATE_SPARTA_HANDLER_WITH_CLEAR(clname, meth, clear)
 
#define CREATE_SPARTA_HANDLER_WITH_OBJ(clname, obj, meth)
 
#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT)
 
#define CREATE_SPARTA_HANDLER_WITH_TWO_DATA(clname, meth, dataOne, dataTwo)
 
#define CREATE_SPARTA_HANDLER_WITH_DATA_WITH_OBJ(clname, obj, meth, dataT)
 

Detailed Description

File that contains the macro used to generate the class callbacks.

Definition in file SpartaHandler.hpp.

Macro Definition Documentation

◆ CREATE_SPARTA_HANDLER

#define CREATE_SPARTA_HANDLER (   clname,
  meth 
)
Value:
sparta::SpartaHandler::from_member<clname, &clname::meth> \
(this, #clname"::"#meth"()")

Creates a SpartaHandler type given the class name (clname) and a class method (meth).

This method requires a class instance (expects this to be defined and of type clname). The class method given must match the following signature:

void clname::meth();

Example:

class MyClass
{
public:
MyClass() {
sparta::SpartaHandler handler =
CREATE_SPARTA_HANDLER(MyClass, myMethod);
// ... do something with the handle
handler();
}
void myMethod() {
std::cout << "myMethod called" << std::endl;
}
};
#define CREATE_SPARTA_HANDLER(clname, meth)

Definition at line 317 of file SpartaHandler.hpp.

◆ CREATE_SPARTA_HANDLER_WITH_CLEAR

#define CREATE_SPARTA_HANDLER_WITH_CLEAR (   clname,
  meth,
  clear 
)
Value:
sparta::SpartaHandler::from_member_clear<clname, &clname::meth, &clname::clear>\
(this, #clname"::"#meth"()")

Creates a SpartaHandler type given the class name (clname), a class method (meth), and a clear method (clear).

This method requires a class instance (expects this to be defined and of type clname). The class method and clear method given must match the following signature:

void clname::meth();
void clname::clear();

This handler type allows the sparta::Scheduler to "clear" the handle that was previously set. This is useful for nullifying a handler on the scheduler.

Example:

class MyClass
{
public:
MyClass() {
sparta::SpartaHandler handler =
CREATE_SPARTA_HANDLER_WITH_CLEAR(MyClass, myMethod, myClear);
// ... do something with the handle
handler();
}
void myMethod() {
std::cout << "myMethod called" << std::endl;
}
void myClear() {
std::cout << "myClear called" << std::endl;
}
};
#define CREATE_SPARTA_HANDLER_WITH_CLEAR(clname, meth, clear)

Definition at line 364 of file SpartaHandler.hpp.

◆ CREATE_SPARTA_HANDLER_WITH_DATA

#define CREATE_SPARTA_HANDLER_WITH_DATA (   clname,
  meth,
  dataT 
)
Value:
sparta::SpartaHandler::from_member_1<clname, dataT, &clname::meth> \
(this, #clname"::"#meth"("#dataT")")

Creates a SpartaHandler type given the class name (clname), a class method (meth), and the data type that method expects (dataT).

This method requires a class instance (expects this to be defined and of type clname). The class method given must match the following signature:

void clname::meth(const dataT &);

Example:

class MyClass
{
public:
MyClass() {
sparta::SpartaHandler handler =
CREATE_SPARTA_HANDLER_WITH_DATA(MyClass, myMethod, uint32_t);
// ... do something with the handle
handler(10);
}
void myMethod(const uint32_t & dat) {
std::cout << "myMethod called: " << dat << std::endl;
}
};
#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT)

Definition at line 441 of file SpartaHandler.hpp.

◆ CREATE_SPARTA_HANDLER_WITH_DATA_WITH_OBJ

#define CREATE_SPARTA_HANDLER_WITH_DATA_WITH_OBJ (   clname,
  obj,
  meth,
  dataT 
)
Value:
sparta::SpartaHandler::from_member_1<clname, dataT, &clname::meth> \
(obj, #clname"::"#meth"("#dataT")")

Creates a SpartaHandler type given the class name (clname), class instance (obj), a class method (meth), and the parameter data (dataT).

This method requires a class instance to be given. The class method given must match the following signature:

void clname::meth(const dataT &);

Example:

class MyClass
{
public:
MyClass() {
sparta::SpartaHandler handler =
CREATE_SPARTA_HANDLER_WITH_DATA_WITH_OBJ(MyClass, this, myMethod, uint32_t);
// ... do something with the handle
handler();
}
void myMethod(const uint32_t & dat) {
std::cout << "myMethod called: " << dat << std::endl;
}
};
#define CREATE_SPARTA_HANDLER_WITH_DATA_WITH_OBJ(clname, obj, meth, dataT)

Definition at line 518 of file SpartaHandler.hpp.

◆ CREATE_SPARTA_HANDLER_WITH_OBJ

#define CREATE_SPARTA_HANDLER_WITH_OBJ (   clname,
  obj,
  meth 
)
Value:
sparta::SpartaHandler::from_member<clname, &clname::meth> \
(obj, #clname"::"#meth"()")

Creates a SpartaHandler type given the class name (clname), a class instance (obj) and a class method (meth).

This method requires a class instance to be given. The class method given must match the following signature:

void clname::meth();

Example:

class MyClass
{
public:
MyClass() {
sparta::SpartaHandler handler =
CREATE_SPARTA_HANDLER_WITH_OBJ(MyClass, this, myMethod);
// ... do something with the handle
handler();
}
void myMethod() {
std::cout << "myMethod called" << std::endl;
}
};
#define CREATE_SPARTA_HANDLER_WITH_OBJ(clname, obj, meth)

Definition at line 401 of file SpartaHandler.hpp.

◆ CREATE_SPARTA_HANDLER_WITH_TWO_DATA

#define CREATE_SPARTA_HANDLER_WITH_TWO_DATA (   clname,
  meth,
  dataOne,
  dataTwo 
)
Value:
sparta::SpartaHandler::from_member_2<clname, dataOne, dataTwo, &clname::meth> \
(this, #clname"::"#meth"("#dataOne","#dataTwo")")

Creates a SpartaHandler type given the class name (clname), a class method (meth), and two arguments (dataOne and dataTwo).

This method requires a class instance (expects this to be defined and of type clname). The class method given must match the following signature:

void clname::meth(const dataOne&, const dataTwo &);

Example:

class MyClass
{
public:
MyClass() {
sparta::SpartaHandler handler =
CREATE_SPARTA_HANDLER_WITH_TWO_DATA(MyClass, myMethod, uint32_t, std::string);
// ... do something with the handle
handler(10, "hello");
}
void myMethod(const uint32_t & dat, const std::string & msg) {
std::cout << "myMethod called " << dat << msg << std::endl;
}
};
#define CREATE_SPARTA_HANDLER_WITH_TWO_DATA(clname, meth, dataOne, dataTwo)

Definition at line 480 of file SpartaHandler.hpp.