change version to 0.7.3
[ncmpcpp.git] / src / format.h
blob17cf23e06c539ca6dcef090f15032c73c96cbbb7
1 /***************************************************************************
2 * Copyright (C) 2008-2014 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 "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 enum class Result { Empty, Missing, Ok };
65 template <typename CharT>
66 using Expression = boost::variant<
67 std::basic_string<CharT>,
68 NC::Color,
69 NC::Format,
70 OutputSwitch,
71 SongTag,
72 boost::recursive_wrapper<FirstOf<CharT>>,
73 boost::recursive_wrapper<Group<CharT>>
76 template <ListType Type, typename CharT>
77 struct List
79 typedef std::vector<Expression<CharT>> Base;
81 List() { }
82 List(Base &&base_)
83 : m_base(std::move(base_))
84 { }
86 Base &base() { return m_base; }
87 const Base &base() const { return m_base; }
89 private:
90 Base m_base;
93 template <typename CharT, typename VisitorT>
94 void visit(VisitorT &visitor, const AST<CharT> &ast);
96 template <typename CharT, typename ItemT>
97 void print(const AST<CharT> &ast, NC::Menu<ItemT> &menu, const MPD::Song *song,
98 NC::BasicBuffer<CharT> *buffer, const unsigned flags = Flags::All);
100 template <typename CharT>
101 void print(const AST<CharT> &ast, NC::BasicBuffer<CharT> &buffer,
102 const MPD::Song *song, const unsigned flags = Flags::All);
104 template <typename CharT>
105 std::basic_string<CharT> stringify(const AST<CharT> &ast, const MPD::Song *song);
107 AST<char> parse(const std::string &s, const unsigned flags = Flags::All);
108 AST<wchar_t> parse(const std::wstring &ws, const unsigned flags = Flags::All);
112 #endif // NCMPCPP_HAVE_FORMAT_H