2012-04-03 15:39:20 +02:00
|
|
|
#ifndef option_manager_hh_INCLUDED
|
|
|
|
#define option_manager_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "utils.hh"
|
|
|
|
#include "exception.hh"
|
2012-04-03 20:25:27 +02:00
|
|
|
#include "completion.hh"
|
2012-04-03 15:39:20 +02:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct option_not_found : public runtime_error
|
|
|
|
{
|
2012-04-14 03:17:09 +02:00
|
|
|
option_not_found(const String& name)
|
2012-04-03 15:39:20 +02:00
|
|
|
: runtime_error("option not found: " + name) {}
|
|
|
|
};
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
String int_to_str(int value);
|
2012-04-03 15:39:20 +02:00
|
|
|
|
|
|
|
class Option
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Option() {}
|
|
|
|
explicit Option(int value) : m_value(int_to_str(value)) {}
|
2012-04-14 03:17:09 +02:00
|
|
|
explicit Option(const String& value) : m_value(value) {}
|
2012-04-03 15:39:20 +02:00
|
|
|
|
|
|
|
Option& operator=(int value) { m_value = int_to_str(value); return *this; }
|
2012-04-14 03:17:09 +02:00
|
|
|
Option& operator=(const String& value) { m_value = value; return *this; }
|
2012-04-03 15:39:20 +02:00
|
|
|
|
|
|
|
operator int() const { return atoi(m_value.c_str()); }
|
2012-04-14 03:17:09 +02:00
|
|
|
operator String() const { return m_value; }
|
2012-04-03 15:39:20 +02:00
|
|
|
private:
|
2012-04-14 03:17:09 +02:00
|
|
|
String m_value;
|
2012-04-03 15:39:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class OptionManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OptionManager(OptionManager& parent)
|
|
|
|
: m_parent(&parent) {}
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
Option& operator[] (const String& name);
|
|
|
|
const Option& operator[] (const String& name) const;
|
2012-04-03 20:25:27 +02:00
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
CandidateList complete_option_name(const String& prefix,
|
2012-04-03 20:25:27 +02:00
|
|
|
size_t cursor_pos);
|
2012-04-03 15:39:20 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
OptionManager()
|
|
|
|
: m_parent(nullptr) {}
|
|
|
|
// the only one allowed to construct a root option manager
|
|
|
|
friend class GlobalOptionManager;
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
std::unordered_map<String, Option> m_options;
|
2012-04-03 15:39:20 +02:00
|
|
|
OptionManager* m_parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GlobalOptionManager : public OptionManager,
|
|
|
|
public Singleton<GlobalOptionManager>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GlobalOptionManager();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // option_manager_hh_INCLUDED
|