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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
42 deletions
+56
-42
Data.cxx
src/config/Data.cxx
+40
-0
Data.hxx
src/config/Data.hxx
+7
-0
File.cxx
src/config/File.cxx
+9
-42
No files found.
src/config/Data.cxx
View file @
8df98932
...
@@ -42,6 +42,26 @@ ConfigData::Clear()
...
@@ -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
*
const
char
*
ConfigData
::
GetString
(
ConfigOption
option
,
ConfigData
::
GetString
(
ConfigOption
option
,
const
char
*
default_value
)
const
noexcept
const
char
*
default_value
)
const
noexcept
...
@@ -123,6 +143,26 @@ ConfigData::GetBool(ConfigOption option, bool default_value) const
...
@@ -123,6 +143,26 @@ ConfigData::GetBool(ConfigOption option, bool default_value) const
return
value
;
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
*
const
ConfigBlock
*
ConfigData
::
FindBlock
(
ConfigBlockOption
option
,
ConfigData
::
FindBlock
(
ConfigBlockOption
option
,
const
char
*
key
,
const
char
*
value
)
const
const
char
*
key
,
const
char
*
value
)
const
...
...
src/config/Data.hxx
View file @
8df98932
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include <array>
#include <array>
#include <chrono>
#include <chrono>
#include <memory>
struct
ConfigParam
;
struct
ConfigParam
;
struct
ConfigBlock
;
struct
ConfigBlock
;
...
@@ -35,6 +36,9 @@ struct ConfigData {
...
@@ -35,6 +36,9 @@ struct ConfigData {
void
Clear
();
void
Clear
();
void
AddParam
(
ConfigOption
option
,
std
::
unique_ptr
<
ConfigParam
>
param
)
noexcept
;
gcc_pure
gcc_pure
const
ConfigParam
*
GetParam
(
ConfigOption
option
)
const
noexcept
{
const
ConfigParam
*
GetParam
(
ConfigOption
option
)
const
noexcept
{
return
params
[
size_t
(
option
)];
return
params
[
size_t
(
option
)];
...
@@ -77,6 +81,9 @@ struct ConfigData {
...
@@ -77,6 +81,9 @@ struct ConfigData {
bool
GetBool
(
ConfigOption
option
,
bool
default_value
)
const
;
bool
GetBool
(
ConfigOption
option
,
bool
default_value
)
const
;
void
AddBlock
(
ConfigBlockOption
option
,
std
::
unique_ptr
<
ConfigBlock
>
block
)
noexcept
;
gcc_pure
gcc_pure
const
ConfigBlock
*
GetBlock
(
ConfigBlockOption
option
)
const
noexcept
{
const
ConfigBlock
*
GetBlock
(
ConfigBlockOption
option
)
const
noexcept
{
return
blocks
[
size_t
(
option
)];
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)
...
@@ -74,7 +74,7 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
block
.
AddBlockParam
(
name
,
std
::
move
(
value
),
line
);
block
.
AddBlockParam
(
name
,
std
::
move
(
value
),
line
);
}
}
static
ConfigBlock
*
static
std
::
unique_ptr
<
ConfigBlock
>
config_read_block
(
BufferedReader
&
reader
)
config_read_block
(
BufferedReader
&
reader
)
{
{
std
::
unique_ptr
<
ConfigBlock
>
block
(
new
ConfigBlock
(
reader
.
GetLineNumber
()));
std
::
unique_ptr
<
ConfigBlock
>
block
(
new
ConfigBlock
(
reader
.
GetLineNumber
()));
...
@@ -96,7 +96,7 @@ config_read_block(BufferedReader &reader)
...
@@ -96,7 +96,7 @@ config_read_block(BufferedReader &reader)
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after '}'"
);
throw
std
::
runtime_error
(
"Unknown tokens after '}'"
);
return
block
.
release
()
;
return
block
;
}
}
/* parse name and value */
/* parse name and value */
...
@@ -106,19 +106,6 @@ config_read_block(BufferedReader &reader)
...
@@ -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
static
void
ReadConfigBlock
(
ConfigData
&
config_data
,
BufferedReader
&
reader
,
ReadConfigBlock
(
ConfigData
&
config_data
,
BufferedReader
&
reader
,
const
char
*
name
,
ConfigBlockOption
o
,
const
char
*
name
,
ConfigBlockOption
o
,
...
@@ -126,15 +113,13 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
...
@@ -126,15 +113,13 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
{
{
const
unsigned
i
=
unsigned
(
o
);
const
unsigned
i
=
unsigned
(
o
);
const
ConfigTemplate
&
option
=
config_block_templates
[
i
];
const
ConfigTemplate
&
option
=
config_block_templates
[
i
];
ConfigBlock
*&
head
=
config_data
.
blocks
[
i
];
if
(
head
!=
nullptr
&&
!
option
.
repeatable
)
{
if
(
!
option
.
repeatable
)
ConfigBlock
*
block
=
head
;
if
(
const
auto
*
block
=
config_data
.
GetBlock
(
o
))
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
"on line %d and redefined on line %u
\n
"
,
"on line %d and redefined on line %u
\n
"
,
name
,
block
->
line
,
name
,
block
->
line
,
reader
.
GetLineNumber
());
reader
.
GetLineNumber
());
}
/* now parse the block or the value */
/* now parse the block or the value */
...
@@ -145,22 +130,7 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
...
@@ -145,22 +130,7 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after '{'"
);
throw
std
::
runtime_error
(
"Unknown tokens after '{'"
);
auto
*
param
=
config_read_block
(
reader
);
config_data
.
AddBlock
(
o
,
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
;
}
}
static
void
static
void
...
@@ -170,21 +140,18 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
...
@@ -170,21 +140,18 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
{
{
const
unsigned
i
=
unsigned
(
o
);
const
unsigned
i
=
unsigned
(
o
);
const
ConfigTemplate
&
option
=
config_param_templates
[
i
];
const
ConfigTemplate
&
option
=
config_param_templates
[
i
];
auto
*&
head
=
config_data
.
params
[
i
];
if
(
head
!=
nullptr
&&
!
option
.
repeatable
)
{
if
(
!
option
.
repeatable
)
auto
*
param
=
head
;
if
(
const
auto
*
param
=
config_data
.
GetParam
(
o
))
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
throw
FormatRuntimeError
(
"config parameter
\"
%s
\"
is first defined "
"on line %d and redefined on line %u
\n
"
,
"on line %d and redefined on line %u
\n
"
,
name
,
param
->
line
,
name
,
param
->
line
,
reader
.
GetLineNumber
());
reader
.
GetLineNumber
());
}
/* now parse the block or the value */
/* now parse the block or the value */
auto
*
param
=
new
ConfigParam
(
ExpectValueAndEnd
(
tokenizer
),
config_data
.
AddParam
(
o
,
std
::
make_unique
<
ConfigParam
>
(
ExpectValueAndEnd
(
tokenizer
),
reader
.
GetLineNumber
());
reader
.
GetLineNumber
()));
Append
(
head
,
param
);
}
}
static
void
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