scenario_simulator_v2 C++ API
highlighter.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSCENARIO_INTERPRETER__UTILITY__HIGHLIGHTER_HPP_
16 #define OPENSCENARIO_INTERPRETER__UTILITY__HIGHLIGHTER_HPP_
17 
18 #include <iostream>
20 #include <string>
21 #include <utility>
22 
24 {
25 inline namespace utility
26 {
28 {
30 
31  template <typename... Ts>
32  decltype(auto) operator()(std::basic_ostream<Ts...> & os) const
33  {
34  return os << yellow << name << reset << "=" << cyan << "\"" << value << "\"" << reset;
35  }
36 };
37 
38 template <typename... Ts>
39 decltype(auto) operator<<(std::basic_ostream<Ts...> & os, const AttributeHighlighter & highlight)
40 {
41  return highlight(os);
42 }
43 
44 template <typename T, typename = typename std::enable_if<HasStreamOutputOperator<T>::value>::type>
45 auto highlight(const std::string & name, const T & value)
46 {
47  return AttributeHighlighter{name, boost::lexical_cast<std::string>(value)};
48 }
49 } // namespace utility
50 } // namespace openscenario_interpreter
51 
52 #endif // OPENSCENARIO_INTERPRETER__UTILITY__HIGHLIGHTER_HPP_
auto yellow
Definition: escape_sequence.hpp:49
auto cyan
Definition: escape_sequence.hpp:52
auto reset
Definition: escape_sequence.hpp:34
auto highlight(const std::string &name, const T &value)
Definition: highlighter.hpp:45
Definition: escape_sequence.hpp:22
Definition: cache.hpp:27
std::string string
Definition: junit5.hpp:26
const std::string value
Definition: highlighter.hpp:29
const std::string name
Definition: highlighter.hpp:29