* src/misc/optionmap.cc, src/misc/optionmap.hh (option_map::get,

option_map::set): Handle default values.
(anonymous::to_int): Do not print anything.
* src/tgbaalgos/gv04.cc, src/tgbaalgos/gv04.hh,
src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03.hh,
src/tgbaalgos/tau03opt.cc, src/tgbaalgos/tau03opt.hh,
src/tgbaalgos/ce.cc, src/tgbaalgos/ce.hh: Take an option_map in
the constructor.
* src/tgbaalgos/gtec.cc, src/tgbaalgos/gtec.hh: Likewise.  Handle
the "poprem", "group", and "shy" options via the option_map.
Supply a couvreur99() wrapper to the shy/non-shy variant.
* src/tgbatest/ltl2tgba.cc, src/tgbatest/randtgba.cc,
iface/gspn/ssp.cc: Adjust.
This commit is contained in:
Alexandre Duret-Lutz 2005-02-16 18:53:18 +00:00
parent 77888e9293
commit f3effb9da0
20 changed files with 274 additions and 203 deletions

View file

@ -19,7 +19,6 @@
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <cassert>
#include <cstring>
#include <iostream>
#include "optionmap.hh"
@ -34,44 +33,43 @@ namespace spot
char* endptr;
int res = strtol(s, &endptr, 10);
if (*endptr)
{
std::cerr << "Failed to parse `" << s << "' as an integer."
<< std::endl;
return false;
}
return false;
i = res;
return true;
}
};
const char* option_map::parse_options(char* options)
const char*
option_map::parse_options(char* options)
{
char* opt = strtok(options, ", \t;");
while (opt)
{
char* equal;
if ((equal = strchr(opt, '=')) != 0)
{
*equal = 0;
int val;
if (!to_int(equal+1, val))
return opt;
options_[opt] = val;
}
else
// default value if declared
options_[opt] = 1;
opt = strtok(0, ", \t;");
}
return 0;
char* opt = strtok(options, ", \t;");
while (opt)
{
char* equal = strchr(opt, '=');
if (equal)
{
*equal = 0;
int val;
if (!to_int(equal + 1, val))
return opt;
options_[opt] = val;
}
else
{
options_[opt] = 1;
}
opt = strtok(0, ", \t;");
}
return 0;
}
int option_map::get(const char* option) const
int
option_map::get(const char* option, int def) const
{
std::map<std::string, int>::const_iterator it = options_.find(option);
if (it == options_.end())
// default value if not declared
return 0;
return def;
else
return it->second;
}
@ -81,22 +79,25 @@ namespace spot
return get(option);
}
int option_map::set(const char* option, int val)
int
option_map::set(const char* option, int val, int def)
{
int old = get(option);
int old = get(option, def);
options_[option] = val;
return old;
}
int& option_map::operator[](const char* option)
int&
option_map::operator[](const char* option)
{
return options_[option];
}
std::ostream& operator<<(std::ostream& os, const option_map& m)
std::ostream&
operator<<(std::ostream& os, const option_map& m)
{
for (std::map<std::string, int>::const_iterator it = m.options_.begin();
it != m.options_.end(); ++it)
it != m.options_.end(); ++it)
os << "\"" << it->first << "\" = " << it->second << std::endl;
return os;
}

View file

@ -46,19 +46,22 @@ namespace spot
/// \brief Get the value of \a option.
///
/// \return The value associated to \a option if it exists, 0 otherwise.
int get(const char* option) const;
/// \return The value associated to \a option if it exists,
/// \a def otherwise.
/// \see operator[]()
int get(const char* option, int def = 0) const;
/// \brief Get the value of \a option.
///
/// \return The value associated to \a option if it exists, 0 otherwise.
/// \see get()
int operator[](const char* option) const;
/// \brief Set the value of \a option to \a val.
///
/// \return The current value associated to \a option if declared,
/// 0 otherwise.
int set(const char* option, int val);
/// \return The previous value associated to \a option if declared,
/// or \a def otherwise.
int set(const char* option, int val, int def = 0);
/// \brief Get a reference to the current value of \a option.
int& operator[](const char* option);