ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Support.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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 __SUPPORT_H__
18#define __SUPPORT_H__
19
20#include <string>
21
22#include <iostream>
23#include <memory>
24
26{
27public:
28 Cmdline() = delete;
29 Cmdline(int argc, const char *const *argv) : _argc(static_cast<unsigned int>(argc)), _argv{argv}
30 {
31 // DO NOTHING
32 }
33
34 std::string get(unsigned int index) const;
35 std::string get_or(unsigned int index, const std::string &) const;
36
37private:
38 unsigned int _argc;
39 const char *const *_argv;
40};
41
42class UI
43{
44public:
45 std::istream *in() const { return _in ? _in.get() : &std::cin; }
46 std::ostream *out() const { return _out ? _out.get() : &std::cout; }
47
48public:
49 void in(std::unique_ptr<std::istream> &&in) { _in = std::move(in); }
50 void out(std::unique_ptr<std::ostream> &&out) { _out = std::move(out); }
51
52private:
53 std::unique_ptr<std::istream> _in;
54 std::unique_ptr<std::ostream> _out;
55};
56
57std::unique_ptr<UI> make_ui(const Cmdline &cmdargs);
58
59#endif // __SUPPORT_H__
Cmdline()=delete
Cmdline(int argc, const char *const *argv)
Definition Support.hpp:29
std::string get(unsigned int index) const
Definition Support.cpp:45
std::string get_or(unsigned int index, const std::string &) const
Definition Support.cpp:53
Definition Support.hpp:43
void out(std::unique_ptr< std::ostream > &&out)
Definition Support.hpp:50
std::ostream * out() const
Definition Support.hpp:46
std::istream * in() const
Definition Support.hpp:45
void in(std::unique_ptr< std::istream > &&in)
Definition Support.hpp:49
std::unique_ptr< UI > make_ui(const Cmdline &cmdargs)
Definition Support.cpp:61