[project @ 2002-07-15 21:01:51 by unknown_lamer]
[clinton/bobotpp.git] / source / Parser.H
index 2fe635b..9007de8 100644 (file)
 #include <libguile.h>
 #endif
 
-struct userFunctionsStruct {
-  String name;
-  void (*function)(ServerConnection *, Person *, String, String);
-  int minLevel;
-  bool needsChannelName;
-};
+#include <map>
+#include <string>
+
+// struct userFunctionsStruct {
+//   //  String name;
+//   void (*function)(ServerConnection *, Person *, String, String);
+//   int minLevel;
+//   bool needsChannelName;
+// };
 
 class userFunction {
 public:
-  String name;
   void (*function)(ServerConnection *, Person *, String, String);
   int minLevel;
   bool needsChannelName;
@@ -50,32 +52,36 @@ public:
   SCM scmFunc;
 #endif
 
-  userFunction(String na,
-               void (*f)(ServerConnection *, Person *,
-                         String, String),
-               int m, bool n
+  userFunction(void (*f)(ServerConnection *, Person *,
+                         String, String) = 0,
+               int m = 0 , bool n = false
 #ifdef USESCRIPTS
                , int a = -1, SCM scm_f = 0
 #endif
                )
-    : name(na), function(f), minLevel(m), needsChannelName(n)
+    : function(f), minLevel(m), needsChannelName(n)
 #ifdef USESCRIPTS
       ,argsCount(a), scmFunc(scm_f)
 #endif
     {
 #ifdef USESCRIPTS
-//      scm_protect_object(scm_f);
+      if (scmFunc)
+       scm_gc_protect_object(scmFunc);
 #endif
     }
 
 #ifdef USESCRIPTS
-//  ~userFunction()
-//    { scm_unprotect_object(scmFunc); };
+  ~userFunction()
+  { 
+    if (scmFunc)
+      scm_gc_unprotect_object(scmFunc); 
+  }
 #endif
 };
 
 class Parser {
 public:
+  static void init ();
   static void parseLine(ServerConnection *, String);
 
   static void parse001(ServerConnection *, Person *, String);
@@ -115,6 +121,11 @@ public:
 #endif
 
   static void sendNotice(Person *, String);
+private:
+  
+  typedef void (*fptr)(ServerConnection *, Person *, String);
+  static std::map<std::string, fptr, std::less<std::string> > functions;
+  
 };
 
 #endif