Sha256: 1eb15ade642b3801049bf95f1daa58be1a586f888fe9157c197509efb354f981

Contents?: true

Size: 1.08 KB

Versions: 16

Compression:

Stored size: 1.08 KB

Contents

/**
 * @file
 * Declares the scoped resource for temporarily changing an environment variable.
 */
#pragma once

#include <leatherman/util/scoped_resource.hpp>
#include <string>
#include <boost/optional.hpp>

namespace leatherman { namespace util {

    /**
     * This is an RAII wrapper for temporarily changing an environment variable.
     * It sets the environment on construction and restores it on destruction.
     */
    struct scoped_env : scoped_resource<std::tuple<std::string, boost::optional<std::string>>>
    {
        /**
         * Temporarily overrides the value of an environment variable.
         * @param var    The environment variable to update.
         * @param newval The value to set it to during existence of this object.
         */
        explicit scoped_env(std::string var, std::string const& newval);

        /**
         * Temporarily unsets an environment variable.
         */
        explicit scoped_env(std::string var);

     private:
        static void restore(std::tuple<std::string, boost::optional<std::string>> &);
    };

}}  // 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/scoped_env.hpp
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/util/inc/leatherman/util/scoped_env.hpp