Move debian and documentation specific parts of SConstruct into SConscript files
[senf.git] / Utils / Console / Mainpage.dox
index c7270dd..e5f90e4 100644 (file)
 
     Commands may then be sent to this UDP console e.g. using netcat
     <pre>
-    $ echo "cd sys; ls" | nc6 -u --half-close localhost 23232 2>/dev/null
+    $ echo "cd sys; ls" | nc -uq0 localhost 23232 2>/dev/null
     </pre>
 
     \see senf::console::UDPServer
             // do not parse all arguments.
             senf::console::CheckedArgumentIteratorWrapper args (command.arguments());
 
-            senf::console::ParseCommandInfo::TokensRange argTokens ( *(args++) );
+            // Extract the first argument. This is again a token range.
+            senf::console::ParseCommandInfo::TokensRange arg1Tokens ( *(args++) );
             if (arg1Tokens.size() != 1)
                 raise senf::console::SyntaxErrorException("argument syntax error");
-            value = arg1Tokens[0];
+            value = arg1Tokens[0].value();
         }
 
         os << value << std::endl;
     One note: When taking the address of an overloaded function (member or non-member), the C++
     language forces you to cast that address to one of the possible types so the compiler knows,
     which overload is requested. So to add a function which is overloaded in C++, each overload
-    needs to be added explicitly, casting to the correct type:
+    needs to be added explicitly, casting to the correct type. There are some macros in
+    Utils/membind.hh to simplify this:
+
     \code
     void over(int);
     void over(int,int);
 
     senf::console::root()
-        .add("over", static_cast<void (*)(int)>(&over));
+        .add("over", SENF_FNP(void, over, (int)));
     senf::console::root()
-        .add("over", static_cast<void (*)(int,int)>(&over));
+        .add("over", SENF_FNP(void, over, (int,int));
         
     class SomeModule {
       senf::console::ScopedDirectory<SomeModule> dir;
       void overlodedMethod(unsigned int)   {....};
         
       void addConsoleCommands() {
-        dir.node().add("overlodedMethod", senf::membind(
-            static_cast<unsigned int (SomeModule::*)() const>(&SomeModule::overlodedMethod), this));
-        dir.node().add("overlodedMethod", senf::membind(
-            static_cast<void (SomeModule::*)(unsigned int)>(&SomeModule::overlodedMethod), this));
+        dir.node().add("overlodedMethod", 
+                       SENF_MEMBINDFNP(unsigned int, SomeModule, overlodedMethod, () const));
+        dir.node().add("overlodedMethod", 
+                       SENF_MEMBINDFNP(unsigned int, SomeModule, overlodedMethod, (unsigned int));
       }
     }
     \endcode
     public:
         enum Color { Red, Green, Blue };
     
-        senf::console::ScopedDirectory<MyClass> dir;
+        senf::console::ScopedDirectory<Test3> dir;
 
         Test3();
 
     SENF_CONSOLE_REGISTER_ENUM_MEMBER( Test3, Color, (Red)(Green)(Blue) );
 
     Test3::Test3() : dir(this)
-        { dir.add("test", &MyClass::mem3); }
+        { dir.add("test", &Test3::mem3); }
     
     Test3 test3ob;
     senf::console::root().add("test3ob", test3ob.dir);
     \endhtmlonly
 
 
+    \subsection console_args_convert Handling special argument types by conversion
+
+    Sometimes an argument type is best handled by just pretending it to be of some other type. The
+    basic idea is, to us \c boost::function to convert the real argument type to some different type
+
+    \code
+    unsigned char fun4(unsigned char value)
+    {
+        return value;
+    }
+    
+    senf::console::root()
+        .add("test8", boost::function<unsigned (unsigned)>(&fun4));
+    \endcode
+    
+    Here, the type signature specified via \c boost::function is different from the real type
+    signature but is compatible. \c boost::function automatically handles the conversion
+    process. Since the console library now sees the argument and return value of type \c unsigned,
+    the values will be parsed correctly as numeric values.
+
+    The same idea can be used to support custom parsing rules. See senf::console::FlagCollection.
+
+
     \subsection console_args_custom Extending the library to support additional types
 
     To support or customize parsing/formatting of other types, they need to be registered. In it's