aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/details/options.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/sqlite/details/options.cxx')
-rw-r--r--odb/sqlite/details/options.cxx120
1 files changed, 113 insertions, 7 deletions
diff --git a/odb/sqlite/details/options.cxx b/odb/sqlite/details/options.cxx
index a7511e2..12f4193 100644
--- a/odb/sqlite/details/options.cxx
+++ b/odb/sqlite/details/options.cxx
@@ -15,6 +15,7 @@
#include <set>
#include <string>
#include <vector>
+#include <utility>
#include <ostream>
#include <sstream>
#include <cstring>
@@ -202,6 +203,7 @@ namespace odb
else
++i_;
+ ++start_position_;
return r;
}
else
@@ -212,11 +214,20 @@ namespace odb
skip ()
{
if (i_ < argc_)
+ {
++i_;
+ ++start_position_;
+ }
else
throw eos_reached ();
}
+ std::size_t argv_scanner::
+ position ()
+ {
+ return start_position_;
+ }
+
// argv_file_scanner
//
int argv_file_scanner::zero_argc_ = 0;
@@ -327,6 +338,7 @@ namespace odb
{
hold_[i_ == 0 ? ++i_ : --i_].swap (args_.front ().value);
args_.pop_front ();
+ ++start_position_;
return hold_[i_].c_str ();
}
}
@@ -340,7 +352,10 @@ namespace odb
if (args_.empty ())
return base::skip ();
else
+ {
args_.pop_front ();
+ ++start_position_;
+ }
}
const argv_file_scanner::option_info* argv_file_scanner::
@@ -353,6 +368,12 @@ namespace odb
return 0;
}
+ std::size_t argv_file_scanner::
+ position ()
+ {
+ return start_position_;
+ }
+
void argv_file_scanner::
load (const std::string& file)
{
@@ -527,8 +548,27 @@ namespace odb
static void
parse (bool& x, scanner& s)
{
- s.next ();
- x = true;
+ const char* o (s.next ());
+
+ if (s.more ())
+ {
+ const char* v (s.next ());
+
+ if (std::strcmp (v, "1") == 0 ||
+ std::strcmp (v, "true") == 0 ||
+ std::strcmp (v, "TRUE") == 0 ||
+ std::strcmp (v, "True") == 0)
+ x = true;
+ else if (std::strcmp (v, "0") == 0 ||
+ std::strcmp (v, "false") == 0 ||
+ std::strcmp (v, "FALSE") == 0 ||
+ std::strcmp (v, "False") == 0)
+ x = false;
+ else
+ throw invalid_value (o, v);
+ }
+ else
+ throw missing_value (o);
}
};
@@ -548,6 +588,17 @@ namespace odb
};
template <typename X>
+ struct parser<std::pair<X, std::size_t> >
+ {
+ static void
+ parse (std::pair<X, std::size_t>& x, scanner& s)
+ {
+ x.second = s.position ();
+ parser<X>::parse (x.first, s);
+ }
+ };
+
+ template <typename X>
struct parser<std::vector<X> >
{
static void
@@ -581,6 +632,7 @@ namespace odb
if (s.more ())
{
+ std::size_t pos (s.position ());
std::string ov (s.next ());
std::string::size_type p = ov.find ('=');
@@ -599,14 +651,14 @@ namespace odb
if (!kstr.empty ())
{
av[1] = const_cast<char*> (kstr.c_str ());
- argv_scanner s (0, ac, av);
+ argv_scanner s (0, ac, av, false, pos);
parser<K>::parse (k, s);
}
if (!vstr.empty ())
{
av[1] = const_cast<char*> (vstr.c_str ());
- argv_scanner s (0, ac, av);
+ argv_scanner s (0, ac, av, false, pos);
parser<V>::parse (v, s);
}
@@ -617,19 +669,73 @@ namespace odb
}
};
+ template <typename K, typename V, typename C>
+ struct parser<std::multimap<K, V, C> >
+ {
+ static void
+ parse (std::multimap<K, V, C>& m, scanner& s)
+ {
+ const char* o (s.next ());
+
+ if (s.more ())
+ {
+ std::size_t pos (s.position ());
+ std::string ov (s.next ());
+ std::string::size_type p = ov.find ('=');
+
+ K k = K ();
+ V v = V ();
+ std::string kstr (ov, 0, p);
+ std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ()));
+
+ int ac (2);
+ char* av[] =
+ {
+ const_cast<char*> (o),
+ 0
+ };
+
+ if (!kstr.empty ())
+ {
+ av[1] = const_cast<char*> (kstr.c_str ());
+ argv_scanner s (0, ac, av, false, pos);
+ parser<K>::parse (k, s);
+ }
+
+ if (!vstr.empty ())
+ {
+ av[1] = const_cast<char*> (vstr.c_str ());
+ argv_scanner s (0, ac, av, false, pos);
+ parser<V>::parse (v, s);
+ }
+
+ m.insert (typename std::multimap<K, V, C>::value_type (k, v));
+ }
+ else
+ throw missing_value (o);
+ }
+ };
+
template <typename X, typename T, T X::*M>
void
thunk (X& x, scanner& s)
{
parser<T>::parse (x.*M, s);
}
+
+ template <typename X, bool X::*M>
+ void
+ thunk (X& x, scanner& s)
+ {
+ s.next ();
+ x.*M = true;
+ }
}
}
}
}
#include <map>
-#include <cstring>
namespace odb
{
@@ -775,9 +881,9 @@ namespace odb
_cli_options_map_["--database"] =
&::odb::sqlite::details::cli::thunk< options, std::string, &options::database_ >;
_cli_options_map_["--create"] =
- &::odb::sqlite::details::cli::thunk< options, bool, &options::create_ >;
+ &::odb::sqlite::details::cli::thunk< options, &options::create_ >;
_cli_options_map_["--read-only"] =
- &::odb::sqlite::details::cli::thunk< options, bool, &options::read_only_ >;
+ &::odb::sqlite::details::cli::thunk< options, &options::read_only_ >;
_cli_options_map_["--options-file"] =
&::odb::sqlite::details::cli::thunk< options, std::string, &options::options_file_ >;
}