"Fossies" - the Fresh Open Source Software Archive

Member "regexxer-0.10/src/signalutils.h" (6 Oct 2011, 2718 Bytes) of package /linux/privat/old/regexxer-0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "signalutils.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2002-2007  Daniel Elstner  <daniel.kitta@gmail.com>
    3  *
    4  * This file is part of regexxer.
    5  *
    6  * regexxer is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * regexxer is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with regexxer; if not, write to the Free Software Foundation,
   18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19  */
   20 
   21 #ifndef REGEXXER_SIGNALUTILS_H_INCLUDED
   22 #define REGEXXER_SIGNALUTILS_H_INCLUDED
   23 
   24 #include <glibmm.h>
   25 
   26 
   27 namespace Util
   28 {
   29 
   30 class QueuedSignal : public sigc::trackable
   31 {
   32 public:
   33   explicit QueuedSignal(int priority = Glib::PRIORITY_HIGH_IDLE);
   34   virtual ~QueuedSignal();
   35 
   36   sigc::connection connect(const sigc::slot<void>& slot);
   37   void queue();
   38   void operator()() { queue(); }
   39 
   40 private:
   41   sigc::signal<void>  signal_;
   42   int                 priority_;
   43   bool                queued_;
   44 
   45   QueuedSignal(const QueuedSignal&);
   46   QueuedSignal& operator=(const QueuedSignal&);
   47 
   48   bool idle_handler();
   49 };
   50 
   51 class AutoConnection
   52 {
   53 private:
   54   sigc::connection  connection_;
   55   bool              blocked_;
   56 
   57   AutoConnection(const AutoConnection&);
   58   AutoConnection& operator=(const AutoConnection&);
   59 
   60 public:
   61   AutoConnection();
   62   explicit AutoConnection(const sigc::connection& connection);
   63   ~AutoConnection();
   64 
   65   void block();
   66   void unblock();
   67   bool blocked() const { return blocked_; }
   68 
   69   AutoConnection& operator=(const sigc::connection& connection);
   70   void disconnect();
   71 
   72   sigc::connection&       base()       { return connection_; }
   73   const sigc::connection& base() const { return connection_; }
   74 };
   75 
   76 class ScopedConnection
   77 {
   78 private:
   79   sigc::connection connection_;
   80 
   81   ScopedConnection(const ScopedConnection&);
   82   ScopedConnection& operator=(const ScopedConnection&);
   83 
   84 public:
   85   explicit ScopedConnection(const sigc::connection& connection)
   86     : connection_ (connection) {}
   87 
   88   ~ScopedConnection() { connection_.disconnect(); }
   89 };
   90 
   91 class ScopedBlock
   92 {
   93 private:
   94   AutoConnection& connection_;
   95 
   96   ScopedBlock(const ScopedBlock&);
   97   ScopedBlock& operator=(const ScopedBlock&);
   98 
   99 public:
  100   explicit ScopedBlock(AutoConnection& connection)
  101     : connection_ (connection) { connection_.block(); }
  102 
  103   ~ScopedBlock() { connection_.unblock(); }
  104 };
  105 
  106 } // namespace Util
  107 
  108 #endif /* REGEXXER_SIGNALUTILS_H_INCLUDED */