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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Oct 1 20:23:41 UTC 2006


Revision: 783
          http://svn.sourceforge.net/rkward/?rev=783&view=rev
Author:   tfry
Date:     2006-10-01 13:23:10 -0700 (Sun, 01 Oct 2006)

Log Message:
-----------
First step in allow structured data to be passed from the backend:
Create RData class as base of RCommand, and make old code compile with that

Modified Paths:
--------------
    trunk/rkward/rkward/core/rcontainerobject.cpp
    trunk/rkward/rkward/core/rfunctionobject.cpp
    trunk/rkward/rkward/core/rkvariable.cpp
    trunk/rkward/rkward/core/robject.cpp
    trunk/rkward/rkward/core/robjectlist.cpp
    trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp
    trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
    trunk/rkward/rkward/khelpdlg.cpp
    trunk/rkward/rkward/rbackend/rcommand.cpp
    trunk/rkward/rkward/rbackend/rcommand.h
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rbackend/rembedinternal.h
    trunk/rkward/rkward/rbackend/rthread.cpp
    trunk/rkward/rkward/windows/rkworkplace.cpp

Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -86,15 +86,15 @@
 
 	} else if (command->getFlags () == UPDATE_CHILD_LIST_COMMAND) {
 		// first check, whether all known children still exist:
-		checkRemovedChildren (command->getStringVector (), command->stringVectorLength ());
+		checkRemovedChildren (command->getStringVector (), command->getDataLength ());
 		
 		// next, update the existing and/or new children
-		num_children_updating = command->stringVectorLength ();
+		num_children_updating = command->getDataLength ();
 		// empty object?
 		if (!num_children_updating) {
 			parent->childUpdateComplete ();
 		}
-		for (int i = 0; i < command->stringVectorLength (); ++i) {
+		for (unsigned int i = 0; i < command->getDataLength (); ++i) {
 			QString cname = command->getStringVector ()[i]; 	// for easier typing
 			if (childmap.find (cname) != childmap.end ()) {
 				RK_DO (qDebug ("updating existing child: %s", cname.latin1 ()), APP, DL_DEBUG);

Modified: trunk/rkward/rkward/core/rfunctionobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rfunctionobject.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/core/rfunctionobject.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -55,10 +55,10 @@
 		RKGlobals::rInterface ()->issueCommand (command, RKGlobals::rObjectList()->getUpdateCommandChain ());
 
 	} else if (command->getFlags () == UPDATE_ARGS_COMMAND) {
-		RK_ASSERT (command->stringVectorLength () % 2 == 0);
+		RK_ASSERT (command->getDataLength () % 2 == 0);
 
 		function_args.clear ();
-		for (int i = 0; i < command->stringVectorLength (); i += 2) {
+		for (unsigned int i = 0; i < command->getDataLength (); i += 2) {
 			function_args.append (new FunctionArg (command->getStringVector ()[i], command->getStringVector ()[i+1]));
 		}
 

Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/core/rkvariable.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -133,7 +133,8 @@
 		if (properties_changed) RKGlobals::tracker ()->objectMetaChanged (this);
 
 	} else if (command->getFlags () == GET_STORAGE_MODE_COMMAND) {
-		RK_ASSERT (command->intVectorLength () == 2);
+		RK_ASSERT (command->getDataType () == RData::IntVector);
+		RK_ASSERT (command->getDataLength () == 2);
 		if (!(command->getIntVector ()[1])) {
 			RKGlobals::rInterface ()->issueCommand ("levels (" + getFullName () + ")", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_FACTOR_LEVELS_COMMAND);
 			if (getVarType () == Unknown) {
@@ -157,12 +158,12 @@
 		RK_ASSERT (myData ());
 		// prevent resyncing of data
 		setSyncing (false);
-		if (command->realVectorLength ()) {
-			RK_ASSERT (command->realVectorLength () == getLength ());
-			setNumeric (0, command->realVectorLength () - 1, command->getRealVector ());
-		} else if (command->stringVectorLength ()) {
-			RK_ASSERT (command->stringVectorLength () == getLength ());
-			setCharacter (0, command->stringVectorLength () - 1, command->getStringVector ());
+		int len = command->getDataLength ();
+		RK_ASSERT (len == getLength ());
+		if (command->getDataType () == RData::RealVector) {
+			setNumeric (0, len - 1, command->getRealVector ());
+		} else if (command->getDataType () == RData::StringVector) {
+			setCharacter (0, len - 1, command->getStringVector ());
 		} else {
 			RK_ASSERT (false);
 		}
@@ -176,10 +177,10 @@
 		RK_ASSERT (myData ());
 		// prevent resyncing of data
 		setSyncing (false);
-		RK_ASSERT (command->stringVectorLength ());
+		RK_ASSERT (command->getDataLength ());
 		RK_ASSERT (!myData ()->value_labels);
 		myData ()->value_labels = new RObject::ValueLabels;
-		for (int i=0; i < command->stringVectorLength (); ++i) {
+		for (unsigned int i=0; i < command->getDataLength (); ++i) {
 			myData ()->value_labels->insert (QString::number (i+1), command->getStringVector ()[i]);
 		}
 		setSyncing (true);

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/core/robject.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -196,11 +196,11 @@
 void RObject::handleGetMetaCommand (RCommand *command) {
 	RK_TRACE (OBJECTS);
 
-	if (command->stringVectorLength ()) {
+	if (command->getDataLength ()) {
 		if (!meta_map) meta_map = new MetaMap;
 		meta_map->clear ();
 
-		int len = command->stringVectorLength ();
+		int len = command->getDataLength ();
 		RK_ASSERT (!(len % 2));
 		int cut = len/2;
 		for (int i=0; i < cut; ++i) {
@@ -224,8 +224,9 @@
 
 	bool change = false;
 
-	if (num_classes != command->stringVectorLength ()) {
-		num_classes = command->stringVectorLength ();
+	int len = command->getDataLength ();
+	if (num_classes != len) {
+		num_classes = len;
 		delete[] classname;
 		classname = new QString [num_classes];
 		change = true;
@@ -241,7 +242,7 @@
 bool RObject::handleClassifyCommand (RCommand *command, bool *dims_changed) {
 	RK_TRACE (OBJECTS);
 
-	if (!command->intVectorLength ()) {
+	if (!command->getDataLength ()) {
 		RK_ASSERT (false);
 		return false;
 	}
@@ -258,8 +259,9 @@
 	}
 
 	// get dimensions
-	if (num_dimensions != (command->intVectorLength () - 1)) {
-		num_dimensions = command->intVectorLength () - 1;
+	int len = command->getDataLength () - 1;
+	if (num_dimensions != len) {
+		num_dimensions = len;
 		*dims_changed = true;
 		delete dimension;
 		if (num_dimensions < 1) {

Modified: trunk/rkward/rkward/core/robjectlist.cpp
===================================================================
--- trunk/rkward/rkward/core/robjectlist.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/core/robjectlist.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -63,17 +63,17 @@
 
 	if (command->getFlags () == UPDATE_LIST_COMMAND) {
 		// first check, whether all known children still exist:
-		checkRemovedChildren (command->getStringVector (), command->stringVectorLength ());
+		checkRemovedChildren (command->getStringVector (), command->getDataLength ());
 		
 		// next, update the existing and/or new children
-		num_children_updating = command->stringVectorLength ();		// TODO: is this correct? Some children might have been removed!
+		num_children_updating = command->getDataLength ();		// TODO: is this correct? Some children might have been removed!
 		// empty workspace?
 		if (!num_children_updating) {
 			num_children_updating = 1;
 			childUpdateComplete ();
 			return;
 		}
-		for (int i = 0; i < command->stringVectorLength (); ++i) {
+		for (unsigned int i = 0; i < command->getDataLength (); ++i) {
 			QString cname = command->getStringVector ()[i];		// for easier typing
 			/*if (cname == (".rk.meta")) {
 				childUpdateComplete ();
@@ -87,7 +87,7 @@
 			}
 		}
 	} else if (command->getFlags () == CHILD_GET_TYPE_COMMAND) {
-		if (command->intVectorLength () != 1) {
+		if (command->getDataLength () != 1) {
 			RK_ASSERT (false);
 		}
 

Modified: trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -105,21 +105,22 @@
 	RK_TRACE (EDITOR);
 
 	if (command->getFlags () == GET_NAMES_COMMAND) {
-		while (command->stringVectorLength () < numTrueCols ()) {	// get rid of superficial columns
+		int len = command->getDataLength ();
+		while (len < numTrueCols ()) {	// get rid of superficial columns
 			deleteColumn (0);
 		}
 
 		// this is really just a very preliminary HACK. If stringVectorLength () is 0, this can not be a data.frame any longer.
 		// abort in order to avoid crash.
 		// TODO: actually, we should have a true check for object type each time before opening an object.
-		if (!command->stringVectorLength ()) {
+		if (!len) {
 			open_chain = RKGlobals::rInterface ()->closeChain (open_chain);
 			delete this;
 			return;
 		}
 
 		// set the names and meta-information
-		for (int col = 0; col < command->stringVectorLength (); ++col) {
+		for (int col = 0; col < len; ++col) {
 			if (numTrueCols () <= col) {
 				insertNewColumn ();
 			}

Modified: trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -141,9 +141,10 @@
 void RKLoadLibsDialog::rCommandDone (RCommand *command) {
 	RK_TRACE (DIALOGS);
 	if (command->getFlags () == GET_CURRENT_LIBLOCS_COMMAND) {
-		RK_ASSERT (command->stringVectorLength () > 0);
+		RK_ASSERT (command->getDataType () == RData::StringVector);
+		RK_ASSERT (command->getDataLength () > 0);
 		QStringList current_library_locations;
-		for (int i=0; i < command->stringVectorLength (); ++i) {
+		for (unsigned int i=0; i < command->getDataLength (); ++i) {
 			current_library_locations.append (command->getStringVector ()[i]);
 		}
 		emit (libraryLocationsChanged (current_library_locations));
@@ -274,13 +275,15 @@
 void LoadUnloadWidget::rCommandDone (RCommand *command) {
 	RK_TRACE (DIALOGS);
 	if (command->getFlags () == GET_INSTALLED_PACKAGES) {
-		RK_ASSERT ((command->stringVectorLength () % 4) == 0);
-		int count = (command->stringVectorLength () / 4);
+		RK_ASSERT (command->getDataType () == RData::StringVector);
+		RK_ASSERT ((command->getDataLength () % 4) == 0);
+		int count = (command->getDataLength () / 4);
 		for (int i=0; i < count; ++i) {
 			new QListViewItem (installed_view, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i], command->getStringVector ()[3* count + i]);
 		}
 	} else if (command->getFlags () == GET_LOADED_PACKAGES) {
-		for (int i=0; i < command->stringVectorLength (); ++i) {
+		RK_ASSERT (command->getDataType () == RData::StringVector);
+		for (unsigned int i=0; i < command->getDataLength (); ++i) {
 			new QListViewItem (loaded_view, command->getStringVector ()[i]);
 		}
 		setEnabled (true);
@@ -461,9 +464,10 @@
 		if (!command->failed ()) {
 			delete placeholder;
 			placeholder = 0;
-			RK_ASSERT ((command->stringVectorLength () % 4) == 1);
-			int count = (command->stringVectorLength () / 4);
-			for (int i=0; i < count; ++i) {
+			RK_ASSERT (command->getDataType () == RData::StringVector);
+			RK_ASSERT ((command->getDataLength () % 4) == 1);
+			unsigned int count = (command->getDataLength () / 4);
+			for (unsigned int i=0; i < count; ++i) {
 				new QListViewItem (updateable_view, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i], command->getStringVector ()[3*count + i]);
 			}
 
@@ -594,9 +598,10 @@
 		if (!command->failed ()) {
 			delete placeholder;
 			placeholder = 0;
-			RK_ASSERT ((command->stringVectorLength () % 2) == 1);
-			int count = (command->stringVectorLength () / 2);
-			for (int i=0; i < count; ++i) {
+			RK_ASSERT (command->getDataType () == RData::StringVector);
+			RK_ASSERT ((command->getDataLength () % 2) == 1);
+			unsigned int count = (command->getDataLength () / 2);
+			for (unsigned int i=0; i < count; ++i) {
 				new QListViewItem (installable_view, command->getStringVector ()[i], command->getStringVector ()[count + i]);
 			}
 			installable_view->setEnabled (true);

Modified: trunk/rkward/rkward/khelpdlg.cpp
===================================================================
--- trunk/rkward/rkward/khelpdlg.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/khelpdlg.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -197,15 +197,15 @@
 	KURL url;
 	if (command->getFlags () == HELP_SEARCH) {
 		resultsList->clear();
-		RK_ASSERT ((command->stringVectorLength () % 3) == 0);
-		int count = (command->stringVectorLength () / 3);
+		RK_ASSERT ((command->getDataLength () % 3) == 0);
+		int count = (command->getDataLength () / 3);
 		for (int i=0; i < count; ++i) {
 			new QListViewItem (resultsList, command->getStringVector ()[i], command->getStringVector ()[count + i], command->getStringVector ()[2*count + i]);
 		}
 		setEnabled(true);
 	} 
 	else if (command->getFlags () == GET_HELP_URL) {
-		RK_ASSERT (command->stringVectorLength ());
+		RK_ASSERT (command->getDataLength ());
 		url.setPath(command->getStringVector ()[0]);
 		if (QFile::exists (url.path ())) {
 			RKwardApp::getApp ()->openHTML (url);
@@ -214,8 +214,8 @@
 			KMessageBox::sorry (this, i18n ("No help found on '%1'. Maybe the corresponding package is not installed/loaded, or maybe you mistyped the command. Try using Help->Search R Help for more options.").arg (command->command ().section ("\"", 1, 1)), i18n ("No help found"));
 		}
 	} else if (command->getFlags () == GET_INSTALLED_PACKAGES) {
-		RK_ASSERT ((command->stringVectorLength () % 4) == 0);
-		int count = (command->stringVectorLength () / 4);
+		RK_ASSERT ((command->getDataLength () % 4) == 0);
+		int count = (command->getDataLength () / 4);
 		for (int i=0; i < count; ++i) {
 			packagesList->insertItem(command->getStringVector ()[i]);
 		}

Modified: trunk/rkward/rkward/rbackend/rcommand.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rcommand.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/rbackend/rcommand.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -27,7 +27,7 @@
 
 int RCommand::next_id = 0;
 
-RCommand::RCommand(const QString &command, int type, const QString &rk_equiv, RCommandReceiver *receiver, int flags){
+RCommand::RCommand(const QString &command, int type, const QString &rk_equiv, RCommandReceiver *receiver, int flags) : RData () {
 	RK_TRACE (RBACKEND);
 	_id = next_id++;
 // if we ever submit enough commands to get a buffer overflow, use only positive numbers.
@@ -40,10 +40,6 @@
 	else _command = command;
 	if (_command.isEmpty ()) _type |= EmptyCommand;
 	status = 0;
-	string_data = 0;
-	real_data = 0;
-	integer_data = 0;
-	string_count = real_count = integer_count = 0;
 	_rk_equiv = rk_equiv;
 	RCommand::receivers = new RCommandReceiver* [MAX_RECEIVERS];
 	num_receivers = 0;
@@ -53,9 +49,6 @@
 
 RCommand::~RCommand(){
 	RK_TRACE (RBACKEND);
-	delete [] string_data;
-	delete real_data;
-	delete integer_data;
 
 	for (QValueList<ROutput*>::iterator it = output_list.begin (); it != output_list.end (); ++it) {
 		delete (*it);
@@ -161,3 +154,68 @@
 	}
 	return ret;
 }
+
+//////////////////////// RData ////////////////////////////77
+
+RData::RData () {
+	RK_TRACE (RBACKEND);
+	datatype = NoData;
+	data = 0;
+	length = 0; 
+}
+
+RData::~RData () {
+	RK_TRACE (RBACKEND);
+
+	if (datatype == StructureVector) {
+		RData **sdata = getStructureVector ();
+		for (int i=length-1; i >= 0; --i) {
+			delete (sdata[i]);
+		}
+		delete [] sdata;
+	} else if (datatype == IntVector) {
+		int *idata = getIntVector ();
+		delete [] idata;
+	} else if (datatype == RealVector) {
+		double *rdata = getRealVector ();
+		delete [] rdata;
+	} else if (datatype == StringVector) {
+		QString *stdata = getStringVector ();
+		delete [] stdata;
+	} else {
+		RK_ASSERT (datatype == NoData);
+	}
+}
+
+double *RData::getRealVector () {
+	if (datatype == RealVector) return (static_cast<double *> (data));
+
+	RK_ASSERT (false);
+	return 0;
+}
+
+int *RData::getIntVector () {
+	if (datatype == IntVector) return (static_cast<int *> (data));
+
+	RK_ASSERT (false);
+	return 0;
+}
+
+QString *RData::getStringVector () {
+	if (datatype == StringVector) return (static_cast<QString *> (data));
+
+	RK_ASSERT (false);
+	return 0;
+}
+
+RData **RData::getStructureVector () {
+	if (datatype == StructureVector) return (static_cast<RData **> (data));
+
+	RK_ASSERT (false);
+	return 0;
+}
+
+void RData::detachData () {
+	data = 0;
+	length = 0;
+}

Modified: trunk/rkward/rkward/rbackend/rcommand.h
===================================================================
--- trunk/rkward/rkward/rbackend/rcommand.h	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/rbackend/rcommand.h	2006-10-01 20:23:10 UTC (rev 783)
@@ -76,6 +76,39 @@
 	QString output;
 };
 
+/** Class to represent data (other than output/erros) passed from the R backend to the main thread. Data is usually a vector of type int, double or QString, but can also contain a hierarchy of RData*s. RCommand is a subclass of this */ 
+class RData {
+public:
+	RData ();
+	~RData ();
+	enum RDataType {
+		StructureVector,
+		IntVector,
+		RealVector,
+		StringVector,
+		NoData
+	};
+
+/** returns the type of data contained */
+	RDataType getDataType () { return datatype; };
+/** 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 ();
+/** 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 ();
+/** 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 ();
+/** 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 ();
+/** 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 ();
+protected:
+	RDataType datatype;
+	void *data;
+	unsigned int length;
+};
+
 /*
 struct RGetValueRequest {
 private:
@@ -114,7 +147,7 @@
   *@author Thomas Friedrichsmeier
   */
   
-class RCommand {
+class RCommand : public RData {
 public:
 /** constructs an RCommand.
 @param command The command (string) to be run in the backend. This may include newlines and ";". The command should be a complete statement. If it is an incomplete statement, the backend will not wait for the rest of the command to come in, but rather the command will fail with RCommand::errorIncomplete.
@@ -186,24 +219,6 @@
 	bool errorIncomplete () { return (status & ErrorIncomplete); };
 /** backend rejected command as having a syntax error */
 	bool errorSyntax () { return (status & ErrorSyntax); };
-/** returns the length (size) of the char * array. @see RCommand::GetStringVector @see RCommand::getStringVector @see RCommand::detachStringVector */
-	int stringVectorLength () { return (string_count); };
-/** returns the length (size) of the double array. @see RCommand::GetRealVector @see RCommand::getRealVector @see RCommand::detachRealVector */
-	int realVectorLength () { return (real_count); };
-/** returns the length (size) of the int array. @see RCommand::GetIntVector @see RCommand::getIntVector @see RCommand::detachIntVector */
-	int intVectorLength () { return (integer_count); };
-/** returns an array of QString*. The array is owned by the RCommand! @see RCommand::GetStringVector @see RCommand::getStringVector @see RCommand::detachStringVector */
-	QString *getStringVector () { return (string_data); };
-/** returns a pointer to the double array. The double array is owned by the RCommand! @see RCommand::GetRealVector @see RCommand::getRealVector @see RCommand::detachRealVector */
-	double *getRealVector () { return (real_data); };
-/** returns a pointer to the int array. The int array is owned by the RCommand! @see RCommand::GetIntVector @see RCommand::getIntVector @see RCommand::detachIntVector */
-	int *getIntVector () { return (integer_data); };
-/** if you want to keep the data, use this function to detach it from the RCommand (after reading the pointer with RCommand::getStringVector), so it won't be deleted with the RCommand */
-	void detachStringVector () { string_data = 0; string_count = 0; };
-/** if you want to keep the data, use this function to detach it from the RCommand (after reading the pointer with RCommand::getRealVector), so it won't be deleted with the RCommand */
-	void detachRealVector () { real_data = 0; real_count = 0; };
-/** if you want to keep the data, use this function to detach it from the RCommand (after reading the pointer with RCommand::getIntVector), so it won't be deleted with the RCommand */
-	void detachIntVector () { integer_data = 0; integer_count = 0; };
 /** return the flags associated with the command. Those are the same that you specified in the constructor, RKWard does not touch them. @see RCommand::RCommand */
 	int getFlags () { return (_flags); };
 /** Add an additional listener to the command */
@@ -219,12 +234,6 @@
 	void newOutput (ROutput *output);
 	QValueList<ROutput*> output_list;
 	QString _command;
-	QString *string_data;
-	int string_count;
-	double *real_data;
-	int real_count;
-	int *integer_data;
-	int integer_count;
 	int _type;
 	int _flags;
 	int status;

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -375,14 +375,14 @@
 }
 
 /** This function is the R side wrapper around stringsToStringList */
-QString *SEXPToStringList (SEXP from_exp, int *count) {
+QString *SEXPToStringList (SEXP from_exp, unsigned int *count) {
 	char **strings = 0;
 	
 	SEXP strexp;
 	PROTECT (strexp = coerceVector (from_exp, STRSXP));
 	*count = length (strexp);
 	strings = new char* [length (strexp)];
-	int i = 0;
+	unsigned int i = 0;
 	for (; i < *count; ++i) {
 		SEXP dummy = VECTOR_ELT (strexp, i);
 
@@ -405,7 +405,7 @@
 }
 
 SEXP doError (SEXP call) {
-	int count;
+	unsigned int count;
 	QString *strings = SEXPToStringList (call, &count);
 	REmbedInternal::this_pointer->handleError (strings, count);
 	deleteQStringArray (strings);
@@ -421,7 +421,7 @@
 } */
 
 SEXP doSubstackCall (SEXP call) {
-	int count;
+	unsigned int count;
 	QString *strings = SEXPToStringList (call, &count);
 	REmbedInternal::this_pointer->handleSubstackCall (strings, count);
 	deleteQStringArray (strings);
@@ -461,7 +461,6 @@
 // heavy copying from RServe below
 	int r_error = 0;
 	ParseStatus status = PARSE_NULL;
-	const char *c = command;
 	SEXP cv, pr, exp;
 
 	PROTECT(cv=allocVector(STRSXP, 1));
@@ -580,7 +579,7 @@
 	}
 }
 
-QString *REmbedInternal::getCommandAsStringVector (const char *command, int *count, RKWardRError *error) {	
+QString *REmbedInternal::getCommandAsStringVector (const char *command, uint *count, RKWardRError *error) {	
 	SEXP exp;
 	QString *list = 0;
 	
@@ -599,7 +598,7 @@
 	return list;
 }
 
-double *REmbedInternal::getCommandAsRealVector (const char *command, int *count, RKWardRError *error) {
+double *REmbedInternal::getCommandAsRealVector (const char *command, uint *count, RKWardRError *error) {
 	SEXP exp;
 	double *reals = 0;
 	
@@ -610,7 +609,7 @@
 		PROTECT (realexp = coerceVector (exp, REALSXP));
 		*count = length (realexp);
 		reals = new double[*count];
-		for (int i = 0; i < *count; ++i) {
+		for (unsigned int i = 0; i < *count; ++i) {
 			reals[i] = REAL (realexp)[i];
 			if (R_IsNaN (reals[i]) || R_IsNA (reals[i]) ) reals[i] = RKGlobals::na_double;
 		}
@@ -626,7 +625,7 @@
 	return reals;
 }
 
-int *REmbedInternal::getCommandAsIntVector (const char *command, int *count, RKWardRError *error) {
+int *REmbedInternal::getCommandAsIntVector (const char *command, uint *count, RKWardRError *error) {
 	SEXP exp;
 	int *integers = 0;
 	
@@ -637,7 +636,7 @@
 		PROTECT (intexp = coerceVector (exp, INTSXP));
 		*count = length (intexp);
 		integers = new int[*count];
-		for (int i = 0; i < *count; ++i) {
+		for (unsigned int i = 0; i < *count; ++i) {
 				integers[i] = INTEGER (intexp)[i];
 		}
 		UNPROTECT (1);	// intexp

Modified: trunk/rkward/rkward/rbackend/rembedinternal.h
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.h	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/rbackend/rembedinternal.h	2006-10-01 20:23:10 UTC (rev 783)
@@ -97,7 +97,7 @@
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of QString or 0 on failure
 @see RCommand::GetStringVector */
-	QString *getCommandAsStringVector (const char *command, int *count, RKWardRError *error);
+	QString *getCommandAsStringVector (const char *command, unsigned int *count, RKWardRError *error);
 /** basically a wrapper to runCommandInternal (). Tries to convert the result of the command to an array of double after running the command. Since
 this will not ever be done for user commands, the R_Visible flag will never be set. @see RCommand::GetRealVector
 @param command char* of the command to be run 
@@ -105,7 +105,7 @@
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of double or 0 on failure
 @see RCommand::GetRealVector */
-	double *getCommandAsRealVector (const char *command, int *count, RKWardRError *error);
+	double *getCommandAsRealVector (const char *command, unsigned int *count, RKWardRError *error);
 /** basically a wrapper to runCommandInternal (). Tries to convert the result of the command to an array of int after running the command. Since
 this will not ever be done for user commands, the R_Visible flag will never be set.  @see RCommand::GetIntVector
 @param command char* of the command to be run 
@@ -113,7 +113,7 @@
 @param error this will be set to a value in RKWardError depending on success/failure of the command
 @returns an array of int or 0 on failure
 @see RCommand::GetIntVector */
-	int *getCommandAsIntVector (const char *command, int *count, RKWardRError *error);
+	int *getCommandAsIntVector (const char *command, unsigned int *count, RKWardRError *error);
 public:
 /** call this periodically to make R's x11 windows process their events */
 	static void processX11Events ();

Modified: trunk/rkward/rkward/rbackend/rthread.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/rbackend/rthread.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -151,11 +151,14 @@
 		MUTEX_UNLOCK;
 	
 		if (ctype & RCommand::GetStringVector) {
-			command->string_data = getCommandAsStringVector (ccommand, &(command->string_count), &error);
+			command->datatype = RData::StringVector;
+			command->data = getCommandAsStringVector (ccommand, &(command->length), &error);
 		} else if (ctype & RCommand::GetRealVector) {
-			command->real_data = getCommandAsRealVector (ccommand, &(command->real_count), &error);
+			command->datatype = RData::RealVector;
+			command->data = getCommandAsRealVector (ccommand, &(command->length), &error);
 		} else if (ctype & RCommand::GetIntVector) {
-			command->integer_data = getCommandAsIntVector (ccommand, &(command->integer_count), &error);
+			command->datatype = RData::IntVector;
+			command->data = getCommandAsIntVector (ccommand, &(command->length), &error);
 		} else {
 			runCommandInternal (ccommand, &error, ctype & RCommand::User);
 		}
@@ -387,7 +390,7 @@
 	
 	runCommandInternal ("library (\"rkward\")\n", &error);
 	if (error) status |= LibLoadFail;
-	int c;
+	unsigned int c;
 	QString *paths = getCommandAsStringVector ("library.dynam (\"rkward\", \"rkward\")[[\"path\"]]\n", &c, &error);
 	if ((error) || (c != 1)) {
 		status |= LibLoadFail;
@@ -399,7 +402,7 @@
 // find out about standard library locations
 	QString *standardliblocs = getCommandAsStringVector (".libPaths ()\n", &c, &error);
 	if (error) status |= OtherFail;
-	for (int i = 0; i < c; ++i) {
+	for (unsigned int i = 0; i < c; ++i) {
 		RKSettingsModuleRPackages::defaultliblocs.append (standardliblocs[i]);
 	}
 	delete [] standardliblocs;

Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp	2006-10-01 19:03:29 UTC (rev 782)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp	2006-10-01 20:23:10 UTC (rev 783)
@@ -276,7 +276,7 @@
 	RK_TRACE (APP);
 
 	RK_ASSERT (command->getFlags () == RESTORE_WORKPLACE_COMMAND);
-	for (int i = 0; i < command->stringVectorLength (); ++i) {
+	for (unsigned int i = 0; i < command->getDataLength (); ++i) {
 		QString desc = command->getStringVector ()[i];
 		QString type = desc.section (QChar (':'), 0, 0);
 		QString specification = desc.section (QChar (':'), 1);


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