cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
options.cpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
11
12#include <algorithm>
13
14Term::Options::Options(const std::initializer_list<Term::Option>& option) : m_Options(option) { clean(); }
15
16bool Term::Options::operator==(const Options& options) { return m_Options == options.m_Options; }
17bool Term::Options::operator!=(const Options& options) { return !(m_Options == options.m_Options); }
18
20{
21 std::vector<Term::Option> cleaned;
22 std::sort(m_Options.begin(), m_Options.end());
23 while(!m_Options.empty())
24 {
25 const std::size_t count = std::count(m_Options.begin(), m_Options.end(), m_Options[0]);
26 const std::size_t anti_count = std::count(m_Options.begin(), m_Options.end(), static_cast<Term::Option>(-1 * static_cast<std::int16_t>(m_Options[0])));
27 if(count > anti_count) { cleaned.emplace_back(m_Options[0]); }
28 else if(count < anti_count) { cleaned.emplace_back(static_cast<Term::Option>(-1 * static_cast<std::int16_t>(m_Options[0]))); }
29 m_Options.erase(std::remove(m_Options.begin(), m_Options.end(), static_cast<Term::Option>(-1 * static_cast<std::int16_t>(m_Options[0]))), m_Options.end());
30 m_Options.erase(std::remove(m_Options.begin(), m_Options.end(), m_Options[0]), m_Options.end());
31 }
32 m_Options = cleaned;
33}
34
35bool Term::Options::has(const Option& option) const noexcept { return std::find(m_Options.begin(), m_Options.end(), option) != m_Options.end(); }
Options()=default
bool has(const Option &option) const noexcept
Definition options.cpp:35
void clean()
Definition options.cpp:19
std::vector< Term::Option > m_Options
Definition options.hpp:47
bool operator==(const Options &options)
Definition options.cpp:16
bool operator!=(const Options &options)
Definition options.cpp:17
Option
Option to set-up the terminal.
Definition options.hpp:23