1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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. *
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. *
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>
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
{ };
51 SongTag(MPD::Song::GetFunction function_
, unsigned delimiter_
= 0)
52 : m_function(function_
), m_delimiter(delimiter_
)
55 MPD::Song::GetFunction
function() const { return m_function
; }
56 unsigned delimiter() const { return m_delimiter
; }
59 MPD::Song::GetFunction m_function
;
63 enum class Result
{ Empty
, Missing
, Ok
};
65 template <typename CharT
>
66 using Expression
= boost::variant
<
67 std::basic_string
<CharT
>,
72 boost::recursive_wrapper
<FirstOf
<CharT
>>,
73 boost::recursive_wrapper
<Group
<CharT
>>
76 template <ListType Type
, typename CharT
>
79 typedef std::vector
<Expression
<CharT
>> Base
;
83 : m_base(std::move(base_
))
86 Base
&base() { return m_base
; }
87 const Base
&base() const { return 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