PageRenderTime 382ms CodeModel.GetById 159ms app.highlight 6ms RepoModel.GetById 84ms app.codeStats 1ms

/indra/newview/llconfirmationmanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 85 lines | 48 code | 11 blank | 26 comment | 0 complexity | 533dabca10f785ba7d8ca0cc0d2c6a01 MD5 | raw file
 1/** 
 2 * @file llconfirmationmanager.h
 3 * @brief LLConfirmationManager class definition
 4 *
 5 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#ifndef LL_LLCONFIRMATIONMANAGER_H
28#define LL_LLCONFIRMATIONMANAGER_H
29
30class LLConfirmationManager
31{
32public:
33	class ListenerBase
34	{
35	public:
36		virtual ~ListenerBase();
37		virtual void confirmed(const std::string& password) = 0;
38	};
39
40	enum Type { TYPE_NONE, TYPE_CLICK, TYPE_PASSWORD };
41	
42	static void confirm(Type type,
43		const std::string& purchase, ListenerBase* listener);
44	static void confirm(const std::string& type,
45		const std::string& purchase, ListenerBase* listener);
46		// note: these take control of, and delete the listener when done
47
48	template <class T>
49	class Listener : public ListenerBase
50	{
51	public:
52		typedef void (T::*ConfirmationMemberFunction)(const std::string&);
53		
54		Listener(T& object, ConfirmationMemberFunction function)
55			: mObject(object), mFunction(function)
56			{ }
57		
58		void confirmed(const std::string& password)
59		{
60			(mObject.*mFunction)(password);
61		}
62		
63	private:
64		T& mObject;
65		ConfirmationMemberFunction mFunction;
66	};
67
68	template <class T>
69	static void confirm(Type type,
70		const std::string& action,
71		T& obj, void(T::*func)(const std::string&))
72	{
73		confirm(type, action, new Listener<T>(obj, func));
74	}
75	
76	template <class T>
77	static void confirm(const std::string& type,
78		const std::string& action,
79		T& obj, void(T::*func)(const std::string&))
80	{
81		confirm(type, action, new Listener<T>(obj, func));
82	}		
83};
84
85#endif