Print.hpp
Go to the documentation of this file.
1 /****
2  * Print.cpp - Helper function templates to simplify printing of objects and variables
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the FlashString Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <Print.h>
23 
30 namespace FSTR
31 {
39 template <class ObjectType>
40 typename std::enable_if<std::is_class<ObjectType>::value, size_t>::type print(Print& p, const ObjectType& object)
41 {
42  return object.printTo(p);
43 }
44 
52 template <typename T> typename std::enable_if<!std::is_class<T>::value, size_t>::type print(Print& p, T value)
53 {
54  return p.print(value);
55 }
56 
64 template <typename T> size_t println(Print& p, const T& value)
65 {
66  size_t size = print(p, value);
67  size += p.println();
68  return size;
69 }
70 
71 } // namespace FSTR
72 
Provides formatted output to stream.
Definition: Print.h:37
size_t println()
Prints a newline to output stream.
Definition: Print.h:227
size_t print(char c)
Prints a single character to output stream.
Definition: Print.h:97
Definition: Array.hpp:108
size_t println(Print &p, const T &value)
Print an object or elementary variable appending a carriage return.
Definition: Print.hpp:64
std::enable_if< std::is_class< ObjectType >::value, size_t >::type print(Print &p, const ObjectType &object)
Print an object.
Definition: Print.hpp:40
ObjectType
Definition: Libraries/jerryscript/src/include/Jerryscript/Types.h:34