mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
2a6dd2879d
Summary: Eden's on C++17 so fully cross the rubicon! Reviewed By: strager Differential Revision: D10498200 fbshipit-source-id: 4e2af5a8d5cef9a106e8c05e6f93ea9e5b8e696e
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2004-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
#pragma once
|
|
#include <folly/Range.h>
|
|
#include <optional>
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
/**
|
|
* A helper class for manipulating an environment variable,
|
|
* and restoring it to its original state at the end of the current scope.
|
|
*/
|
|
class ScopedEnvVar {
|
|
public:
|
|
explicit ScopedEnvVar(folly::StringPiece name);
|
|
~ScopedEnvVar();
|
|
|
|
/**
|
|
* Unset the environment variable.
|
|
*/
|
|
void unset();
|
|
|
|
/**
|
|
* Set the environment variable
|
|
*/
|
|
void set(const char* value);
|
|
void set(const std::string& value);
|
|
void set(folly::StringPiece value);
|
|
|
|
private:
|
|
/**
|
|
* The environment variable name.
|
|
*/
|
|
std::optional<std::string> name_;
|
|
|
|
/**
|
|
* The original value of this environment variable that we should restore it
|
|
* to on destruction of this ScopedEnvVar. This will be std::nullopt if the
|
|
* environment variable was originally unset, and should be unset on
|
|
* destruction.
|
|
*/
|
|
std::optional<std::string> origValue_;
|
|
};
|
|
} // namespace eden
|
|
} // namespace facebook
|