Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
Format.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * Format.h
17 * Formatting functions for basic types.
18 * Copyright (C) 2005 Simon Newton
19 */
20
26#ifndef INCLUDE_OLA_STRINGS_FORMAT_H_
27#define INCLUDE_OLA_STRINGS_FORMAT_H_
28
29#include <stdint.h>
31#include <iomanip>
32#include <iostream>
33#include <limits>
34#include <ostream>
35#include <sstream>
36#include <string>
37
38namespace ola {
39namespace strings {
40
46std::string IntToString(int i);
47
53std::string IntToString(unsigned int i);
54
67template<typename T>
68_ToHex<T> ToHex(T v, bool prefix = true) {
69 return _ToHex<T>(v, (std::numeric_limits<T>::digits / HEX_BIT_WIDTH), prefix);
70}
71
75template <typename T>
76std::ostream& operator<<(std::ostream &out, const ola::strings::_ToHex<T> &i) {
77 std::ios::fmtflags flags(out.flags()); // Store the current format flags
78 // In C++, you only get the 0x on non-zero values, so we have to explicitly
79 // add it for all values if we want it
80 if (i.prefix) {
81 out << "0x";
82 }
83 out << std::setw(i.width) << std::hex << std::setfill('0')
84 << ola::strings::_HexCast(i.value);
85 out.flags(flags); // Put the format flags back to normal
86 return out;
87}
88
101void FormatData(std::ostream *out,
102 const uint8_t *data,
103 unsigned int length,
104 unsigned int indent = 0,
105 unsigned int byte_per_line = 8);
106} // namespace strings
107} // namespace ola
108#endif // INCLUDE_OLA_STRINGS_FORMAT_H_
Private implementations of the formatting functions from Format.h.
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
Definition FormatPrivate.h:46