File: Callbacks.hpp

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (45 lines) | stat: -rw-r--r-- 2,258 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 2010 © Václav Šmilauer <eudoxos@arcig.cz>
#pragma once

#include <lib/serialization/Serializable.hpp>

namespace yade { // Cannot have #include directive inside.

class Interaction;
class Body;
class Scene;

class IntrCallback : public Serializable {
public:
	virtual ~IntrCallback() {}; // vtable
	typedef void (*FuncPtr)(IntrCallback*, Interaction*);
	// should be set at every step by InteractionLoop
	Scene* scene;
	/*
	At the beginning of each timestep, perform initialization and
	return pointer to the static member function that does the actual work.
	Returned value might be NULL, in which case the callback will be deactivated during that timestep.
	*/
	virtual FuncPtr stepInit() { throw std::runtime_error("Called IntrCallback::stepInit() of the base class?"); }
	// clang-format off
	YADE_CLASS_BASE_DOC(IntrCallback,Serializable,"Abstract callback object which will be called for every (real) :yref:`Interaction` after the interaction has been processed by :yref:`InteractionLoop`.\n\nAt the beginning of the interaction loop, ``stepInit`` is called, initializing the object; it returns either ``NULL`` (to deactivate the callback during this time step) or pointer to function, which will then be passed (1) pointer to the callback object itself and (2) pointer to :yref:`Interaction`.\n\n.. note::\n\t(NOT YET DONE) This functionality is accessible from python by passing 4th argument to :yref:`InteractionLoop` constructor, or by appending the callback object to :yref:`InteractionLoop::callbacks`.\n");
	// clang-format on
};
REGISTER_SERIALIZABLE(IntrCallback);

#ifdef YADE_BODY_CALLBACKS
class BodyCallback : public Serializable {
public:
	virtual ~BodyCallback() {}; // vtable
	typedef void (*FuncPtr)(BodyCallback*, Body*);
	// set at every step, before stepInit() is called
	Scene*          scene;
	virtual FuncPtr stepInit() { throw std::runtime_error("Called BodyCallback::stepInit() of the base class?"); }
	// clang-format off
		YADE_CLASS_BASE_DOC(BodyCallback,Serializable,"Abstract callback object which will be called for every :yref:`Body` after being processed by :yref:`NewtonIntegrator`. See :yref:`IntrCallback` for details.");
	// clang-format on
};
REGISTER_SERIALIZABLE(BodyCallback);
#endif

} // namespace yade