2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class CoreExport dynamic_reference_base : public interfacebase, public insp::intrusive_list_node<dynamic_reference_base>
31 /** Called when the target of the dynamic_reference has been acquired
33 virtual void OnCapture() = 0;
41 ServiceProvider* value;
44 dynamic_reference_base(Module* Creator, const std::string& Name);
45 ~dynamic_reference_base();
46 inline const std::string& GetProvider() { return name; }
47 void SetProvider(const std::string& newname);
49 /** Set handler to call when the target object becomes available
50 * @param h Handler to call
52 void SetCaptureHook(CaptureHook* h) { hook = h; }
55 operator bool() { return (value != NULL); }
56 static void reset_all();
59 inline void dynamic_reference_base::check()
62 throw ModuleException("Dynamic reference to '" + name + "' failed to resolve");
66 class dynamic_reference : public dynamic_reference_base
69 dynamic_reference(Module* Creator, const std::string& Name)
70 : dynamic_reference_base(Creator, Name) {}
72 inline T* operator->()
75 return static_cast<T*>(value);
83 const T* operator->() const
85 return static_cast<T*>(value);
88 const T* operator*() const
95 class dynamic_reference_nocheck : public dynamic_reference_base
98 dynamic_reference_nocheck(Module* Creator, const std::string& Name)
99 : dynamic_reference_base(Creator, Name) {}
103 return static_cast<T*>(value);
111 const T* operator->() const
113 return static_cast<T*>(value);
116 const T* operator*() const
123 class ChanModeReference : public dynamic_reference_nocheck<ModeHandler>
126 ChanModeReference(Module* mod, const std::string& modename)
127 : dynamic_reference_nocheck<ModeHandler>(mod, "mode/" + modename) {}
130 class UserModeReference : public dynamic_reference_nocheck<ModeHandler>
133 UserModeReference(Module* mod, const std::string& modename)
134 : dynamic_reference_nocheck<ModeHandler>(mod, "umode/" + modename) {}