Projects / libconfigduo / Comments

Comments for libconfigduo

08 Oct 2010 18:29 jabbyknob

I'm writing a configuration manipulation layer over libconfig, and I need to allow users to replace items in a list with arbitrary simple types. For example:

change this:
foo = (1, 2, 3);

to this:
foo = (1, "bar", 3);

Is there an elegant way I can do this without changing libconfig code? If not, can we merge a change into the main line code to enable this functionality?

27 Jul 2010 01:32 mesmerism

Re: long long and int64_t

Windows does not have int64_t (it doesn't have inttypes.h). "long long", on the other hand, is a standard type specified by the C99 standard to be "at least 64 bits wide". I'd rather use a standard type that is available on all major platforms, rather than create yet another typedef for 64-bit integers (which maps to int64_t on systems that have inttypes.h and __int64 on WIndows).

However, I've not had any problems using 'long long' and 'int64_t' interchangeably on Linux, so I'm not sure why you're seeing a problem...

13 Jul 2010 10:52 maximdementiev

On my platform (GenuineIntel GNU/Linux 2.6.34-gentoo-r1 SMP x86_64 + gcc 4.4.4 + glibc 2.11.2) the type int64_t from inttypes.h is an alias for long (and uint64_t for unsigned long).

So, when I try to read the example (http://www.hyperrealm.com/libconfig/test.cfg.txt), the library fails to give me value 9223372036854775807 of type Setting::TypeInt64 with the help of "uint64_t(setting)", I must use "unsigned long long" type, which is not correct.

Why not to use intXX_t types instead of long, long long, ... ?

30 Jun 2010 10:36 zdo

I made small improvement. Now bools are not only 'true' and 'false', but also 'yes', 'no', 'on' and 'off'. Please commit changes in main branch.

http://github.com/zdo/libconfig-1.4.6

15 Jun 2010 08:02 kindkaktus

After upgrading from libconfig 1.4.2 to 1.4.5 I rushed into a problem that whitespace at the end is not tolerated.

E.g. parsing of config below:

name="val";

produces ParseException, syntax error at line 2. Notice whitespace at the second line.


I noticed that you recently changed whitespace rules in lex scanner, may it cause the problem?

24 May 2010 13:31 mesmerism

Regarding the long/unsigned long functions...these were removed because these types are not portable; on some systems they are 64-bit, on others 32-bit. This has caused problems in the past, so I felt that it was best to remove them.

21 May 2010 22:12 coldtobi

Hi!

My project, solarpowerlog uses libconfig++ for its configuration parser.
Recently a user reported a compile error and it narrowed down that with an 1.4.5
libconfig Setting::lookupValue(std::string, unsigned int) was no longer
available. (worked fine with 1.3.x, as in debian right now)

As there are operators for "=" defined, it seems that these functions might be
"forgotten".

The attached patch adds support for signed and unsigned longs.

--- libconfig-1.4.5.orig/lib/libconfigcpp.c++
+++ libconfig-1.4.5/lib/libconfigcpp.c++
@@ -505,6 +505,21 @@

// ---------------------------------------------------------------------------

+bool Config::lookupValue(const char *path, unsigned long &value) const throw()
+{
+ CONFIG_LOOKUP_NO_EXCEPTIONS(path, unsigned long, value);
+}
+
+// ---------------------------------------------------------------------------
+
+bool Config::lookupValue(const char *path, long &value) const throw()
+{
+ CONFIG_LOOKUP_NO_EXCEPTIONS(path, long, value);
+}
+
+
+// ---------------------------------------------------------------------------
+
Setting & Config::getRoot() const
{
return(Setting::wrapSetting(config_root_setting(_config)));
@@ -913,6 +928,22 @@

// ---------------------------------------------------------------------------

+bool Setting::lookupValue(const char *name, long &value) const throw()
+{
+ SETTING_LOOKUP_NO_EXCEPTIONS(name, long, value);
+}
+
+// ---------------------------------------------------------------------------
+
+bool Setting::lookupValue(const char *name, unsigned long &value) const
throw()
+{
+ SETTING_LOOKUP_NO_EXCEPTIONS(name, unsigned long, value);
+}
+
+
+
+// ---------------------------------------------------------------------------
+
bool Setting::exists(const char *name) const throw()
{
if(_type != TypeGroup)
--- libconfig-1.4.5.orig/lib/libconfig.h++
+++ libconfig-1.4.5/lib/libconfig.h++
@@ -257,6 +257,9 @@
bool lookupValue(const char *name, float &value) const throw();
bool lookupValue(const char *name, const char *&value) const throw();
bool lookupValue(const char *name, std::string &value) const throw();
+ bool lookupValue(const char *name, unsigned long &value) const throw();
+ bool lookupValue(const char *name, long &value) const throw();
+

inline bool lookupValue(const std::string &name, bool &value)
const throw()
@@ -293,6 +296,15 @@
inline bool lookupValue(const std::string &name, std::string &value) const
throw()
{ return(lookupValue(name.c_str(), value)); }
+
+ inline bool lookupValue(const std::string &name, unsigned long &value) const
+ throw()
+ { return(lookupValue(name.c_str(), value)); }
+
+ inline bool lookupValue(const std::string &name, long &value) const
+ throw()
+ { return(lookupValue(name.c_str(), value)); }
+

void remove(const char *name)
throw(SettingTypeException, SettingNotFoundException);
@@ -403,6 +415,8 @@
bool lookupValue(const char *path, float &value) const throw();
bool lookupValue(const char *path, const char *&value) const throw();
bool lookupValue(const char *path, std::string &value) const throw();
+ bool lookupValue(const char *path, unsigned long &value) const throw();
+ bool lookupValue(const char *path, long &value) const throw();

inline bool lookupValue(const std::string &path, bool &value) const throw()
{ return(lookupValue(path.c_str(), value)); }
@@ -437,6 +451,15 @@
inline bool lookupValue(const std::string &path, std::string &value)
const throw()
{ return(lookupValue(path.c_str(), value)); }
+
+ inline bool lookupValue(const std::string &path,
+ unsigned long &value) const throw()
+ { return(lookupValue(path.c_str(), value)); }
+
+ inline bool lookupValue(const std::string &path,
+ long &value) const throw()
+ { return(lookupValue(path.c_str(), value)); }
+

Setting & getRoot() const;

29 Apr 2010 04:00 mesmerism

@carney - You're right, that is a bug...I've applied your fix to the codebase. Thanks.

23 Apr 2010 00:09 carney

In libconfig-1.3.2 I ran into a problem with libconfigcpp.c++ Setting::add(). It's missing support for TypeInt64. Setting::assertType() also looks likes it needs TypeInt64.

My diffs:

Index: libconfigcpp.c++
===================================================================
--- libconfigcpp.c++ (revision 3451)
+++ libconfigcpp.c++ (revision 3628)
@@ -1037,9 +1037,13 @@
}
else
{
- if((type != TypeInt) && (type != TypeFloat) && (type != TypeString)
- && (type != TypeBoolean))
- throw SettingTypeException(*this, idx);
+ if((type != TypeInt) &&
+ (type != TypeInt64) &&
+ (type != TypeFloat) &&
+ (type != TypeString) &&
+ (type != TypeBoolean)) {
+ throw SettingTypeException(*this, idx);
+ }
}
}

@@ -1085,7 +1089,7 @@
if(type != _type)
{
if(!(isNumber() && config_get_auto_convert(_setting->config)
- && ((type == TypeInt) || (type == TypeFloat))))
+ && ((type == TypeInt) || (type == TypeInt64) || (type == TypeFloat))))
throw SettingTypeException(*this);
}
}

05 Apr 2010 16:56 arevet

It would be nice to get a way to compile the library with the read only capabilities, that would reduce the size of the library for many projects that are reading the config file and never writes to it.

Screenshot

Project Spotlight

ReciJournal

An open, cross-platform journaling program.

Screenshot

Project Spotlight

Veusz

A scientific plotting package.