Config: reformat all descriptions to fill 80 columns
[ncmpcpp.git] / src / format.h
blob06001efe1a708db59c93137acd447c627c352ebe
1 /***************************************************************************
2 * Copyright (C) 2008-2017 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_HAVE_FORMAT_H
22 #define NCMPCPP_HAVE_FORMAT_H
24 #include <boost/variant.hpp>
26 #include "curses/menu.h"
27 #include "song.h"
29 namespace Format {
31 namespace Flags {
32 const unsigned None = 0;
33 const unsigned Color = 1;
34 const unsigned Format = 2;
35 const unsigned OutputSwitch = 4;
36 const unsigned Tag = 8;
37 const unsigned All = Color | Format | OutputSwitch | Tag;
40 enum class ListType { Group, FirstOf, AST };
42 template <ListType, typename> struct List;
43 template <typename CharT> using Group = List<ListType::Group, CharT>;
44 template <typename CharT> using FirstOf = List<ListType::FirstOf, CharT>;
45 template <typename CharT> using AST = List<ListType::AST, CharT>;
47 struct OutputSwitch { };
49 struct SongTag
51 SongTag(MPD::Song::GetFunction function_, unsigned delimiter_ = 0)
52 : m_function(function_), m_delimiter(delimiter_)
53 { }
55 MPD::Song::GetFunction function() const { return m_function; }
56 unsigned delimiter() const { return m_delimiter; }
58 private:
59 MPD::Song::GetFunction m_function;
60 unsigned m_delimiter;
63 template <typename CharT> using SongTagMap = std::vector<
64 std::pair<SongTag, std::basic_string<CharT> >
67 enum class Result { Empty, Missing, Ok };
69 template <typename CharT>
70 using Expression = boost::variant<
71 std::basic_string<CharT>,
72 NC::Color,
73 NC::Format,
74 OutputSwitch,
75 SongTag,
76 boost::recursive_wrapper<FirstOf<CharT>>,
77 boost::recursive_wrapper<Group<CharT>>
80 template <ListType Type, typename CharT>
81 struct List
83 typedef std::vector<Expression<CharT>> Base;
85 List() { }
86 List(Base &&base_)
87 : m_base(std::move(base_))
88 { }
90 Base &base() { return m_base; }
91 const Base &base() const { return m_base; }
93 private:
94 Base m_base;
97 template <typename CharT, typename VisitorT>
98 void visit(VisitorT &visitor, const AST<CharT> &ast);
100 template <typename CharT, typename ItemT>
101 void print(const AST<CharT> &ast, NC::Menu<ItemT> &menu, const MPD::Song *song,
102 NC::BasicBuffer<CharT> *buffer, const unsigned flags = Flags::All);
104 template <typename CharT>
105 void print(const AST<CharT> &ast, NC::BasicBuffer<CharT> &buffer,
106 const MPD::Song *song, const unsigned flags = Flags::All);
108 template <typename CharT>
109 std::basic_string<CharT> stringify(const AST<CharT> &ast, const MPD::Song *song);
111 AST<char> parse(const std::string &s, const unsigned flags = Flags::All);
112 AST<wchar_t> parse(const std::wstring &ws, const unsigned flags = Flags::All);
116 #endif // NCMPCPP_HAVE_FORMAT_H