MPD: config/Block.hxx Source File

MPD 0.20.18

Block.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_CONFIG_BLOCK_HXX
21 #define MPD_CONFIG_BLOCK_HXX
22
23 #include "check.h"
24 #include "Param.hxx"
25 #include "Compiler.h"
26
27 #include <string>
28 #include <vector>
29
30 class AllocatedPath;
31
32 struct BlockParam {
33 std::string name;
34 std::string value;
35 int line;
36
41 mutable bool used;
42
43 gcc_nonnull_all
44 BlockParam(const char *_name, const char *_value, int _line=-1)
45 :name(_name), value(_value), line(_line), used(false) {}
46
47 int GetIntValue() const;
48
49 unsigned GetUnsignedValue() const;
50
51 bool GetBoolValue() const;
52 };
53
54 struct ConfigBlock {
59 ConfigBlock *next;
60
61 int line;
62
63 std::vector<BlockParam> block_params;
64
69 bool used;
70
71 explicit ConfigBlock(int _line=-1)
72 :next(nullptr), line(_line), used(false) {}
73
74 ConfigBlock(const ConfigBlock &) = delete;
75
76 ~ConfigBlock();
77
78 ConfigBlock &operator=(const ConfigBlock &) = delete;
79
85 bool IsNull() const noexcept {
86 return line < 0;
87 }
88
89 gcc_pure
90 bool IsEmpty() const noexcept {
91 return block_params.empty();
92 }
93
94 gcc_nonnull_all
95 void AddBlockParam(const char *_name, const char *_value,
96 int _line=-1) {
97 block_params.emplace_back(_name, _value, _line);
98 }
99
100 gcc_nonnull_all gcc_pure
101 const BlockParam *GetBlockParam(const char *_name) const noexcept;
102
103 gcc_pure
104 const char *GetBlockValue(const char *name,
105 const char *default_value=nullptr) const noexcept;
106
113 AllocatedPath GetPath(const char *name,
114 const char *default_value=nullptr) const;
115
116 int GetBlockValue(const char *name, int default_value) const;
117
118 unsigned GetBlockValue(const char *name, unsigned default_value) const;
119
120 bool GetBlockValue(const char *name, bool default_value) const;
121 };
122
123 #endif
BlockParam::name
std::string name
Definition: Block.hxx:33
check.h
gcc_nonnull_all
#define gcc_nonnull_all
Definition: Compiler.h:122
BlockParam::GetIntValue
int GetIntValue() const
BlockParam::GetBoolValue
bool GetBoolValue() const
Param.hxx
AllocatedPath
A path name in the native file system character set.
Definition: AllocatedPath.hxx:38
BlockParam::BlockParam
gcc_nonnull_all BlockParam(const char *_name, const char *_value, int _line=-1)
Definition: Block.hxx:44
ConfigBlock::next
ConfigBlock * next
The next ConfigBlock with the same name.
Definition: Block.hxx:59
ConfigBlock::AddBlockParam
gcc_nonnull_all void AddBlockParam(const char *_name, const char *_value, int _line=-1)
Definition: Block.hxx:95
ConfigBlock::used
bool used
This flag is false when nobody has queried the value of this option yet.
Definition: Block.hxx:69
BlockParam::value
std::string value
Definition: Block.hxx:34
ConfigBlock
Definition: Block.hxx:54
ConfigBlock::GetBlockValue
gcc_pure const char * GetBlockValue(const char *name, const char *default_value=nullptr) const noexcept
Compiler.h
ConfigBlock::IsEmpty
gcc_pure bool IsEmpty() const noexcept
Definition: Block.hxx:90
ConfigBlock::line
int line
Definition: Block.hxx:61
ConfigBlock::operator=
ConfigBlock & operator=(const ConfigBlock &)=delete
BlockParam::GetUnsignedValue
unsigned GetUnsignedValue() const
ConfigBlock::ConfigBlock
ConfigBlock(int _line=-1)
Definition: Block.hxx:71
ConfigBlock::~ConfigBlock
~ConfigBlock()
BlockParam::used
bool used
This flag is false when nobody has queried the value of this option yet.
Definition: Block.hxx:41
ConfigBlock::GetPath
AllocatedPath GetPath(const char *name, const char *default_value=nullptr) const
Same as config_get_path(), but looks up the setting in the specified block.
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
BlockParam::line
int line
Definition: Block.hxx:35
BlockParam
Definition: Block.hxx:32
ConfigBlock::GetBlockParam
gcc_nonnull_all gcc_pure const BlockParam * GetBlockParam(const char *_name) const noexcept
ConfigBlock::IsNull
bool IsNull() const noexcept
Determine if this is a "null" instance, i.e.
Definition: Block.hxx:85
ConfigBlock::block_params
std::vector< BlockParam > block_params
Definition: Block.hxx:63
name
const Partition const char * name
Definition: Count.hxx:34