Code::Blocks  SVN r11506
projectloader_hooks.cpp
Go to the documentation of this file.
1 /*
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
4  *
5  * $Revision: 9426 $
6  * $Id: projectloader_hooks.cpp 9426 2013-11-02 19:42:20Z alpha0010 $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/projectloader_hooks.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include "cbproject.h"
14 #endif
15 
16 #include "projectloader_hooks.h"
17 #include "tinyxml.h"
18 
19 #include <map>
20 
21 namespace ProjectLoaderHooks
22 {
23  typedef std::map<int, HookFunctorBase*> HookFunctorsMap;
24  static HookFunctorsMap s_HookFunctorsMap;
25  static int s_UniqueID = 0;
26 }
27 
29 {
30  for (HookFunctorsMap::iterator it = s_HookFunctorsMap.begin(); it != s_HookFunctorsMap.end(); ++it)
31  {
32  if (it->second == functor)
33  return it->first;
34  }
35  s_HookFunctorsMap[s_UniqueID] = functor;
36  return s_UniqueID++;
37 }
38 
40 {
41  HookFunctorsMap::iterator it = s_HookFunctorsMap.find(id);
42  if (it != s_HookFunctorsMap.end())
43  {
44  ProjectLoaderHooks::HookFunctorBase* functor = it->second;
45  s_HookFunctorsMap.erase(it);
46  if (deleteHook)
47  {
48  delete functor;
49  return nullptr;
50  }
51  return functor;
52  }
53  return nullptr;
54 }
55 
57 {
58  return s_HookFunctorsMap.size() != 0;
59 }
60 
61 void ProjectLoaderHooks::CallHooks(cbProject* project, TiXmlElement* elem, bool isLoading)
62 {
63  for (HookFunctorsMap::iterator it = s_HookFunctorsMap.begin(); it != s_HookFunctorsMap.end(); ++it)
64  {
65  ProjectLoaderHooks::HookFunctorBase* functor = it->second;
66  if (functor)
67  functor->Call(project, elem, isLoading);
68  }
69 }
DLLIMPORT void CallHooks(cbProject *project, TiXmlElement *elem, bool isLoading)
Call all registered hooks using the supplied parameters.
std::map< int, HookFunctorBase * > HookFunctorsMap
Provides static functions to add hooks to the project loading/saving procedure.
DLLIMPORT HookFunctorBase * UnregisterHook(int id, bool deleteHook=true)
Unregister a previously registered project loading/saving hook.
Represents a Code::Blocks project.
Definition: cbproject.h:96
DLLIMPORT int RegisterHook(HookFunctorBase *functor)
Register a project loading/saving hook.
static HookFunctorsMap s_HookFunctorsMap
Abstract base hook functor interface.
DLLIMPORT bool HasRegisteredHooks()
Are there any hooks registered?
virtual void Call(cbProject *, TiXmlElement *, bool) const =0