[rkward-cvs] SF.net SVN: rkward:[2464] trunk/rkward/rkward/rbackend

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon May 11 17:14:55 UTC 2009


Revision: 2464
          http://rkward.svn.sourceforge.net/rkward/?rev=2464&view=rev
Author:   tfry
Date:     2009-05-11 17:14:54 +0000 (Mon, 11 May 2009)

Log Message:
-----------
Use QStringList for substack calls in order to simplify code

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rbackend/rembedinternal.h
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rthread.cpp
    trunk/rkward/rkward/rbackend/rthread.h

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2009-05-11 16:44:11 UTC (rev 2463)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2009-05-11 17:14:54 UTC (rev 2464)
@@ -2,7 +2,7 @@
                           rembedinternal  -  description
                              -------------------
     begin                : Sun Jul 25 2004
-    copyright            : (C) 2004, 2005, 2006, 2007, 2008 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2005, 2006, 2007, 2008, 2009 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -23,6 +23,7 @@
 #define TRUE true
 #define FALSE false
 #include <qstring.h>
+#include <QStringList>
 #include <qtextcodec.h>
 #include "../core/robject.h"
 #include "../debug.h"
@@ -683,7 +684,11 @@
 
 	unsigned int count;
 	QString *strings = SEXPToStringList (call, &count);
-	REmbedInternal::this_pointer->handleSubstackCall (strings, count);
+	QStringList list;
+	for (int i = 0; i < count; ++i) {
+		list.append (strings[i]);
+	}
+	REmbedInternal::this_pointer->handleSubstackCall (list);
 	delete [] strings;
 	return R_NilValue;
 }

Modified: trunk/rkward/rkward/rbackend/rembedinternal.h
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.h	2009-05-11 16:44:11 UTC (rev 2463)
+++ trunk/rkward/rkward/rbackend/rembedinternal.h	2009-05-11 17:14:54 UTC (rev 2464)
@@ -2,7 +2,7 @@
                           rembedinternal  -  description
                              -------------------
     begin                : Sun Jul 25 2004
-    copyright            : (C) 2004, 2005, 2006, 2007 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2005, 2006, 2007, 2009 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -47,6 +47,7 @@
 	bool bool_a;		/**< a bool parameter. Look at the respective callbacks to find out, what it is used for. */
 };
 
+class QStringList;
 class QString;
 class RData;
 class QTextCodec;
@@ -144,7 +145,7 @@
 
 /** The main callback from R to rkward. Since we need QStrings and stuff to handle the requests, this is only a pure virtual function. The real
 implementation is in RThread::handleSubstackCall () */
-	virtual void handleSubstackCall (QString *call, int call_length) = 0;
+	virtual void handleSubstackCall (QStringList &list) = 0;
 
 /** This second callback handles R standard callbacks. The difference to the first one is, that these are typically required to finish within the same
 function. On the other hand, also, they don't require further computations in R, and hence no full-fledged substack.

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2009-05-11 16:44:11 UTC (rev 2463)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2009-05-11 17:14:54 UTC (rev 2464)
@@ -291,7 +291,7 @@
 
 	// clear reply object
 	issueCommand (".rk.set.reply (NULL)", RCommand::App | RCommand::Sync, QString::null, 0, 0, request->in_chain);
-	if (!request->call_length) {
+	if (request->call.isEmpty ()) {
 		RK_ASSERT (false);
 		closeChain (request->in_chain);
 		return;
@@ -299,7 +299,7 @@
 	
 	QString call = request->call[0];
 	if (call == "get.tempfile.name") {
-		if (request->call_length >= 3) {
+		if (request->call.count () >= 3) {
 			QString file_prefix = request->call[1];
 			QString file_extension = request->call[2];
 			QDir dir (RKSettingsModuleGeneral::filesPath ());
@@ -313,9 +313,9 @@
 			issueCommand (".rk.set.reply (\"Too few arguments in call to get.tempfile.name.\")", RCommand::App | RCommand::Sync, QString::null, 0, 0, request->in_chain);
 		}
 	} else if (call == "sync") {
-		RK_ASSERT (request->call_length >= 2);
+		RK_ASSERT (request->call.count () >= 2);
 
-		for (int i = 1; i < request->call_length; ++i) {
+		for (int i = 1; i < request->call.count (); ++i) {
 			QString object_name = request->call[i];
 			RObject *obj = RObjectList::getObjectList ()->findObject (object_name);
 			if (obj) {
@@ -327,25 +327,22 @@
 			}
 		}
 	} else if (call == "syncall") {
-		RK_ASSERT (request->call_length == 1);
+		RK_ASSERT (request->call.count () == 1);
 
 		RK_DO (qDebug ("triggering update of object list"), RBACKEND, DL_DEBUG);
 		RObjectList::getObjectList ()->updateFromR (request->in_chain);
 	} else if (call == "syncglobal") {
-		RK_ASSERT (request->call_length == 1);
+		RK_ASSERT (request->call.count () == 1);
 
 		RK_DO (qDebug ("triggering update of globalenv"), RBACKEND, DL_DEBUG);
 		RObjectList::getGlobalEnv ()->updateFromR (request->in_chain);
 	} else if (call == "edit") {
-		RK_ASSERT (request->call_length >= 2);
+		RK_ASSERT (request->call.count () >= 2);
 
-		QStringList object_list;
-		for (int i = 1; i < request->call_length; ++i) {
-			object_list.append (request->call[i]);
-		}
+		QStringList object_list = request->call.mid (1);
 		new RKEditObjectAgent (object_list, request->in_chain);
 	} else if (call == "require") {
-		if (request->call_length >= 2) {
+		if (request->call.count () >= 2) {
 			QString lib_name = request->call[1];
 			KMessageBox::information (0, i18n ("The R-backend has indicated that in order to carry out the current task it needs the package '%1', which is not currently installed. We will open the package-management tool, and there you can try to locate and install the needed package.", lib_name), i18n ("Require package '%1'", lib_name));
 			RKLoadLibsDialog::showInstallPackagesModal (0, request->in_chain, lib_name);
@@ -360,14 +357,14 @@
 #ifndef DISABLE_RKWINDOWCATCHER
  	} else if (call == "startOpenX11") {
 		// TODO: error checking/handling (wrong parameter count/type)
-		if (request->call_length >= 2) {
+		if (request->call.count () >= 2) {
 			MUTEX_LOCK;
 			window_catcher->start (QString (request->call[1]).toInt ());
 			MUTEX_UNLOCK;
 		}
  	} else if (call == "endOpenX11") {
 		// TODO: error checking/handling (wrong parameter count/type)
-		if (request->call_length >= 2) {
+		if (request->call.count () >= 2) {
 			MUTEX_LOCK;
 			window_catcher->stop (QString (request->call[1]).toInt ());
 			MUTEX_UNLOCK;

Modified: trunk/rkward/rkward/rbackend/rthread.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.cpp	2009-05-11 16:44:11 UTC (rev 2463)
+++ trunk/rkward/rkward/rbackend/rthread.cpp	2009-05-11 17:14:54 UTC (rev 2464)
@@ -380,10 +380,10 @@
 	MUTEX_UNLOCK;
 }
 
-void RThread::handleSubstackCall (QString *call, int call_length) {
+void RThread::handleSubstackCall (QStringList &call) {
 	RK_TRACE (RBACKEND);
 
-	if (call_length == 2) {		// schedule symbol update for later
+	if (call.count () == 2) {		// schedule symbol update for later
 		if (call[0] == "ws") {
 			RK_ASSERT (current_command);
 			if ((current_command->type () & RCommand::ObjectListUpdate) || (!(current_command->type () & RCommand::Sync))) {		// ignore Sync commands that are not flagged as ObjectListUpdate
@@ -394,16 +394,15 @@
 	}
 
 	RCommand *prev_command = current_command;
-	REvalRequest *request = new REvalRequest;
-	request->call = call;
-	request->call_length = call_length;
+	REvalRequest request;
+	request.call = call;
 	MUTEX_LOCK;
 	flushOutput ();
 	RCommandStack *reply_stack = new RCommandStack (prev_command);
-	request->in_chain = reply_stack->startChain (reply_stack);
+	request.in_chain = reply_stack->startChain (reply_stack);
 	MUTEX_UNLOCK;
 
-	RKRBackendEvent* event = new RKRBackendEvent (RKRBackendEvent::REvalRequest, request);
+	RKRBackendEvent* event = new RKRBackendEvent (RKRBackendEvent::REvalRequest, &request);
 	qApp->postEvent (RKGlobals::rInterface (), event);
 	
 	bool done = false;
@@ -443,7 +442,6 @@
 	}
 
 	MUTEX_LOCK;
-	delete request;
 	delete reply_stack;
 	MUTEX_UNLOCK;
 }
@@ -599,14 +597,14 @@
 		global_env_toplevel_count = count;
 	
 		if (search_update_needed) {	// this includes an update of the globalenv, even if not needed
-			QString call = "syncall";
 			MUTEX_UNLOCK;
-			handleSubstackCall (&call, 1);
+			QStringList call ("syncall");
+			handleSubstackCall (call);
 			MUTEX_LOCK;
 		} else if (globalenv_update_needed) {
-			QString call = "syncglobal";
 			MUTEX_UNLOCK;
-			handleSubstackCall (&call, 1);
+			QStringList call ("syncglobal");
+			handleSubstackCall (call);
 			MUTEX_LOCK;
 		}
 	}
@@ -617,18 +615,11 @@
 	}
 
 	if (!changed_symbol_names.isEmpty ()) {
-		int call_length = changed_symbol_names.count () + 1;
-		QString *call = new QString[call_length];
-		call[0] = "sync";
-		int i = 1;
-		for (QStringList::const_iterator it = changed_symbol_names.constBegin (); it != changed_symbol_names.constEnd (); ++it) {
-			call[i++] = *it;
-		}
-		RK_ASSERT (i == call_length);
+		QStringList call = changed_symbol_names;
+		call.prepend (QString ("sync"));	// should be faster than reverse
 		MUTEX_UNLOCK;
-		handleSubstackCall (call, call_length);
+		handleSubstackCall (call);
 		MUTEX_LOCK;
-		delete [] call;
 		changed_symbol_names.clear ();
 	}
 }

Modified: trunk/rkward/rkward/rbackend/rthread.h
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.h	2009-05-11 16:44:11 UTC (rev 2463)
+++ trunk/rkward/rkward/rbackend/rthread.h	2009-05-11 17:14:54 UTC (rev 2464)
@@ -36,8 +36,7 @@
 private:
 friend class RInterface;
 friend class RThread;
-	QString *call;
-	int call_length;
+	QStringList call;
 	RCommandChain *in_chain;
 };
 
@@ -154,7 +153,7 @@
 
 This is a sub-eventloop, being run when the backend request information from the frontend. See \ref RThread for a more detailed description
 @see REmbedInternal::handleSubstackCall () */
-	void handleSubstackCall (QString *call, int call_length);
+	void handleSubstackCall (QStringList &call);
 
 /** This function is public for technical reasons, only. Don't use except from REmbedInternal!
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list