Console: More simple argument parsing (argument iterator wrapper)
[senf.git] / Console / Variables.ih
index e1a2ce8..3772fd0 100644 (file)
 
 // Custom includes
 #include <boost/function.hpp>
+#include <boost/type_traits/is_const.hpp>
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
 namespace senf {
 namespace console {
+
+    template <class Variable> class ConstVariableAttributor;
+    template <class Variable> class VariableAttributor;
+
 namespace detail {
 
+#ifndef DOXYGEN
+
     template <class Variable>
     struct QueryVariable
     {
         typedef Variable const & Signature ();
         typedef boost::function<Signature> Function;
         typedef detail::ParsedCommandTraits<Signature> Traits;
+        typedef Variable const & result_type;
 
         QueryVariable(Variable const & var);
 
@@ -56,16 +64,34 @@ namespace detail {
         typedef boost::function<Signature> Function;
         typedef detail::ParsedCommandTraits<Signature> Traits;
         typedef boost::function<void (Variable const &)> OnChangeHandler;
+        typedef void result_type;
         
-        SetVariable(Variable & var);
+        SetVariable(Variable & var, OnChangeHandler handler = OnChangeHandler());
         
         void operator()(Variable const & value) const;
-        void onChange(OnChangeHandler handler);
 
         Variable & var_;
         OnChangeHandler handler_;
     };
 
+    template <class Variable, bool isConst=boost::is_const<Variable>::value>
+    struct VariableNodeCreator
+    {
+        typedef VariableAttributor<Variable> result_type;
+        static VariableAttributor<Variable> add(DirectoryNode & node, std::string const & name,
+                                                Variable & var);
+    };
+
+    template <class Variable>
+    struct VariableNodeCreator<Variable, true>
+    {
+        typedef ConstVariableAttributor<Variable> result_type;
+        static ConstVariableAttributor<Variable> add(DirectoryNode & node, std::string const & name,
+                                                     Variable & var);
+    };
+
+#endif
+
 }}}
 
 ///////////////////////////////ih.e////////////////////////////////////////