Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mapping_options_cpp_printer.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <iostream>
19 #include <string>
20 
22 
23 namespace tc {
24 
26  public:
28  const MappingOptions& options_,
29  size_t indent_ = 0)
30  : options(options_), indent(indent_) {}
32  size_t indent;
33 };
34 
36  public:
37  MappingOptionsCppPrinter(std::ostream& out, size_t ws = 0)
38  : out_(out), ws_(ws) {}
39 
42  const std::string& str);
43 
46  const MappingOptions& options);
47 
48  private:
49  inline MappingOptionsCppPrinter& tab();
52  inline MappingOptionsCppPrinter& printString(const char* str);
53  inline MappingOptionsCppPrinter& printString(const std::string str) {
54  return printString(str.c_str());
55  }
57  const std::string& name,
58  bool value);
59 
60  template <typename T>
62  const std::string& name,
63  const std::vector<T>& values);
64 
65  template <typename T>
67  const std::string& name,
68  const T& value);
69 
71  const SchedulerOptionsView& schedulerOptions,
72  const std::string& prefix);
73 
74  std::ostream& out_;
75  size_t ws_;
76  bool lineContinuation_ = false;
77 };
78 
79 inline std::ostream& operator<<(
80  std::ostream& out,
81  const MappingOptionsAsCpp& mo) {
82  auto prn = MappingOptionsCppPrinter(out, mo.indent);
83  prn << mo.options;
84  return out;
85 }
86 
88  for (size_t i = 0; i < ws_; ++i) {
89  out_ << " ";
90  }
91  return *this;
92 }
93 
95  this->out_ << std::endl;
96  if (!lineContinuation_) {
97  lineContinuation_ = true;
98  ws_ += 4;
99  }
100  return *this;
101 }
102 
104  this->out_ << ";" << std::endl;
105  lineContinuation_ = false;
106  ws_ -= 4;
107  return *this;
108 }
109 
111  const char* str) {
112  this->out_ << str;
113  return *this;
114 }
115 
117  const std::string& name,
118  bool value) {
119  endl();
120  tab();
121  out_ << "." << name << "(" << (value ? "true" : "false") << ")";
122  return *this;
123 }
124 
125 template <typename T>
127  const std::string& name,
128  const T& value) {
129  endl();
130  tab();
131  out_ << "." << name << "(" << value << ")";
132  return *this;
133 }
134 
135 template <typename T>
137  const std::string& name,
138  const std::vector<T>& values) {
139  endl();
140  tab();
141  out_ << "." << name << "(";
142  if (values.size() > 0) {
143  out_ << values[0];
144  }
145  for (size_t i = 1, e = values.size(); i < e; ++i) {
146  out_ << ", " << values[i];
147  }
148  out_ << ")";
149  return *this;
150 }
151 } // namespace tc
size_t ws_
Definition: mapping_options_cpp_printer.h:75
size_t indent
Definition: mapping_options_cpp_printer.h:32
MappingOptionsCppPrinter & printBooleanOption(const std::string &name, bool value)
Definition: mapping_options_cpp_printer.h:116
MappingOptionsCppPrinter & endStmt()
Definition: mapping_options_cpp_printer.h:103
MappingOptionsCppPrinter & printString(const std::string str)
Definition: mapping_options_cpp_printer.h:53
friend MappingOptionsCppPrinter & operator<<(MappingOptionsCppPrinter &prn, const std::string &str)
MappingOptionsCppPrinter & printListOption(const std::string &name, const std::vector< T > &values)
Definition: mapping_options_cpp_printer.h:136
MappingOptionsCppPrinter(std::ostream &out, size_t ws=0)
Definition: mapping_options_cpp_printer.h:37
MappingOptionsAsCpp(const MappingOptions &options_, size_t indent_=0)
Definition: mapping_options_cpp_printer.h:27
std::ostream & out_
Definition: mapping_options_cpp_printer.h:74
Definition: mapping_options_cpp_printer.h:35
MappingOptionsCppPrinter & printSchedulerOptions(const SchedulerOptionsView &schedulerOptions, const std::string &prefix)
std::ostream & operator<<(std::ostream &out, const MappingOptionsAsCpp &mo)
Definition: mapping_options_cpp_printer.h:79
MappingOptionsCppPrinter & tab()
Definition: mapping_options_cpp_printer.h:87
Definition: mapping_options.h:336
MappingOptionsCppPrinter & endl()
Definition: mapping_options_cpp_printer.h:94
bool lineContinuation_
Definition: mapping_options_cpp_printer.h:76
const MappingOptions & options
Definition: mapping_options_cpp_printer.h:31
MappingOptionsCppPrinter & printValueOption(const std::string &name, const T &value)
Definition: mapping_options_cpp_printer.h:126
Definition: mapping_options.h:278
Definition: mapping_options_cpp_printer.h:25
MappingOptionsCppPrinter & printString(const char *str)
Definition: mapping_options_cpp_printer.h:110