]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/utils/EnvVariable.h
2 * Copyright (c) 2019 The Jaeger Authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef JAEGERTRACING_UTILS_ENV_VARIABLE_H
18 #define JAEGERTRACING_UTILS_ENV_VARIABLE_H
24 namespace jaegertracing
{
26 namespace EnvVariable
{
28 inline std::string
getStringVariable(const char* envVar
)
30 const auto rawVariable
= std::getenv(envVar
);
31 return std::string(rawVariable
? rawVariable
: "");
34 inline std::pair
<bool, int> getIntVariable(const char* envVar
)
36 const auto rawVariable
= std::getenv(envVar
);
37 const std::string
variable(rawVariable
? rawVariable
: "");
38 if (!variable
.empty()) {
39 std::istringstream
iss(variable
);
42 return std::make_pair(false, intVal
);
45 return std::make_pair(false, 0);
48 inline std::pair
<bool, bool> getBoolVariable(const char* envVar
)
50 const auto rawVariable
= std::getenv(envVar
);
51 std::string
variable(rawVariable
? rawVariable
: "");
53 if (!variable
.empty()) {
55 variable
.begin(), variable
.end(), variable
.begin(), ::tolower
);
56 return std::make_pair(true, (variable
== "true"));
58 return std::make_pair(false, false);
61 } // namespace EnvVariable
63 } // namespace jaegertracing
65 #endif // JAEGERTRACING_UTILS_ENV_VARIABLE_H