Author: mordante
Date: Fri Oct 31 19:44:52 2008
New Revision: 30469

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30469&view=rev
Log:
Add a helper function to generate an unique id.

This function will be needed later when a widget without an id needs to
do some registration in new window functions.

Modified:
    trunk/src/gui/widgets/helper.cpp
    trunk/src/gui/widgets/helper.hpp

Modified: trunk/src/gui/widgets/helper.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/helper.cpp?rev=30469&r1=30468&r2=30469&view=diff
==============================================================================
--- trunk/src/gui/widgets/helper.cpp (original)
+++ trunk/src/gui/widgets/helper.cpp Fri Oct 31 19:44:52 2008
@@ -170,5 +170,15 @@
        return t_string(vgettext("Mandatory widget '$id' hasn't been defined.", 
symbols));
 }
 
+std::string get_uid()
+{
+       static unsigned id = 0;
+       ++id;
+       assert(id); // avoid wrapping.
+
+       return "____" + lexical_cast<std::string>(id);
+
+}
+
 } // namespace gui2
 

Modified: trunk/src/gui/widgets/helper.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/helper.hpp?rev=30469&r1=30468&r2=30469&view=diff
==============================================================================
--- trunk/src/gui/widgets/helper.hpp (original)
+++ trunk/src/gui/widgets/helper.hpp Fri Oct 31 19:44:52 2008
@@ -132,6 +132,16 @@
  */
 t_string missing_widget(const std::string& id);
 
+/**
+ * Gets an unique id for a widget.
+ *
+ * The id will have extra leading underscores so it's in the private range and
+ * can't collide with user defined ids.
+ *
+ * @returns                       The id.
+ */
+std::string get_uid();
+
 } // namespace gui2
 
 #endif


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to