This commit introduces nnfw::util::env::IntAccessor which makes it easy
to access environmets (for configuration).
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
}
}
+#include <string>
+
+namespace nnfw
+{
+namespace util
+{
+namespace env
+{
+
+template <typename T> struct Accessor
+{
+ virtual ~Accessor() = default;
+
+ virtual bool access(T &out) const = 0;
+};
+
+class IntAccessor : public Accessor<int>
+{
+public:
+ IntAccessor(const std::string &tag);
+
+public:
+ bool access(int &out) const override;
+
+private:
+ std::string _tag;
+};
+
+} // namespace env
+} // namespace util
+} // namespace nnfw
+
#endif // __UTIL_ENVIRONMENT_H__
} // namespace util
} // namespace nnfw
+
+namespace nnfw
+{
+namespace util
+{
+namespace env
+{
+
+IntAccessor::IntAccessor(const std::string &tag) : _tag{tag}
+{
+ // DO NOTHING
+}
+
+bool IntAccessor::access(int &out) const
+{
+ auto value = std::getenv(_tag.c_str());
+
+ if (value == nullptr)
+ {
+ return false;
+ }
+
+ out = std::stoi(value);
+ return true;
+}
+
+} // namespace env
+} // namespace util
+} // namespace nnfw
add_library(nnapi_unittest_common ${NNAPI_UNITTEST_LIB_SOURCES})
target_include_directories(nnapi_unittest_common PUBLIC "inc")
+target_link_libraries(nnapi_unittest_common nnfw_util)
target_link_libraries(nnapi_unittest_common tensorflow_lite)
function(add_nnapi_unittest NAME)
#include "env.h"
-#include <cstdlib>
+#include "util/environment.h"
//
// Integer variable
//
IntVar::IntVar(const std::string &name, int32_t value) : _value{value}
{
- auto env = std::getenv(name.c_str());
-
- if (env != nullptr)
- {
- _value = std::atoi(env);
- }
+ nnfw::util::env::IntAccessor{name}.access(value);
}