ONE - On-device Neural Engine
Loading...
Searching...
No Matches
env.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3
*
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
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
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.
15
*/
16
17
#ifndef __PEPPER_ENV_H__
18
#define __PEPPER_ENV_H__
19
20
#include <string>
21
22
//
23
// KVStore: Key-Value Store Interface
24
//
25
namespace
pepper
// TODO Extract this section if necessary
26
{
27
28
enum class
KVStoreTrait
29
{
30
Queryable
,
31
};
32
33
template
<KVStoreTrait Trait>
class
KVStoreInterface
;
34
35
template
<>
class
KVStoreInterface
<
KVStoreTrait
::
Queryable
>
36
{
37
public
:
38
KVStoreInterface
() =
default
;
39
40
public
:
41
virtual
~KVStoreInterface
() =
default
;
42
43
public
:
// Core interface (PLEASE PREFER TO THE BELOW HELPERS)
44
//
45
// "query(k)" SHOULD
46
// - return a valid C-string if the key "k" exists in the store, or
47
// - return nullptr otherwise.
48
//
49
// DESIGN NOTE - Why "query" instead of "get"?
50
//
51
// Let us consider the following class declarations as an example:
52
//
53
// struct Base {
54
// virtual const char *get(const char *) const = 0;
55
// const char *get(const std::string &s) const { return nullptr; }
56
// };
57
//
58
// struct Derived : public Base {
59
// const char *get(const char *) const final { return nullptr; }
60
// };
61
//
62
// It is impossible to write the code of the following form:
63
//
64
// Derived obj;
65
//
66
// std::string s = ...;
67
// obj.get(s);
68
// ^^^^^^^^^^^
69
// error: no viable conversion from 'std::string' (aka 'basic_string<char>') to 'const char *'
70
//
71
// Please refer to the concept of name hiding in C++ for more details.
72
virtual
const
char
*
query
(
const
char
*k)
const
= 0;
73
74
public
:
// Derived helper methods
75
const
char
*
get
(
const
std::string &k)
const
{
return
query(k.c_str()); }
76
83
std::string get(
const
std::string &key,
const
std::string &default_value)
const
;
84
};
85
86
}
// namespace pepper
87
88
//
89
// ProcessEnvironment
90
//
91
namespace
pepper
92
{
93
94
struct
ProcessEnvironment
final :
public
KVStoreInterface
<KVStoreTrait::Queryable>
95
{
96
const
char
*
query
(
const
char
*k)
const
final
;
97
};
98
99
}
// namespace pepper
100
101
#endif
// __PEPPER_ENV_H__
pepper::KVStoreInterface< KVStoreTrait::Queryable >::~KVStoreInterface
virtual ~KVStoreInterface()=default
pepper::KVStoreInterface< KVStoreTrait::Queryable >::KVStoreInterface
KVStoreInterface()=default
pepper::KVStoreInterface< KVStoreTrait::Queryable >::query
virtual const char * query(const char *k) const =0
pepper::KVStoreInterface< KVStoreTrait::Queryable >::get
const char * get(const std::string &k) const
Definition
env.h:75
pepper::KVStoreInterface
Definition
env.h:33
pepper
Definition
csv2vec.h:24
pepper::KVStoreTrait
KVStoreTrait
Definition
env.h:29
pepper::KVStoreTrait::Queryable
@ Queryable
pepper::ProcessEnvironment
Definition
env.h:95
pepper::ProcessEnvironment::query
const char * query(const char *k) const final
Definition
env.cpp:45
compiler
pepper-env
include
pepper
env.h
Generated by
1.9.8