File: scope.hpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (33 lines) | stat: -rw-r--r-- 573 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include "common.hpp"

POLYBAR_NS

namespace scope_util {
  /**
   * Creates a wrapper that will trigger given callback when
   * leaving the object's scope (i.e, when it gets destroyed)
   *
   * Example usage:
   * @code cpp
   *   {
   *     on_exit handler([]{ ... });
   *     ...
   *   }
   * @endcode
   */
  class on_exit {
   public:
    on_exit(const function<void(void)>& fn) : m_callback(fn) {}

    virtual ~on_exit() {
      m_callback();
    }

   protected:
    function<void(void)> m_callback;
  };
} // namespace scope_util

POLYBAR_NS_END