[rkward-cvs] SF.net SVN: rkward:[3131] branches/2010_10_18_backend_restructuring_branch/ rkward/rbackend

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Oct 18 13:12:31 UTC 2010


Revision: 3131
          http://rkward.svn.sourceforge.net/rkward/?rev=3131&view=rev
Author:   tfry
Date:     2010-10-18 13:12:31 +0000 (Mon, 18 Oct 2010)

Log Message:
-----------
Use the two runDirectCommand()-methods, where applicable.
Compiles and runs in the current state.

Modified Paths:
--------------
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp	2010-10-18 11:57:12 UTC (rev 3130)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp	2010-10-18 13:12:31 UTC (rev 3131)
@@ -59,8 +59,10 @@
 	_rk_equiv = rk_equiv;
 	RCommand::receivers = new RCommandReceiver* [MAX_RECEIVERS];
 	num_receivers = 0;
-	addReceiver (receiver);
-	addReceiver (RKCommandLog::getLog ());
+	if (!(type & Internal)) {
+		addReceiver (receiver);
+		addReceiver (RKCommandLog::getLog ());
+	}
 }
 
 RCommand::~RCommand(){

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h	2010-10-18 11:57:12 UTC (rev 3130)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h	2010-10-18 13:12:31 UTC (rev 3131)
@@ -153,6 +153,7 @@
 		Sync=16,		/**< Command is used to sync data to or from R-space. Typically used in the editor classes */
 		EmptyCommand=32,		/**< Command is empty and will not be processed (an empty command may be used as a "marker") */
 		Console=64,	/**< Command originated in the console. These commands will get some extra treatment in RKwatch */
+		Internal=128,	/**< Command is meant to be used in the backend, only. Do not use outside rbackend classes! */
 		GetIntVector=512,			/**< Try to fetch result as an array of integers */
 		GetStringVector=1024,	/**< Try to fetch result as an array of chars */
 		GetRealVector=2048,		/**< Try to fetch result as an array of doubles */

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.cpp	2010-10-18 11:57:12 UTC (rev 3130)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.cpp	2010-10-18 13:12:31 UTC (rev 3131)
@@ -34,19 +34,19 @@
 	discardData ();
 }
 
-double *RData::getRealVector () {
+double *RData::getRealVector () const {
 	return (static_cast<double *> (data));
 }
 
-int *RData::getIntVector () {
+int *RData::getIntVector () const {
 	return (static_cast<int *> (data));
 }
 
-QString *RData::getStringVector () {
+QString *RData::getStringVector () const {
 	return (static_cast<QString *> (data));
 }
 
-RData **RData::getStructureVector () {
+RData **RData::getStructureVector () const {
 	return (static_cast<RData **> (data));
 }
 

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.h	2010-10-18 11:57:12 UTC (rev 3130)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rdata.h	2010-10-18 13:12:31 UTC (rev 3131)
@@ -37,13 +37,13 @@
 /** returns the length (size) of the data array. @see RCommand::GetStringVector @see RCommand::GetRealVector @see RCommand::GetIntVector @see RCommand:GetStructure */
 	unsigned int getDataLength () { return length; };
 /** returns an array of double, if that is the type of data contained (else 0). The array is owned by the RCommand! @see RCommand::GetRealVector @see RData::detachData () @see RData::getDataLength () @see RData::getDataType () */
-	double *getRealVector ();
+	double *getRealVector () const;
 /** returns an array of int, if that is the type of data contained (else 0). The array is owned by the RCommand! @see RCommand::GetIntVector @see RData::detachData () @see RData::getDataLength () @see RData::getDataType () */
-	int *getIntVector ();
+	int *getIntVector () const;
 /** returns an array of QString, if that is the type of data contained (else 0). The array is owned by the RCommand! @see RCommand::GetStringVector @see RData::detachData () @see RData::getDataLength () @see RData::getDataType () */
-	QString *getStringVector ();
+	QString *getStringVector () const;
 /** returns an array of RData*, if that is the type of data contained (else 0). The array is owned by the RCommand! @see RCommand::GetStructureVector @see RData::detachData () @see RData::getDataLength () @see RData::getDataType () */
-	RData **getStructureVector ();
+	RData **getStructureVector () const;
 /** The data contained in the RData structure is owned by RData, and will usually be deleted at the end of the lifetime of the RData object. If you want to keep the data, call detachData () to prevent this deletion. You will be responsible for deletion of the data yourself. */
 	void detachData ();
 	void discardData ();

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp	2010-10-18 11:57:12 UTC (rev 3130)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp	2010-10-18 13:12:31 UTC (rev 3131)
@@ -1044,7 +1044,7 @@
 bool REmbedInternal::runDirectCommand (const QString &command) {
 	RK_TRACE (RBACKEND);
 
-	RCommand c (command, RCommand::App | RCommand::Sync);
+	RCommand c (command, RCommand::App | RCommand::Sync | RCommand::Internal);
 	runCommand (&c);
 	return (c.succeeded ());
 }
@@ -1053,7 +1053,7 @@
 	RK_TRACE (RBACKEND);
 	RK_ASSERT ((datatype >= RCommand::GetIntVector) && (datatype <= RCommand::GetStructuredData));
 
-	RCommand *c = new RCommand (command, RCommand::App | RCommand::Sync | datatype);
+	RCommand *c = new RCommand (command, RCommand::App | RCommand::Sync | RCommand::Internal | datatype);
 	runCommand (c);
 	return c;
 }
@@ -1129,10 +1129,10 @@
 					command->datatype = RData::StringVector;
 					command->data = SEXPToStringList (exp, &(command->length));
 				} else if (command->type () & RCommand::GetRealVector) {
-					command->datatype = RData::StringVector;
+					command->datatype = RData::RealVector;
 					command->data = SEXPToRealArray (exp, &(command->length));
 				} else if (command->type () & RCommand::GetIntVector) {
-					command->datatype = RData::StringVector;
+					command->datatype = RData::IntVector;
 					command->data = SEXPToIntArray (exp, &(command->length));
 				} else if (command->type () & RCommand::GetStructuredData) {
 					RData *data = SEXPToRData (exp);

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp	2010-10-18 11:57:12 UTC (rev 3130)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp	2010-10-18 13:12:31 UTC (rev 3131)
@@ -164,12 +164,8 @@
 	// step 2: actual handling
 	if (!((command->type () & RCommand::EmptyCommand) || (command->status & RCommand::Canceled))) {
 		all_current_commands.append (command);
-		RKWardRError error;
-		
-		int ctype = command->type ();
-		QString ccommand = command->command ();		// easier typing below
-		
-		RK_DO (qDebug ("running command: %s", ccommand.toLatin1().data ()), RBACKEND, DL_DEBUG);
+
+		RK_DO (qDebug ("running command: %s", command->command ().toLatin1().data ()), RBACKEND, DL_DEBUG);
 	
 		command->status |= RCommand::Running;	// it is important that this happens before the Mutex is unlocked!
 		RCommandStackModel::getModel ()->itemChange (command);
@@ -185,14 +181,11 @@
 
 			if (!outp.isEmpty ()) {
 				// all regular output was sink()ed, i.e. all remaining output is a message/warning/error
-				RKWardRError error;
-				runCommandInternal (".rk.cat.output (\"<h2>Messages, warnings, or errors:</h2>\\n\")", &error, false);
-				RK_ASSERT (!error);
+				runDirectCommand (".rk.cat.output (\"<h2>Messages, warnings, or errors:</h2>\\n\")");
 
 				outp.replace ('\\', "\\\\");
 				outp.replace ('"', "\\\"");
-				runCommandInternal ("rk.print.literal (\"" + outp + "\")", &error, false);
-				RK_ASSERT (!error);
+				runDirectCommand ("rk.print.literal (\"" + outp + "\")");
 			}
 		}
 	
@@ -427,49 +420,41 @@
 
 	connectCallbacks ();
 
-	RKWardRError error;
 	int status = 0;
-	
-	runCommandInternal ("library (\"rkward\")\n", &error);
-	if (error) status |= LibLoadFail;
-	runCommandInternal (QString ("stopifnot(.rk.app.version==\"%1\")\n").arg (VERSION), &error);
-	if (error) status |= LibLoadFail;
-	runCommandInternal (".rk.fix.assignments ()\n", &error);
-	if (error) status |= LibLoadFail;
 
+	if (!runDirectCommand ("library (\"rkward\")\n")) status |= LibLoadFail;
+	if (!runDirectCommand (QString ("stopifnot(.rk.app.version==\"%1\")\n").arg (VERSION))) status |= LibLoadFail;
+	if (!runDirectCommand (".rk.fix.assignments ()\n")) status |= LibLoadFail;
+
 // find out about standard library locations
-	unsigned int c;
-	QString *standardliblocs = getCommandAsStringVector (".libPaths ()\n", &c, &error);
-	if (error) status |= OtherFail;
-	for (unsigned int i = 0; i < c; ++i) {
-		RKSettingsModuleRPackages::defaultliblocs.append (standardliblocs[i]);
+	RCommand *dummy = runDirectCommand (".libPaths ()\n", RCommand::GetStringVector);
+	if (dummy->failed ()) status |= OtherFail;
+	for (unsigned int i = 0; i < dummy->getDataLength (); ++i) {
+		RKSettingsModuleRPackages::defaultliblocs.append (dummy->getStringVector ()[i]);
 	}
-	delete [] standardliblocs;
+	delete dummy;
 
 // start help server / determined help base url
-	QString *help_base_url = getCommandAsStringVector (".rk.getHelpBaseUrl ()\n", &c, &error);
-	if (error) status |= OtherFail;
+	dummy = runDirectCommand (".rk.getHelpBaseUrl ()\n", RCommand::GetStringVector);
+	if (dummy->failed ()) status |= OtherFail;
 	else {
-		RK_ASSERT (c == 1);
-		RKSettingsModuleR::help_base_url = help_base_url[0];
+		RK_ASSERT (dummy->getDataLength () == 1);
+		RKSettingsModuleR::help_base_url = dummy->getStringVector ()[0];
 	}
-	delete [] help_base_url;
+	delete dummy;
 
 // apply user configurable run time options
 	QStringList commands = RKSettingsModuleR::makeRRunTimeOptionCommands () + RKSettingsModuleRPackages::makeRRunTimeOptionCommands () + RKSettingsModuleOutput::makeRRunTimeOptionCommands () + RKSettingsModuleGraphics::makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.begin (); it != commands.end (); ++it) {
-		runCommandInternal ((*it).toLocal8Bit (), &error);
-		if (error) {
+		if (!runDirectCommand ((*it).toLocal8Bit ())) {
 			status |= OtherFail;
 			RK_DO (qDebug ("error in initialization call '%s'", (*it).toLatin1().data ()), RBACKEND, DL_ERROR);
 		}
 	}
 
 // error/output sink and help browser
-	runCommandInternal ("options (error=quote (.rk.do.error ()))\n", &error);
-	if (error) status |= SinkFail;
-	runCommandInternal ("rk.set.output.html.file (\"" + RKSettingsModuleGeneral::filesPath () + "/rk_out.html\")\n", &error);
-	if (error) status |= SinkFail;
+	if (!runDirectCommand ("options (error=quote (.rk.do.error ()))\n")) status |= SinkFail;
+	if (!runDirectCommand ("rk.set.output.html.file (\"" + RKSettingsModuleGeneral::filesPath () + "/rk_out.html\")\n")) status |= SinkFail;
 
 	MUTEX_LOCK;
 	flushOutput ();
@@ -487,21 +472,17 @@
 
 	bool search_update_needed = false;
 	bool globalenv_update_needed = false;
-	RKWardRError error;
 
-	if (check_list) {
-		unsigned int count;
-		QString *strings;
-	
+	if (check_list) {	
 	// TODO: avoid parsing this over and over again
 		RK_DO (qDebug ("checkObjectUpdatesNeeded: getting search list"), RBACKEND, DL_TRACE);
-		strings = getCommandAsStringVector ("search ()\n", &count, &error);
-		if ((int) count != toplevel_env_names.count ()) {
+		RCommand *dummy = runDirectCommand ("search ()\n", RCommand::GetStringVector);
+		if ((int) dummy->getDataLength () != toplevel_env_names.count ()) {
 			search_update_needed = true;
 		} else {
-			for (unsigned int i = 0; i < count; ++i) {
+			for (unsigned int i = 0; i < dummy->getDataLength (); ++i) {
 				// order is important in the search path
-				if (toplevel_env_names[i] != strings[i]) {
+				if (toplevel_env_names[i] != dummy->getStringVector ()[i]) {
 					search_update_needed = true;
 					break;
 				}
@@ -509,21 +490,21 @@
 		}
 		if (search_update_needed) {
 			toplevel_env_names.clear ();
-			for (unsigned int i = 0; i < count; ++i) {
-				toplevel_env_names.append (strings[i]);
+			for (unsigned int i = 0; i < dummy->getDataLength (); ++i) {
+				toplevel_env_names.append (dummy->getStringVector ()[i]);
 			}
 		}
-		delete [] strings;
+		delete dummy;
 	
 	// TODO: avoid parsing this over and over again
 		RK_DO (qDebug ("checkObjectUpdatesNeeded: getting globalenv symbols"), RBACKEND, DL_TRACE);
-		strings = getCommandAsStringVector ("ls (globalenv (), all.names=TRUE)\n", &count, &error);
-		if ((int) count != global_env_toplevel_names.count ()) {
+		dummy = runDirectCommand ("ls (globalenv (), all.names=TRUE)\n", RCommand::GetStringVector);
+		if ((int) dummy->getDataLength () != global_env_toplevel_names.count ()) {
 			globalenv_update_needed = true;
 		} else {
-			for (unsigned int i = 0; i < count; ++i) {
+			for (unsigned int i = 0; i < dummy->getDataLength (); ++i) {
 				// order is not important in the symbol list
-				if (!global_env_toplevel_names.contains (strings[i])) {
+				if (!global_env_toplevel_names.contains (dummy->getStringVector ()[i])) {
 					globalenv_update_needed = true;
 					break;
 				}
@@ -531,11 +512,11 @@
 		}
 		if (globalenv_update_needed) {
 			global_env_toplevel_names.clear ();
-			for (unsigned int i = 0; i < count; ++i) {
-				global_env_toplevel_names.append (strings[i]);
+			for (unsigned int i = 0; i < dummy->getDataLength (); ++i) {
+				global_env_toplevel_names.append (dummy->getStringVector ()[i]);
 			}
 		}
-		delete [] strings;
+		delete dummy;
 	
 		if (search_update_needed) {	// this includes an update of the globalenv, even if not needed
 			MUTEX_UNLOCK;
@@ -555,7 +536,7 @@
 
 	if (search_update_needed || globalenv_update_needed) {
 		RK_DO (qDebug ("checkObjectUpdatesNeeded: updating watches"), RBACKEND, DL_TRACE);
-		runCommandInternal (".rk.watch.globalenv ()\n", &error);
+		runDirectCommand (".rk.watch.globalenv ()\n");
 	}
 
 	if (!changed_symbol_names.isEmpty ()) {


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