knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Printable.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_PRINTABLE_H
7 #define KNOWROB_PRINTABLE_H
8 
9 #include <ostream>
10 #include <sstream>
11 #include <fmt/format.h>
12 
13 namespace knowrob {
14 
18  class Printable {
19  public:
20  virtual ~Printable() = default;
21 
26  virtual void write(std::ostream &os) const = 0;
27 
32  virtual std::string format() const {
33  std::stringstream ss;
34  write(ss);
35  return ss.str();
36  }
37  };
38 
45  inline std::ostream &operator<<(std::ostream &os, const Printable &printable) {
46  printable.write(os);
47  return os;
48  }
49 }
50 
51 //#if FMT_VERSION >= 90000
52 //template <> struct fmt::formatter<knowrob::Printable> : fmt::ostream_formatter {};
53 //#endif
54 
55 #endif //KNOWROB_PRINTABLE_H
virtual std::string format() const
Definition: Printable.h:32
virtual ~Printable()=default
virtual void write(std::ostream &os) const =0
TermRule & string()
Definition: terms.cpp:63
std::ostream & operator<<(std::ostream &os, const Printable &printable)
Definition: Printable.h:45