[glibmm] Move IOCondition from main.h to iochannel.h and autogenerate it.



commit c97f8e8681e550ebe09af9ac5a366273b6d98673
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Oct 26 12:24:38 2011 +0200

    Move IOCondition from main.h to iochannel.h and autogenerate it.
    
    	* glib/src/iochannel.hg: Use _WRAP_ENUM() for IOCondition instead of
    	hand-coding it in
    	* glib/glibmm/main.h:
    	though this requires some manual editing of
    	* glib/src/glib_enums.defs: due to the weird defines that GioChannel uses for
    	its values. See the comment.
    	* glib/glibmm/streamiochannel.cc: Adjust the includes.
    	This avoids the need to include glib.h from main.h.

 ChangeLog                      |   13 +++++++++
 glib/glibmm/main.h             |   54 +---------------------------------------
 glib/glibmm/streamiochannel.cc |    1 +
 glib/src/glib_enums.defs       |   20 ++++++++++----
 glib/src/iochannel.hg          |   17 +++++++++++-
 5 files changed, 44 insertions(+), 61 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 81c9127..99ac870 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2011-10-26  Murray Cumming  <murrayc murrayc com>
 
+	Move IOCondition from main.h to iochannel.h and autogenerate it.
+
+	* glib/src/iochannel.hg: Use _WRAP_ENUM() for IOCondition instead of 
+	hand-coding it in 
+	* glib/glibmm/main.h: 
+	though this requires some manual editing of 
+	* glib/src/glib_enums.defs: due to the weird defines that GioChannel uses for
+	its values. See the comment.
+	* glib/glibmm/streamiochannel.cc: Adjust the includes.
+	This avoids the need to include glib.h from main.h.
+	
+2011-10-26  Murray Cumming  <murrayc murrayc com>
+
 	Avoid some deprecation compiler warnings. 
 
 	* gio/src/file.hg:
diff --git a/glib/glibmm/main.h b/glib/glibmm/main.h
index 1905344..6d1cbda 100644
--- a/glib/glibmm/main.h
+++ b/glib/glibmm/main.h
@@ -23,8 +23,8 @@
 #include <glibmm/refptr.h>
 #include <glibmm/timeval.h>
 #include <glibmm/priorities.h>
+#include <glibmm/iochannel.h>
 #include <sigc++/sigc++.h>
-#include <glib.h>
 #include <vector>
 
 namespace Glib
@@ -32,64 +32,12 @@ namespace Glib
 
 class Cond;
 class Mutex;
-class IOChannel;
 
 /** @defgroup MainLoop The Main Event Loop
  * Manages all available sources of events.
  * @{
  */
 
-/** A bitwise combination representing an I/O condition to watch for on an
- * event source.
- * The flags correspond to those used by the <tt>%poll()</tt> system call
- * on UNIX (see <tt>man 2 poll</tt>).  To test for individual flags, do
- * something like this:
- * @code
- * if((condition & Glib::IO_OUT) != 0)
- *   do_some_output();
- * @endcode
- * @par Bitwise operators:
- * <tt>IOCondition operator|(IOCondition, IOCondition)</tt><br>
- * <tt>IOCondition operator&(IOCondition, IOCondition)</tt><br>
- * <tt>IOCondition operator^(IOCondition, IOCondition)</tt><br>
- * <tt>IOCondition operator~(IOCondition)</tt><br>
- * <tt>IOCondition& operator|=(IOCondition&, IOCondition)</tt><br>
- * <tt>IOCondition& operator&=(IOCondition&, IOCondition)</tt><br>
- * <tt>IOCondition& operator^=(IOCondition&, IOCondition)</tt><br>
- */
-enum IOCondition
-{
-  IO_IN   = G_IO_IN,  /*!< @hideinitializer There is data to read. */
-  IO_OUT  = G_IO_OUT, /*!< @hideinitializer Data can be written (without blocking). */
-  IO_PRI  = G_IO_PRI, /*!< @hideinitializer There is urgent data to read. */
-  IO_ERR  = G_IO_ERR, /*!< @hideinitializer %Error condition. */
-  IO_HUP  = G_IO_HUP, /*!< @hideinitializer Hung up (the connection has been broken,
-                                            usually for pipes and sockets). */
-  IO_NVAL = G_IO_NVAL /*!< @hideinitializer Invalid request. The file descriptor is not open. */
-};
-
-inline IOCondition operator|(IOCondition lhs, IOCondition rhs)
-  { return static_cast<IOCondition>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
-
-inline IOCondition operator&(IOCondition lhs, IOCondition rhs)
-  { return static_cast<IOCondition>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
-
-inline IOCondition operator^(IOCondition lhs, IOCondition rhs)
-  { return static_cast<IOCondition>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
-
-inline IOCondition operator~(IOCondition flags)
-  { return static_cast<IOCondition>(~static_cast<unsigned>(flags)); }
-
-inline IOCondition& operator|=(IOCondition& lhs, IOCondition rhs)
-  { return (lhs = static_cast<IOCondition>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
-
-inline IOCondition& operator&=(IOCondition& lhs, IOCondition rhs)
-  { return (lhs = static_cast<IOCondition>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
-
-inline IOCondition& operator^=(IOCondition& lhs, IOCondition rhs)
-  { return (lhs = static_cast<IOCondition>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
-
-
 class PollFD
 {
 public:
diff --git a/glib/glibmm/streamiochannel.cc b/glib/glibmm/streamiochannel.cc
index 08b661b..e5201db 100644
--- a/glib/glibmm/streamiochannel.cc
+++ b/glib/glibmm/streamiochannel.cc
@@ -18,6 +18,7 @@
  */
 
 #include <glibmm/streamiochannel.h>
+#include <glibmm/main.h> //For Source
 #include <glib.h>
 #include <fstream>
 #include <iostream>
diff --git a/glib/src/glib_enums.defs b/glib/src/glib_enums.defs
index bfec0b5..09c252b 100644
--- a/glib/src/glib_enums.defs
+++ b/glib/src/glib_enums.defs
@@ -368,16 +368,24 @@
 ;;   G_IO_NVAL	GLIB_SYSDEF_POLLNVAL
 ;; } GIOCondition;
 
+;; We hand-edit these to use the actual enum values,
+;; because the values are actually defines that contain a =,
+;; which is very bizarre.
+;; We would need to include the header anyway,
+;; because we can't just use numeric values.
+;; If you regenerate this .defs file and forget to make this change
+;; then you will see compiler errors like this:
+;; ../glibmm/iochannel.h:154:12: error: expected primary-expression before '=' token
 (define-flags-extended IOCondition
   (in-module "G")
   (c-name "GIOCondition")
   (values
-    '("in" "G_IO_IN" "GLIB_SYSDEF_POLLIN")
-    '("out" "G_IO_OUT" "GLIB_SYSDEF_POLLOUT")
-    '("pri" "G_IO_PRI" "GLIB_SYSDEF_POLLPRI")
-    '("err" "G_IO_ERR" "GLIB_SYSDEF_POLLERR")
-    '("hup" "G_IO_HUP" "GLIB_SYSDEF_POLLHUP")
-    '("nval" "G_IO_NVAL" "GLIB_SYSDEF_POLLNVAL")
+    '("in" "G_IO_IN" "G_IO_IN")
+    '("out" "G_IO_OUT" "G_IO_OUT")
+    '("pri" "G_IO_PRI" "G_IO_PRI")
+    '("err" "G_IO_ERR" "G_IO_ERR")
+    '("hup" "G_IO_HUP" "G_IO_HUP")
+    '("nval" "G_IO_NVAL" "G_IO_NVAL")
   )
 )
 
diff --git a/glib/src/iochannel.hg b/glib/src/iochannel.hg
index f4853c3..a59d3c5 100644
--- a/glib/src/iochannel.hg
+++ b/glib/src/iochannel.hg
@@ -21,11 +21,11 @@
 _DEFS(glibmm,glib)
 
 #include <glibmmconfig.h>
+#include <glib.h> //For the GIOChannel enum values.
 #include <glibmm/error.h>
-#include <glibmm/main.h>
 #include <glibmm/refptr.h>
 #include <glibmm/ustring.h>
-#include <glib.h>
+#include <sigc++/sigc++.h>
 #include <string>
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -42,6 +42,19 @@ _WRAP_ENUM(SeekType, GSeekType, NO_GTYPE, s#^SEEK_#SEEK_TYPE_#)
 _WRAP_ENUM(IOStatus, GIOStatus, NO_GTYPE)
 _WRAP_ENUM(IOFlags, GIOFlags, NO_GTYPE)
 
+
+/** A bitwise combination representing an I/O condition to watch for on an
+ * event source.
+ * The flags correspond to those used by the <tt>%poll()</tt> system call
+ * on UNIX (see <tt>man 2 poll</tt>).  To test for individual flags, do
+ * something like this:
+ * @code
+ * if((condition & Glib::IO_OUT) != 0)
+ *   do_some_output();
+ * @endcode
+ */
+_WRAP_ENUM(IOCondition, GIOCondition, NO_GTYPE)
+
 /** Exception class for IOChannel errors.
  */
 _WRAP_GERROR(IOChannelError, GIOChannelError, G_IO_CHANNEL_ERROR, NO_GTYPE,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]