Poplar and PopLibs
OptionFlags.hpp
1// Copyright (c) 2018 Graphcore Ltd. All rights reserved.
2#ifndef poplar_OptionFlags_hpp
3#define poplar_OptionFlags_hpp
4
5#include <functional>
6#include <initializer_list>
7#include <iosfwd>
8#include <iterator>
9#include <memory>
10#include <poplar/StringRef.hpp>
11#include <string>
12#include <utility>
13
14namespace poplar {
15namespace core {
16class OptionFlags;
17class OptionFlagsIterator;
18} // namespace core
19class ProfileValue;
20
25public:
26 using OptionFlag = std::pair<const std::string, std::string>;
27 using initializer_list = std::initializer_list<OptionFlag>;
28
29 class iterator : public std::iterator<std::forward_iterator_tag, OptionFlag> {
30 std::unique_ptr<core::OptionFlagsIterator> impl;
31
32 iterator(std::unique_ptr<core::OptionFlagsIterator> p) noexcept;
33
34 friend class OptionFlags;
35
36 public:
37 iterator(const iterator &other);
38 iterator &operator=(const iterator &other);
39 iterator(iterator &&other) noexcept;
40 iterator &operator=(iterator &&other) noexcept;
41 ~iterator();
42 const OptionFlag &operator*() const;
43 const OptionFlag *operator->() const;
44 bool operator==(const iterator &other) const;
45 bool operator!=(const iterator &other) const { return !(*this == other); }
46 iterator &operator++();
47 iterator operator++(int) {
48 iterator it(*this);
49 ++(*this);
50 return it;
51 }
52 };
53
54public:
61 OptionFlags(const OptionFlags &other);
62 OptionFlags(OptionFlags &&other) noexcept;
63 OptionFlags &operator=(const OptionFlags &other);
64 OptionFlags &operator=(OptionFlags &&other) noexcept;
65
71 bool operator==(const OptionFlags &other) const;
72
83 OptionFlags(initializer_list &&list) : OptionFlags() { set(std::move(list)); }
84
97 void set(initializer_list &&list);
98
106 void set(StringRef option, StringRef value);
107
113 StringRef at(StringRef option) const;
114
117 void clear();
118
123 iterator begin() const;
124 iterator end() const;
125
126 // Implementation
127private:
128 std::unique_ptr<core::OptionFlags> impl;
129};
130
131ProfileValue getAsProfileValue(const OptionFlags &flags);
132
137void readJSON(StringRef string, OptionFlags &flags);
138
143void readJSON(std::istream &stream, OptionFlags &flags);
144
149void readJSONFromEnv(StringRef envVarName, OptionFlags &flags);
150
154std::ostream &operator<<(std::ostream &ostream, const OptionFlags &flags);
155
156} // end namespace poplar
157
158#endif // poplar_OptionFlags_hpp
A set of option/value string flags to be used in various APIs.
Definition: OptionFlags.hpp:24
void set(initializer_list &&list)
Set option flags from an initializer list of string pairs.
OptionFlags()
Construct a set of option flags.
void clear()
Remove all set flags.
iterator begin() const
Get iterators for the currently set option flags.
void set(StringRef option, StringRef value)
Set a single option to a value.
OptionFlags(initializer_list &&list)
Construct a set of option flags from an initializer list of string pairs.
Definition: OptionFlags.hpp:83
StringRef at(StringRef option) const
Retrieves the value of the given option.
bool operator==(const OptionFlags &other) const
Option flags are an exact match.
ProfileValue represents a read-only JSON-like tree of values that are used to store the output of the...
Definition: ProfileValue.hpp:39
Supported Option flags:
Poplar classes and functions.
Definition: ArrayRef.hpp:14
std::ostream & operator<<(std::ostream &os, const DebugNameAndId &dnai)
Display the path name of the DebugNameAndId.
void readJSON(StringRef string, OptionFlags &flags)
Read options from a string in JSON format.
void readJSONFromEnv(StringRef envVarName, OptionFlags &flags)
Read options from a environment variable in JSON format.