Sha256: db3e67b385935aab4bb83d54dcc792dad0c8e29de93886a0f0e75d0bbe96dcc1

Contents?: true

Size: 1.57 KB

Versions: 16

Compression:

Stored size: 1.57 KB

Contents

/**
 * @file
 * Declares the base class for scope exit.
 */
#pragma once

#include <functional>

namespace leatherman { namespace util {

    /**
     * Used to call a function when scope is exited.
    */
    struct scope_exit
    {
        /**
         * Constructs a scope_exit.
         */
        scope_exit();

        /**
         * Constructs a scope_exit.
         * @param callback The function to call when scope is exited.
         */
        explicit scope_exit(std::function<void()> callback);

        /**
         * Moves the given scope_exit into this scope_exit.
         * @param other The scope_exit to move into this scope_exit.
         */
        scope_exit(scope_exit&& other);

        /**
         * Moves the given scoped_resource into this scoped_resource.
         * @param other The scoped_resource to move into this scoped_resource.
         * @return Returns this scope_exit.
         */
        scope_exit& operator=(scope_exit&& other);

        /**
         * Destructs a scope_exit.
         */
        ~scope_exit();

        /**
         * Invokes the callback.
         * If called, the callback will not be called upon destruction.
         */
        void invoke();

    private:
        explicit scope_exit(scope_exit const&) = delete;
        scope_exit& operator=(scope_exit const&) = delete;
        void* operator new(size_t) = delete;
        void operator delete(void*) = delete;
        void* operator new[](size_t) = delete;
        void operator delete[](void* ptr) = delete;

        std::function<void()> _callback;
    };

}}  // namespace leatherman::util

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/util/inc/leatherman/util/scope_exit.hpp