1 // -*- C++ -*-
2 
3 /*
4  * Gnome Chemistry Utils
5  * gcu/dialog-owner.h
6  *
7  * Copyright (C) 2005-2011 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program 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
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
22  * USA
23  */
24 
25 #ifndef GCU_DIALOG_OWNER_H
26 #define GCU_DIALOG_OWNER_H
27 
28 #include <string>
29 #include <map>
30 
31 /*!\file*/
32 namespace gcu {
33 
34 class Dialog;
35 
36 /*!\class DialogOwner gcu/dialog-owner.h
37 This class is the base class for objects owning dialogs. It is aimed at ensuring
38 that each dialog is unique and that when the owner is destroyed, its dialogs
39 are closed.
40 */
41 
42 class DialogOwner
43 {
44 friend class Dialog;
45 public:
46 /*!
47 The constructor.
48 */
49 	DialogOwner ();
50 /*!
51 The destructor.
52 */
53 	virtual ~DialogOwner ();
54 
55 /*!
56 @param name the name associated to the Dialog.
57 
58 @return the Dialog instance associated with name or NULL if there is none.
59 */
60 	Dialog *GetDialog (std::string name) const;
61 
62 /*!
63 	Destroys all dialogs associated with this instance.
64 */
65 	void ClearDialogs ();
66 
67 private:
68 	bool AddDialog (std::string name, Dialog *dialog) ;
RemoveDialog(std::string name)69 	void RemoveDialog (std::string name)  {Dialogs.erase (name);}
70 
71 private:
72 	std::map <std::string, Dialog*> Dialogs;
73 };
74 
75 }	// namespace gcu
76 
77 #endif	// GCU_DIALOG_OWNER_H
78