2
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3
* http://www.gnu.org/licenses/lgpl-3.0.html
6
#ifndef PROJECTLOADER_HOOKS_H
7
#define PROJECTLOADER_HOOKS_H
14
/** Provides static functions to add hooks to the project loading/saving procedure. */
15
namespace ProjectLoaderHooks
17
/** Abstract base hook functor interface. */
18
class DLLIMPORT HookFunctorBase
21
virtual ~HookFunctorBase(){}
22
virtual void Call(cbProject*, TiXmlElement*, bool) const = 0;
25
/** Functor class for use as a project loading/saving hook.
26
* Passed as the first parameter in RegisterHook() and
30
* ProjectLoaderHooks::HookFunctorBase* myhook = new ProjectLoaderHooks::HookFunctor<MyClass>(this, &MyClass::OnHookCalled);
31
* int id = ProjectLoaderHooks::RegisterHook(myhook);
33
* (and before your class' destruction - or earlier):
34
* ProjectLoaderHooks::UnregisterHook(id, true);
36
* Member functions used as hook callbacks must have the following signature:
37
* void YourFunctionName(cbProject*, TiXmlElement*, bool)
39
* Use normal TinyXML procedures to work with the TiXmlElement* argument.
40
* The isLoading argument is true if your hook is called when the project is being loaded,
41
* and false when the project is saved.
43
template<class T> class DLLIMPORT HookFunctor : public HookFunctorBase
46
typedef void (T::*Func)(cbProject*, TiXmlElement*, bool);
47
HookFunctor(T* obj, Func func)
51
virtual void Call(cbProject* project, TiXmlElement* elem, bool isLoading) const
53
if (m_pObj && m_pFunc)
54
(m_pObj->*m_pFunc)(project, elem, isLoading);
61
/** Register a project loading/saving hook.
62
* @param functor The functor to use as a callback.
63
* @return An ID. Use this to unregister your hook later.
65
extern DLLIMPORT int RegisterHook(HookFunctorBase* functor);
66
/** Unregister a previously registered project loading/saving hook.
67
* @param id The hook's ID. You should have the ID from when RegisterHook() was called.
68
* @param deleteHook If true, the hook will be deleted (default). If not, it's
69
* up to you to delete it.
70
* @return The functor. If @c deleteHook was true, it always returns NULL.
72
extern DLLIMPORT HookFunctorBase* UnregisterHook(int id, bool deleteHook = true);
73
/** Are there any hooks registered?
74
* @return True if any hooks are registered, false if none.
76
extern DLLIMPORT bool HasRegisteredHooks();
77
/** Call all registered hooks using the supplied parameters.
78
* This is called by ProjectLoader.
79
* @param project The project in question.
80
* @param elem The XML element under which the called hook can read/write.
81
* @param isLoading True if the project is being loaded, false if being saved.
83
extern DLLIMPORT void CallHooks(cbProject* project, TiXmlElement* elem, bool isLoading);
86
#endif // PROJECTLOADER_HOOKS_H