1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// SPDX-License-Identifier: LGPL-2.1-or-later
// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <brgl@bgdev.pl>
#include <iterator>
#include <ostream>
#include "internal.hpp"
namespace gpiod {
namespace line {
namespace {
const ::std::map<line::value, ::std::string> value_names = {
{ line::value::INACTIVE, "INACTIVE" },
{ line::value::ACTIVE, "ACTIVE" },
};
const ::std::map<line::direction, ::std::string> direction_names = {
{ line::direction::AS_IS, "AS_IS" },
{ line::direction::INPUT, "INPUT" },
{ line::direction::OUTPUT, "OUTPUT" },
};
const ::std::map<line::bias, ::std::string> bias_names = {
{ line::bias::AS_IS, "AS_IS" },
{ line::bias::UNKNOWN, "UNKNOWN" },
{ line::bias::DISABLED, "DISABLED" },
{ line::bias::PULL_UP, "PULL_UP" },
{ line::bias::PULL_DOWN, "PULL_DOWN" },
};
const ::std::map<line::drive, ::std::string> drive_names = {
{ line::drive::PUSH_PULL, "PUSH_PULL" },
{ line::drive::OPEN_DRAIN, "OPEN_DRAIN" },
{ line::drive::OPEN_SOURCE, "OPEN_SOURCE" },
};
const ::std::map<line::edge, ::std::string> edge_names = {
{ line::edge::NONE, "NONE" },
{ line::edge::RISING, "RISING_EDGE" },
{ line::edge::FALLING, "FALLING_EDGE" },
{ line::edge::BOTH, "BOTH_EDGES" },
};
const ::std::map<line::clock, ::std::string> clock_names = {
{ line::clock::MONOTONIC, "MONOTONIC" },
{ line::clock::REALTIME, "REALTIME" },
{ line::clock::HTE, "HTE" },
};
} /* namespace */
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, line::value val)
{
out << value_names.at(val);
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, line::direction dir)
{
out << direction_names.at(dir);
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, line::edge edge)
{
out << edge_names.at(edge);
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, line::bias bias)
{
out << bias_names.at(bias);
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, line::drive drive)
{
out << drive_names.at(drive);
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, line::clock clock)
{
out << clock_names.at(clock);
return out;
}
template<typename T>
::std::ostream& insert_vector(::std::ostream& out,
const ::std::string& name, const ::std::vector<T>& vec)
{
out << name << "(";
::std::copy(vec.begin(), ::std::prev(vec.end()),
::std::ostream_iterator<T>(out, ", "));
out << vec.back();
out << ")";
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const offsets& offs)
{
return insert_vector(out, "gpiod::offsets", offs);
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const line::values& vals)
{
return insert_vector(out, "gpiod::values", vals);
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const line::value_mapping& mapping)
{
out << "gpiod::value_mapping(" << mapping.first << ": " << mapping.second << ")";
return out;
}
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const line::value_mappings& mappings)
{
return insert_vector(out, "gpiod::value_mappings", mappings);
}
} /* namespace line */
} /* namespace gpiod */
|