[Saga-devel] saga SVN commit 3415: /trunk/
jpabecasis at cct.lsu.edu
jpabecasis at cct.lsu.edu
Sat Jan 31 15:29:21 CST 2009
User: jpabecasis
Date: 2009/01/31 03:29 PM
Modified:
/trunk/saga/impl/engine/ini/
ini.cpp
/trunk/test/cpp/misc_tests/
ini_parser.cpp, ini_parser.ini
Log:
Lazy expansion of configuration settings.
Also expanded test case to cover this.
ini::has_entry has been simplified to use get_entry, which may seem
backwards but the code already did essentially the same. I think
has_entry should just be banished. Use get_entry with a default value
instead and handle the empty value!
In the process, I just realized how broken the implementation of the
pimpl idiom seems to be here, as well as the use of root and
clone'ing... get_section(s) is fundamentally broken.
The whole ini mess should really be cleaned up!
File Changes:
Directory: /trunk/saga/impl/engine/ini/
=======================================
File [modified]: ini.cpp
Delta lines: +11 -32
===================================================================
--- trunk/saga/impl/engine/ini/ini.cpp 2009-01-31 21:27:08 UTC (rev 3414)
+++ trunk/saga/impl/engine/ini/ini.cpp 2009-01-31 21:28:30 UTC (rev 3415)
@@ -336,9 +336,6 @@
void saga::impl::ini::section::add_entry (std::string key,
std::string val)
{
- if ( ! val.empty () )
- val = expand_entry (val);
-
if ( val.empty () )
entries.erase (key);
else
@@ -347,30 +344,7 @@
bool saga::impl::ini::section::has_entry (std::string key) const
{
- std::string::size_type i = key.find (".", 0);
-
- if ( i != std::string::npos )
- {
- std::string sub_sec = key.substr (0, i);
- std::string sub_key = key.substr (i+1, key.length () - i);
-
- if ( has_section (sub_sec) )
- {
- section_map::const_iterator cit = sections.find(sub_sec);
- BOOST_ASSERT(cit != sections.end());
- return ((*cit).second.has_entry (sub_key));
- }
-
- SAGA_THROW("No such section (" + sub_sec + ") in section " + get_name (),
- saga::DoesNotExist);
- }
-
- if ( entries.find (key) != entries.end () )
- {
- return true;
- }
-
- return false;
+ return !get_entry(key, "").empty();
}
std::string saga::impl::ini::section::get_entry (std::string key) const
@@ -393,11 +367,12 @@
saga::DoesNotExist);
}
- if ( has_entry (key) )
+ entry_map::const_iterator cit = entries.find(key);
+ if (cit != entries.end())
{
- entry_map::const_iterator cit = entries.find(key);
- BOOST_ASSERT(cit != entries.end());
- return ((*cit).second);
+ std::string result = expand_entry((*cit).second);
+ if (!result.empty())
+ return result;
}
SAGA_THROW("No such key (" + key + ") in section " + get_name (),
@@ -431,7 +406,11 @@
if (cur_section->entries.end() == entry)
return default_val;
- return entry->second;
+ std::string result = expand_entry(entry->second);
+ if (result.empty())
+ return default_val;
+
+ return result;
}
const saga::impl::ini::entry_map & saga::impl::ini::section::get_entries (void) const
Directory: /trunk/test/cpp/misc_tests/
======================================
File [modified]: ini_parser.cpp
Delta lines: +34 -13
===================================================================
--- trunk/test/cpp/misc_tests/ini_parser.cpp 2009-01-31 21:27:08 UTC (rev 3414)
+++ trunk/test/cpp/misc_tests/ini_parser.cpp 2009-01-31 21:28:30 UTC (rev 3415)
@@ -13,42 +13,63 @@
#include <saga/saga/adaptors/utils/ini/ini.hpp>
-#include <boost/assert.hpp>
+#include <boost/test/minimal.hpp>
#include <string>
+#include <iostream>
-int main()
+int test_main(int, char *[])
{
saga::ini::section conf("ini_parser.ini");
// Identifying sections and nested sections.
- BOOST_ASSERT(conf.has_section("section"));
+ BOOST_CHECK(conf.has_section("section"));
+
// FIXME: has_section_full should be folded into has_section.
- BOOST_ASSERT(conf.has_section_full("section.nested"));
- BOOST_ASSERT(conf.has_section_full("section.nested.even.more"));
+ BOOST_CHECK(conf.has_section_full("section.nested"));
+ BOOST_CHECK(conf.has_section_full("section.nested.even.more"));
{
// Getting and reading from a section
- // FIXME: These should also work, for consistency with get_entry.
- // BOOST_ASSERT(conf.has_entry("section.entry"));
- // BOOST_ASSERT(!conf.has_entry("section.no-entry"));
+ BOOST_CHECK(conf.has_entry("section.entry"));
+ BOOST_CHECK(!conf.has_entry("section.no-entry"));
saga::ini::section section = conf.get_section("section");
- BOOST_ASSERT(section.has_entry("entry"));
- BOOST_ASSERT(!section.has_entry("no-entry"));
+ BOOST_CHECK(section.has_entry("entry"));
+ BOOST_CHECK(!section.has_entry("no-entry"));
}
// Getting nested entries
- BOOST_ASSERT("value" == conf.get_entry("section.entry"));
- BOOST_ASSERT("default" == conf.get_entry("section.no-entry", "default"));
+ BOOST_CHECK("value" == conf.get_entry("section.entry"));
+ BOOST_CHECK("default" == conf.get_entry("section.no-entry", "default"));
{
// Accessing a nested section
saga::ini::section very_nested_section
= conf.get_section("section.nested.even.more");
- BOOST_ASSERT("very-nested-value"
+ BOOST_CHECK("very-nested-value"
== very_nested_section.get_entry("very-nested-entry"));
}
+
+ // Variable expansion
+ {
+ // FIXME: get_section is fundamentally broken!
+ // saga::ini::section section = conf.get_section("variable-expansion");
+
+ BOOST_CHECK(conf.get_entry("variable-expansion.defined")
+ == conf.get_entry("section.entry"));
+ BOOST_CHECK(conf.has_entry("variable-expansion.not-defined")
+ == conf.has_entry("section.no-entry"));
+ BOOST_CHECK("default value"
+ == conf.get_entry("variable-expansion.default-value"));
+
+ BOOST_CHECK(conf.get_entry("variable-expansion.nested-entry-1")
+ == conf.get_entry("variable-expansion.defined"));
+ BOOST_CHECK(conf.get_entry("variable-expansion.nested-entry-2")
+ == conf.get_entry("variable-expansion.defined"));
+ }
+
+ return 0;
}
File [modified]: ini_parser.ini
Delta lines: +16 -0
===================================================================
--- trunk/test/cpp/misc_tests/ini_parser.ini 2009-01-31 21:27:08 UTC (rev 3414)
+++ trunk/test/cpp/misc_tests/ini_parser.ini 2009-01-31 21:28:30 UTC (rev 3415)
@@ -24,3 +24,19 @@
[section.nested.even.more]
very-nested-entry = very-nested-value
+[variable-expansion]
+defined = $[section.entry]
+not-defined = $[section.no-entry]
+default-value = $[section.no-entry:default value]
+
+# nested references in default value
+nested-entry-1 = $[section.entry:$[section.no-entry]]
+nested-entry-2 = $[section.no-entry:$[section.entry]]
+
+# TODO: Escape sequences in default values (and elsewhere?)
+
+[variable-expansion.environment]
+defined = ${PATH}
+not-defined = ${__SAGA_NOT_DEFINED_VAR__}
+default-value = ${__SAGA_NOT_DEFINED_VAR__:default value}
+
More information about the saga-devel
mailing list