1/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_TSL_UTIL_ENV_VAR_H_
17#define TENSORFLOW_TSL_UTIL_ENV_VAR_H_
18
19#include "tensorflow/tsl/platform/status.h"
20#include "tensorflow/tsl/platform/stringpiece.h"
21#include "tensorflow/tsl/platform/types.h"
22
23namespace tsl {
24
25// Returns a boolean into "value" from the environmental variable
26// "env_var_name". If it is unset, the default value is used. A string "0" or a
27// case insensitive "false" is interpreted as false. A string "1" or a case
28// insensitive "true" is interpreted as true. Otherwise, an error status is
29// returned.
30Status ReadBoolFromEnvVar(StringPiece env_var_name, bool default_val,
31 bool* value);
32
33// Returns an int64 into "value" from the environmental variable "env_var_name".
34// If it is unset, the default value is used.
35// If the string cannot be parsed into int64, an error status is returned.
36Status ReadInt64FromEnvVar(StringPiece env_var_name, int64_t default_val,
37 int64_t* value);
38// Returns a float into "value" from the environmental variable "env_var_name".
39// If it is unset, the default value is used.
40// If the string cannot be parsed into float, an error status is returned.
41Status ReadFloatFromEnvVar(StringPiece env_var_name, float default_val,
42 float* value);
43
44// Returns a string into "value" from the environmental variable "env_var_name".
45// If it is unset, the default value is used.
46Status ReadStringFromEnvVar(StringPiece env_var_name, StringPiece default_val,
47 std::string* value);
48
49// Returns a comma separated string into "value" from the environmental variable
50// "env_var_name". If it is unset, the default value is comma split and used.
51Status ReadStringsFromEnvVar(StringPiece env_var_name, StringPiece default_val,
52 std::vector<std::string>* value);
53
54} // namespace tsl
55
56#endif // TENSORFLOW_TSL_UTIL_ENV_VAR_H_
57