From e8b0b1b03631398c63927f1d1c2ce0e510bb1cd4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 7 Jun 2018 18:39:20 +0900 Subject: [PATCH] Add StrVar class (#1599) This commit adds StrVar class which reads string value from environment (as it is). Default value will be used if corresponding environment variable does not exists. Signed-off-by: Jonghyun Park --- tools/nnapi_unittests/inc/env.h | 12 ++++++++++++ tools/nnapi_unittests/lib/env.cpp | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tools/nnapi_unittests/inc/env.h b/tools/nnapi_unittests/inc/env.h index 8926dab..95b3875 100644 --- a/tools/nnapi_unittests/inc/env.h +++ b/tools/nnapi_unittests/inc/env.h @@ -33,4 +33,16 @@ private: int32_t _value; }; +class StrVar +{ +public: + StrVar(const std::string &name, const std::string &value); + +public: + const std::string &operator()(void) const { return _value; } + +private: + std::string _value; +}; + #endif // __ENV_UTILS_H__ diff --git a/tools/nnapi_unittests/lib/env.cpp b/tools/nnapi_unittests/lib/env.cpp index efad443..f0646ed 100644 --- a/tools/nnapi_unittests/lib/env.cpp +++ b/tools/nnapi_unittests/lib/env.cpp @@ -25,3 +25,18 @@ IntVar::IntVar(const std::string &name, int32_t value) : _value{value} { nnfw::util::env::IntAccessor{name}.access(_value); } + +// +// String variable +// +#include + +StrVar::StrVar(const std::string &name, const std::string &value) : _value{value} +{ + auto env = std::getenv(name.c_str()); + + if (env) + { + _value = std::string{env}; + } +} -- 2.7.4