MPD  0.20.6
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 
44  BlockParam(const char *_name, const char *_value, int _line=-1)
45  :name(_name), value(_value), line(_line), used(false) {}
46 
47  gcc_pure
48  int GetIntValue() const;
49 
50  gcc_pure
51  unsigned GetUnsignedValue() const;
52 
53  gcc_pure
54  bool GetBoolValue() const;
55 };
56 
57 struct ConfigBlock {
63 
64  int line;
65 
66  std::vector<BlockParam> block_params;
67 
72  bool used;
73 
74  explicit ConfigBlock(int _line=-1)
75  :next(nullptr), line(_line), used(false) {}
76 
77  ConfigBlock(const ConfigBlock &) = delete;
78 
79  ~ConfigBlock();
80 
81  ConfigBlock &operator=(const ConfigBlock &) = delete;
82 
88  bool IsNull() const {
89  return line < 0;
90  }
91 
92  gcc_pure
93  bool IsEmpty() const {
94  return block_params.empty();
95  }
96 
98  void AddBlockParam(const char *_name, const char *_value,
99  int _line=-1) {
100  block_params.emplace_back(_name, _value, _line);
101  }
102 
104  const BlockParam *GetBlockParam(const char *_name) const;
105 
106  gcc_pure
107  const char *GetBlockValue(const char *name,
108  const char *default_value=nullptr) const;
109 
116  AllocatedPath GetPath(const char *name,
117  const char *default_value=nullptr) const;
118 
119  gcc_pure
120  int GetBlockValue(const char *name, int default_value) const;
121 
122  gcc_pure
123  unsigned GetBlockValue(const char *name, unsigned default_value) const;
124 
125  gcc_pure
126  bool GetBlockValue(const char *name, bool default_value) const;
127 };
128 
129 #endif
std::string name
Definition: Block.hxx:33
#define gcc_nonnull_all
Definition: Compiler.h:122
gcc_nonnull_all gcc_pure const BlockParam * GetBlockParam(const char *_name) const
A path name in the native file system character set.
gcc_nonnull_all BlockParam(const char *_name, const char *_value, int _line=-1)
Definition: Block.hxx:44
gcc_pure bool GetBoolValue() const
ConfigBlock * next
The next ConfigBlock with the same name.
Definition: Block.hxx:62
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_nonnull_all void AddBlockParam(const char *_name, const char *_value, int _line=-1)
Definition: Block.hxx:98
bool used
This flag is false when nobody has queried the value of this option yet.
Definition: Block.hxx:72
std::string value
Definition: Block.hxx:34
int line
Definition: Block.hxx:64
gcc_pure int GetIntValue() const
ConfigBlock & operator=(const ConfigBlock &)=delete
bool IsNull() const
Determine if this is a "null" instance, i.e.
Definition: Block.hxx:88
ConfigBlock(int _line=-1)
Definition: Block.hxx:74
gcc_pure const char * GetBlockValue(const char *name, const char *default_value=nullptr) const
gcc_pure bool IsEmpty() const
Definition: Block.hxx:93
bool used
This flag is false when nobody has queried the value of this option yet.
Definition: Block.hxx:41
gcc_pure unsigned GetUnsignedValue() const
#define gcc_pure
Definition: Compiler.h:116
int line
Definition: Block.hxx:35
std::vector< BlockParam > block_params
Definition: Block.hxx:66
const Partition const char * name
Definition: Count.hxx:34