LLVM OpenMP
EnvHelper.h
Go to the documentation of this file.
1//===- EnvHelper.h - General logging class ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Provides environment helpers shared between a couple of places.
11///
12//===----------------------------------------------------------------------===//
13
14#include <optional>
15
16#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_ENVHELPER_H
17#define OPENMP_TOOLS_OMPTEST_INCLUDE_ENVHELPER_H
18
19namespace omptest {
20/// Load the value of a given boolean environmental variable. Return
21/// std::nullopt if not specified in the environment.
22inline std::optional<bool>
23getBoolEnvironmentVariable(const char *VariableName) {
24 if (VariableName == nullptr)
25 return std::nullopt;
26 if (const char *EnvValue = std::getenv(VariableName)) {
27 std::string S{EnvValue};
28 for (auto &C : S)
29 C = (char)std::tolower(C);
30 if (S == "1" || S == "on" || S == "true" || S == "yes")
31 return true;
32 if (S == "0" || S == "off" || S == "false" || S == "no")
33 return false;
34 }
35 return std::nullopt;
36}
37} // namespace omptest
38#endif // OPENMP_TOOLS_OMPTEST_INCLUDE_ENVHELPER_H
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark S
std::optional< bool > getBoolEnvironmentVariable(const char *VariableName)
Load the value of a given boolean environmental variable.
Definition EnvHelper.h:23
#define C