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
|
/***************************************************************************
* Copyright (C) 2008-2014 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef NCMPCPP_HAVE_FORMAT_H
#define NCMPCPP_HAVE_FORMAT_H
#include <boost/variant.hpp>
#include "menu.h"
#include "song.h"
namespace Format {
namespace Flags {
const unsigned None = 0;
const unsigned Color = 1;
const unsigned Format = 2;
const unsigned OutputSwitch = 4;
const unsigned Tag = 8;
const unsigned All = Color | Format | OutputSwitch | Tag;
}
enum class ListType { Group, FirstOf, AST };
template <ListType, typename> struct List;
template <typename CharT> using Group = List<ListType::Group, CharT>;
template <typename CharT> using FirstOf = List<ListType::FirstOf, CharT>;
template <typename CharT> using AST = List<ListType::AST, CharT>;
struct OutputSwitch { };
struct SongTag
{
SongTag(MPD::Song::GetFunction function_, unsigned delimiter_ = 0)
: m_function(function_), m_delimiter(delimiter_)
{ }
MPD::Song::GetFunction function() const { return m_function; }
unsigned delimiter() const { return m_delimiter; }
private:
MPD::Song::GetFunction m_function;
unsigned m_delimiter;
};
enum class Result { Empty, Missing, Ok };
template <typename CharT>
using Expression = boost::variant<
std::basic_string<CharT>,
NC::Color,
NC::Format,
OutputSwitch,
SongTag,
boost::recursive_wrapper<FirstOf<CharT>>,
boost::recursive_wrapper<Group<CharT>>
>;
template <ListType Type, typename CharT>
struct List
{
typedef std::vector<Expression<CharT>> Base;
List() { }
List(Base &&base_)
: m_base(std::move(base_))
{ }
Base &base() { return m_base; }
const Base &base() const { return m_base; }
private:
Base m_base;
};
template <typename CharT, typename VisitorT>
void visit(VisitorT &visitor, const AST<CharT> &ast);
template <typename CharT, typename ItemT>
void print(const AST<CharT> &ast, NC::Menu<ItemT> &menu, const MPD::Song *song,
NC::BasicBuffer<CharT> *buffer, const unsigned flags = Flags::All);
template <typename CharT>
void print(const AST<CharT> &ast, NC::BasicBuffer<CharT> &buffer,
const MPD::Song *song, const unsigned flags = Flags::All);
template <typename CharT>
std::basic_string<CharT> stringify(const AST<CharT> &ast, const MPD::Song *song);
AST<char> parse(const std::string &s, const unsigned flags = Flags::All);
AST<wchar_t> parse(const std::wstring &ws, const unsigned flags = Flags::All);
}
#endif // NCMPCPP_HAVE_FORMAT_H
|