Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libconfig
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
libconfig
Commits
db711b1e
Commit
db711b1e
authored
Dec 30, 2015
by
jltallon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #45 from jltallon/master
Implement float_precision parameter (Closes #31)
parents
462425bb
8471e3a6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
2 deletions
+76
-2
doc/libconfig.texi
doc/libconfig.texi
+29
-0
lib/libconfig.c
lib/libconfig.c
+25
-1
lib/libconfig.h
lib/libconfig.h
+5
-1
lib/libconfig.h++
lib/libconfig.h++
+3
-0
lib/libconfigcpp.c++
lib/libconfigcpp.c++
+14
-0
No files found.
doc/libconfig.texi
View file @
db711b1e
...
...
@@ -824,6 +824,22 @@ configuration @var{config}, or @code{NULL} if none is set.
@end deftypefun
@deftypefun void config
_
set
_
float
_
precision(@w
{
config
_
t *@var
{
config
}}
, @w
{
unsigned short @var
{
digits
}}
)
@deftypefunx
{
unsigned short
}
config
_
get
_
float
_
precision(@w
{
config
_
t *@var
{
config
}}
)
@b
{
Since @i
{
v1.6
}}
These functions set and get the number of decimal digits to output when writing
the configuration to a file or stream.
@code
{
config
_
set
_
float
_
precision(config,digits)
}
specifies "the number of
digits to appear after the radix character". Please refer to printf(3) for details.
Valid float precision range from 0 (no decimals) to about 15 (implementation defined).
This parameter has no effect on parsing.
@end deftypefun
@deftypefun void config
_
set
_
options (@w
{
config
_
t *@var
{
config
}}
, @w
{
int @var
{
options
}}
)
@deftypefunx int config
_
get
_
options (@w
{
config
_
t *@var
{
config
}}
)
...
...
@@ -1465,6 +1481,19 @@ Valid tab widths range from 0 to 15. The default tab width is 2.
@end deftypemethod
@deftypemethod Config void setFloatPrecision (@w
{
unsigned short @var
{
width
}}
)
@deftypemethodx Config
{
unsigned short
}
getFloatPrecision ()
These methods set and get the float precision for the configuration.
This parameter influences the formatting of floating point settings in
the configuration when it is written to a file or stream.
Float precision has no effect on parsing.
Valid precisions range from 0 to about 15 (implementation dependent),
though the library will accept and store values up to 255.
@end deftypemethod
@deftypemethod Config
{
Setting
&}
getRoot ()
This method returns the root setting for the configuration, which is a group.
...
...
lib/libconfig.c
View file @
db711b1e
...
...
@@ -49,6 +49,9 @@
#define CHUNK_SIZE 16
#define FLOAT_PRECISION DBL_DIG
#define TAB2DIGITS(x) (((x) & 0xFF00) >> 8)
#define DIGITS2TAB(x) (((x) & 0xFF) << 8)
#define _new(T) (T *)calloc(1, sizeof(T))
/* zeroed */
#define _delete(P) free((void *)(P))
...
...
@@ -218,7 +221,10 @@ static void __config_write_value(const config_t *config,
{
char
*
q
;
snprintf
(
fbuf
,
sizeof
(
fbuf
)
-
3
,
"%.*g"
,
FLOAT_PRECISION
,
value
->
fval
);
snprintf
(
fbuf
,
sizeof
(
fbuf
)
-
3
,
"%.*f"
,
TAB2DIGITS
(
config
->
tab_width
),
/* XXX: hack; See config_set_float_precision */
value
->
fval
);
/* check for exponent */
q
=
strchr
(
fbuf
,
'e'
);
...
...
@@ -751,6 +757,18 @@ void config_destroy(config_t *config)
memset
((
void
*
)
config
,
0
,
sizeof
(
config_t
));
}
/* ------------------------------------------------------------------------- */
void
config_set_float_precision
(
config_t
*
config
,
unsigned
short
digits
)
{
config
->
tab_width
|=
DIGITS2TAB
(
digits
);
}
unsigned
short
config_get_float_precision
(
config_t
*
config
)
{
return
TAB2DIGITS
(
config
->
tab_width
);
}
/* ------------------------------------------------------------------------- */
void
config_init
(
config_t
*
config
)
...
...
@@ -763,7 +781,13 @@ void config_init(config_t *config)
config
->
options
=
(
CONFIG_OPTION_SEMICOLON_SEPARATORS
|
CONFIG_OPTION_COLON_ASSIGNMENT_FOR_GROUPS
|
CONFIG_OPTION_OPEN_BRACE_ON_SEPARATE_LINE
);
/* @version 1.6: piggyback float_digits on top of tab_width
* (ab)using the existing macros' 0x0F mask in order to preserve
* API & ABI compatibility ; changes are fully backwards compatible
*/
config
->
tab_width
=
2
;
config
->
tab_width
|=
DIGITS2TAB
(
FLOAT_PRECISION
);
/* float_digits */
}
/* ------------------------------------------------------------------------- */
...
...
lib/libconfig.h
View file @
db711b1e
...
...
@@ -142,6 +142,10 @@ extern LIBCONFIG_API void config_set_destructor(config_t *config,
extern
LIBCONFIG_API
void
config_set_include_dir
(
config_t
*
config
,
const
char
*
include_dir
);
extern
LIBCONFIG_API
void
config_set_float_precision
(
config_t
*
config
,
unsigned
short
digits
);
extern
LIBCONFIG_API
unsigned
short
config_get_float_precision
(
config_t
*
config
);
extern
LIBCONFIG_API
void
config_init
(
config_t
*
config
);
extern
LIBCONFIG_API
void
config_destroy
(
config_t
*
config
);
...
...
@@ -299,7 +303,7 @@ extern LIBCONFIG_API int config_lookup_string(const config_t *config,
(C)->tab_width = ((W) & 0x0F)
#define
/* unsigned char */
config_get_tab_width(
/* const config_t * */
C) \
((C)->tab_width)
((C)->tab_width
& 0x0F
)
#define
/* unsigned short */
config_setting_source_line( \
/* const config_setting_t * */
S) \
...
...
lib/libconfig.h++
View file @
db711b1e
...
...
@@ -466,6 +466,9 @@ class LIBCONFIGXX_API Config
void
setTabWidth
(
unsigned
short
width
);
unsigned
short
getTabWidth
()
const
;
void
setFloatPrecision
(
unsigned
short
digits
);
unsigned
short
getFloatPrecision
()
const
;
void
setIncludeDir
(
const
char
*
includeDir
);
const
char
*
getIncludeDir
()
const
;
...
...
lib/libconfigcpp.c++
View file @
db711b1e
...
...
@@ -374,6 +374,20 @@ unsigned short Config::getTabWidth() const
// ---------------------------------------------------------------------------
void
Config
::
setFloatPrecision
(
unsigned
short
digits
)
{
return
(
config_set_float_precision
(
_config
,
digits
));
}
// ---------------------------------------------------------------------------
unsigned
short
Config
::
getFloatPrecision
()
const
{
return
(
config_get_float_precision
(
_config
));
}
// ---------------------------------------------------------------------------
void
Config
::
setIncludeDir
(
const
char
*
includeDir
)
{
config_set_include_dir
(
_config
,
includeDir
);
...
...
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