Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
8df98932
Commit
8df98932
authored
Jul 18, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/Data: add methods AddParam(), AddBlock()
parent
95481dda
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
52 deletions
+66
-52
Data.cxx
src/config/Data.cxx
+40
-0
Data.hxx
src/config/Data.hxx
+7
-0
File.cxx
src/config/File.cxx
+19
-52
No files found.
src/config/Data.cxx
View file @
8df98932
...
...
@@ -42,6 +42,26 @@ ConfigData::Clear()
}
}
gcc_nonnull_all
static
void
Append
(
ConfigParam
*&
head
,
ConfigParam
*
p
)
{
assert
(
p
->
next
==
nullptr
);
auto
**
i
=
&
head
;
while
(
*
i
!=
nullptr
)
i
=
&
(
*
i
)
->
next
;
*
i
=
p
;
}
void
ConfigData
::
AddParam
(
ConfigOption
option
,
std
::
unique_ptr
<
ConfigParam
>
param
)
noexcept
{
Append
(
params
[
size_t
(
option
)],
param
.
release
());
}
const
char
*
ConfigData
::
GetString
(
ConfigOption
option
,
const
char
*
default_value
)
const
noexcept
...
...
@@ -123,6 +143,26 @@ ConfigData::GetBool(ConfigOption option, bool default_value) const
return
value
;
}
gcc_nonnull_all
static
void
Append
(
ConfigBlock
*&
head
,
ConfigBlock
*
p
)
{
assert
(
p
->
next
==
nullptr
);
auto
**
i
=
&
head
;
while
(
*
i
!=
nullptr
)
i
=
&
(
*
i
)
->
next
;
*
i
=
p
;
}
void
ConfigData
::
AddBlock
(
ConfigBlockOption
option
,
std
::
unique_ptr
<
ConfigBlock
>
block
)
noexcept
{
Append
(
blocks
[
size_t
(
option
)],
block
.
release
());
}
const
ConfigBlock
*
ConfigData
::
FindBlock
(
ConfigBlockOption
option
,
const
char
*
key
,
const
char
*
value
)
const
...
...
src/config/Data.hxx
View file @
8df98932
...
...
@@ -24,6 +24,7 @@
#include <array>
#include <chrono>
#include <memory>
struct
ConfigParam
;
struct
ConfigBlock
;
...
...
@@ -35,6 +36,9 @@ struct ConfigData {
void
Clear
();
void
AddParam
(
ConfigOption
option
,
std
::
unique_ptr
<
ConfigParam
>
param
)
noexcept
;
gcc_pure
const
ConfigParam
*
GetParam
(
ConfigOption
option
)
const
noexcept
{
return
params
[
size_t
(
option
)];
...
...
@@ -77,6 +81,9 @@ struct ConfigData {
bool
GetBool
(
ConfigOption
option
,
bool
default_value
)
const
;
void
AddBlock
(
ConfigBlockOption
option
,
std
::
unique_ptr
<
ConfigBlock
>
block
)
noexcept
;
gcc_pure
const
ConfigBlock
*
GetBlock
(
ConfigBlockOption
option
)
const
noexcept
{
return
blocks
[
size_t
(
option
)];
...
...
src/config/File.cxx
View file @
8df98932
...
...
@@ -74,7 +74,7 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
block
.
AddBlockParam
(
name
,
std
::
move
(
value
),
line
);
}
static
ConfigBlock
*
static
std
::
unique_ptr
<
ConfigBlock
>
config_read_block
(
BufferedReader
&
reader
)
{
std
::
unique_ptr
<
ConfigBlock
>
block
(
new
ConfigBlock
(
reader
.
GetLineNumber
()));
...
...
@@ -96,7 +96,7 @@ config_read_block(BufferedReader &reader)
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after '}'"
);
return
block
.
release
()
;
return
block
;
}
/* parse name and value */
...
...
@@ -106,19 +106,6 @@ config_read_block(BufferedReader &reader)
}
}
gcc_nonnull_all
static
void
Append
(
ConfigBlock
*&
head
,
ConfigBlock
*
p
)
{
assert
(
p
->
next
==
nullptr
);
auto
**
i
=
&
head
;
while
(
*
i
!=
nullptr
)
i
=
&
(
*
i
)
->
next
;
*
i
=
p
;
}
static
void
ReadConfigBlock
(
ConfigData
&
config_data
,
BufferedReader
&
reader
,
const
char
*
name
,
ConfigBlockOption
o
,
...
...
@@ -126,15 +113,13 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
{
const
unsigned
i
=
unsigned
(
o
);
const
ConfigTemplate
&
option
=
config_block_templates
[
i
];
ConfigBlock
*&
head
=
config_data
.
blocks
[
i
];
if
(
head
!=
nullptr
&&
!
option
.
repeatable
)
{
ConfigBlock
*
block
=
head
;
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
"on line %d and redefined on line %u
\n
"
,
name
,
block
->
line
,
reader
.
GetLineNumber
());
}
if
(
!
option
.
repeatable
)
if
(
const
auto
*
block
=
config_data
.
GetBlock
(
o
))
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
"on line %d and redefined on line %u
\n
"
,
name
,
block
->
line
,
reader
.
GetLineNumber
());
/* now parse the block or the value */
...
...
@@ -145,22 +130,7 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after '{'"
);
auto
*
param
=
config_read_block
(
reader
);
assert
(
param
!=
nullptr
);
Append
(
head
,
param
);
}
gcc_nonnull_all
static
void
Append
(
ConfigParam
*&
head
,
ConfigParam
*
p
)
{
assert
(
p
->
next
==
nullptr
);
auto
**
i
=
&
head
;
while
(
*
i
!=
nullptr
)
i
=
&
(
*
i
)
->
next
;
*
i
=
p
;
config_data
.
AddBlock
(
o
,
config_read_block
(
reader
));
}
static
void
...
...
@@ -170,21 +140,18 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
{
const
unsigned
i
=
unsigned
(
o
);
const
ConfigTemplate
&
option
=
config_param_templates
[
i
];
auto
*&
head
=
config_data
.
params
[
i
];
if
(
head
!=
nullptr
&&
!
option
.
repeatable
)
{
auto
*
param
=
head
;
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
"on line %d and redefined on line %u
\n
"
,
name
,
param
->
line
,
reader
.
GetLineNumber
());
}
if
(
!
option
.
repeatable
)
if
(
const
auto
*
param
=
config_data
.
GetParam
(
o
))
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
"on line %d and redefined on line %u
\n
"
,
name
,
param
->
line
,
reader
.
GetLineNumber
());
/* now parse the block or the value */
auto
*
param
=
new
ConfigParam
(
ExpectValueAndEnd
(
tokenizer
),
reader
.
GetLineNumber
());
Append
(
head
,
param
);
config_data
.
AddParam
(
o
,
std
::
make_unique
<
ConfigParam
>
(
ExpectValueAndEnd
(
tokenizer
),
reader
.
GetLineNumber
()));
}
static
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment