Xonotic
CallbackChain Class Reference

Callback chains contain zero or more callbacks. More...

+ Inheritance diagram for CallbackChain:
+ Collaboration diagram for CallbackChain:

Classes

class  CallbackNode
 

Public Member Functions

 ATTRIB (CallbackChain, cbc_next, CallbackNode)
 
 CallbackChain ::CallbackChain (string _name)
 
bool CallbackChain_Add (CallbackChain this, Callback cb, int order)
 
bool CallbackChain_Call (CallbackChain this)
 
int CallbackChain_Remove (CallbackChain this, Callback cb)
 

Public Attributes

int cbc_order = 0
 

Detailed Description

Callback chains contain zero or more callbacks.

Definition at line 36 of file base.qh.

Member Function Documentation

◆ ATTRIB()

CallbackChain::ATTRIB ( CallbackChain  ,
cbc_next  ,
CallbackNode   
)

◆ CallbackChain ::CallbackChain()

CallbackChain::CallbackChain ::CallbackChain ( string  _name)
inline

Definition at line 50 of file base.qh.

References CONSTRUCT, and netname.

50  {
52  this.netname = _name;
53  }
Callback chains contain zero or more callbacks.
Definition: base.qh:36
string netname
Definition: powerups.qc:20
#define CONSTRUCT(cname,...)
Definition: oo.qh:111

◆ CallbackChain_Add()

bool CallbackChain::CallbackChain_Add ( CallbackChain  this,
Callback  cb,
int  order 
)
inline

Definition at line 55 of file base.qh.

References CBC_ORDER_ANY, CBC_ORDER_FIRST, CBC_ORDER_LAST, entity(), NEW, NULL, and prev.

56  {
57  if (order & CBC_ORDER_FIRST) {
58  if (order & CBC_ORDER_LAST)
59  if (this.cbc_order & CBC_ORDER_ANY)
60  return false;
61  if (this.cbc_order & CBC_ORDER_FIRST)
62  return false;
63  } else if (order & CBC_ORDER_LAST) {
64  if (this.cbc_order & CBC_ORDER_LAST)
65  return false;
66  }
67  entity node = NEW(CallbackNode, cb, order);
68  if (order & CBC_ORDER_FIRST) {
69  node.cbc_next = this.cbc_next;
70  this.cbc_next = node;
71  } else if (order & CBC_ORDER_LAST) {
72  CallbackNode prev = NULL, it = this.cbc_next;
73  while (it) { prev = it, it = it.cbc_next; }
74  if (prev) prev.cbc_next = node;
75  else this.cbc_next = node;
76  } else {
77  // by default we execute last, but before a possible CBC_ORDER_LAST callback
78  CallbackNode prev = NULL, it = this.cbc_next;
79  while (it && !(it.cbc_order & CBC_ORDER_LAST)) { prev = it, it = it.cbc_next; }
80  node.cbc_next = it;
81  if (prev) prev.cbc_next = node;
82  else this.cbc_next = node;
83  }
84  this.cbc_order |= (order | CBC_ORDER_ANY);
85  return true;
86  }
int cbc_order
Definition: base.qh:49
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
prev
Definition: all.qh:66
const int CBC_ORDER_LAST
Definition: base.qh:8
const int CBC_ORDER_FIRST
Definition: base.qh:7
#define NULL
Definition: post.qh:17
const int CBC_ORDER_ANY
Definition: base.qh:10
+ Here is the call graph for this function:

◆ CallbackChain_Call()

bool CallbackChain::CallbackChain_Call ( CallbackChain  this)
inline

Definition at line 104 of file base.qh.

References CallbackChain_ReturnValue, and ENDCLASS.

105  {
106  bool r = false;
107  for (Callback it = this.cbc_next; it; it = it.cbc_next) {
109  r |= it.cbc.cbc_func();
110  }
111  return r; // callbacks return an error status, so 0 is default return value
112  }
Callbacks may be added to zero or more callback chains.
Definition: base.qh:17
bool CallbackChain_ReturnValue
Definition: base.qh:12

◆ CallbackChain_Remove()

int CallbackChain::CallbackChain_Remove ( CallbackChain  this,
Callback  cb 
)
inline

Definition at line 87 of file base.qh.

References CBC_ORDER_ANY, next, NULL, and prev.

88  {
89  int n = 0, order = 0;
90  for (Callback prev = NULL, it = this.cbc_next; it; prev = it, it = it.cbc_next) {
91  if (it.cbc == cb) {
92  // remove it from the chain
93  Callback next = it.cbc_next;
94  if (prev) prev.cbc_next = next;
95  else this.cbc_next = next;
96  ++n;
97  }
98  // it is now something we want to keep
99  order |= (it.cbc_order & CBC_ORDER_ANY);
100  }
101  this.cbc_order = order;
102  return n;
103  }
int cbc_order
Definition: base.qh:49
Callbacks may be added to zero or more callback chains.
Definition: base.qh:17
prev
Definition: all.qh:66
#define NULL
Definition: post.qh:17
next
Definition: all.qh:88
const int CBC_ORDER_ANY
Definition: base.qh:10

Member Data Documentation

◆ cbc_order

int CallbackChain::cbc_order = 0

Definition at line 49 of file base.qh.


The documentation for this class was generated from the following file: