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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Mar 3 12:28:36 UTC 2011


Revision: 3463
          http://rkward.svn.sourceforge.net/rkward/?rev=3463&view=rev
Author:   tfry
Date:     2011-03-03 12:28:35 +0000 (Thu, 03 Mar 2011)

Log Message:
-----------
Cleanups (simplify handling of meta data)

Modified Paths:
--------------
    trunk/rkward/rkward/core/robject.cpp
    trunk/rkward/rkward/core/robject.h
    trunk/rkward/rkward/rbackend/rkstructuregetter.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2011-03-03 11:42:36 UTC (rev 3462)
+++ trunk/rkward/rkward/core/robject.cpp	2011-03-03 12:28:35 UTC (rev 3463)
@@ -87,22 +87,15 @@
 
 QString RObject::getMetaProperty (const QString &id) const {
 	RK_TRACE (OBJECTS);
-	if (meta_map) {
-		RObject::MetaMap::iterator it;
-		if ((it = meta_map->find (id)) != meta_map->end ()) {
-			return (it.value ());
-		}
-	}
+	if (meta_map) return (meta_map->value (id));
 	return QString ();
 }
 
 QString RObject::getDescription () const {
 	RK_TRACE (OBJECTS);
 	if (meta_map) {
-		RObject::MetaMap::iterator it;
-		if ((it = meta_map->find ("label")) != meta_map->end ()) {
-			return (getShortName () + " (" + it.value () + ')');
-		}
+		QString label = meta_map->value ("label");
+		if (!label.isEmpty ()) return (getShortName () + " (" + label + ')');
 	}
 	return getShortName ();;
 }
@@ -162,28 +155,15 @@
 void RObject::setMetaProperty (const QString &id, const QString &value, bool sync) {
 	RK_TRACE (OBJECTS);
 	if (value.isEmpty ()) {
-		if (meta_map) {
-			meta_map->remove (id);
-			if (!meta_map->size ()) {
-				delete meta_map;
-				meta_map = 0;
-				type -= (type & HasMetaObject);
-			}
-		}
-		RKGlobals::tracker ()->objectMetaChanged (this);
-		return;
-	}
-	
-	if (meta_map) {
-		RObject::MetaMap::iterator it;
-		if ((it = meta_map->find (id)) != meta_map->end ()) {
-			if (it.value () == value) return;
-		}
+		if (meta_map && meta_map->contains (id)) meta_map->remove (id);
+		else return;
 	} else {
-		meta_map = new MetaMap;
+		if (!meta_map) meta_map = new MetaMap;
+		else if (meta_map->value (id) == value) return;
+
+		meta_map->insert (id, value);
 	}
 
-	meta_map->insert (id, value);
 	if (sync) writeMetaData (0);
 	RKGlobals::tracker ()->objectMetaChanged (this);
 }
@@ -211,29 +191,25 @@
 
 void RObject::writeMetaData (RCommandChain *chain) {
 	RK_TRACE (OBJECTS);
-	
-	if (!meta_map) {
-		if (hasMetaObject ()) {
-			RCommand *command = new RCommand ("attr (" + getFullName () + ", \".rk.meta\") <- NULL", RCommand::App | RCommand::Sync);
-			RKGlobals::rInterface ()->issueCommand (command, chain);
+
+	if (!meta_map) return;
+
+	QString map_string;
+	if (meta_map->isEmpty ()) {
+		map_string.append ("NULL");
+
+		delete meta_map;	// now that is is synced, delete it
+		meta_map = 0;
+	} else {
+		for (MetaMap::const_iterator it = meta_map->constBegin (); it != meta_map->constEnd (); ++it) {
+			if (!map_string.isEmpty ()) map_string.append (", ");
+			map_string.append (rQuote (it.key ()) + '=' + rQuote (it.value ()));
 		}
-		type -= (type & HasMetaObject);
-		return;
+		map_string = "c (" + map_string + ')';
 	}
-	
-	QString command_string = ".rk.set.meta (" + getFullName () + ", c (";
-	for (MetaMap::const_iterator it = meta_map->constBegin (); it != meta_map->constEnd (); ++it) {
-		if (it != meta_map->constBegin ()) {
-			command_string.append (", ");
-		}
-		command_string.append (rQuote (it.key ()) + '=' + rQuote (it.value ()));
-	}
-	command_string.append ("))");
-	
-	RCommand *command = new RCommand (command_string, RCommand::App | RCommand::Sync);
+
+	RCommand *command = new RCommand (".rk.set.meta (" + getFullName () + ", " + map_string + ')', RCommand::App | RCommand::Sync);
 	RKGlobals::rInterface ()->issueCommand (command, chain);
-	
-	type |= HasMetaObject;
 }
 
 void RObject::updateFromR (RCommandChain *chain) {
@@ -419,11 +395,10 @@
 	RK_ASSERT (new_data->getDataType () == RData::StringVector);
 
 	unsigned int len = new_data->getDataLength ();
-	if (len == 1) len = 0;		// if it's a single element, it's just a dummy
 	bool change = false;
 	if (len) {
 		if (!meta_map) meta_map = new MetaMap;
-		meta_map->clear ();
+		else meta_map->clear ();
 
 		RK_ASSERT (!(len % 2));
 		unsigned int cut = len/2;
@@ -431,7 +406,6 @@
 			meta_map->insert (new_data->getStringVector ()[i], new_data->getStringVector ()[i+cut]);
 		}
 
-		type |= HasMetaObject;
 		// TODO: only signal change, if there really was a change!
 		change = true;
 	} else {		// no meta data received
@@ -440,8 +414,6 @@
 			meta_map = 0;
 			change = true;
 		}
-
-		type -= (type & HasMetaObject);
 	}
 	return change;
 }

Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h	2011-03-03 11:42:36 UTC (rev 3462)
+++ trunk/rkward/rkward/core/robject.h	2011-03-03 12:28:35 UTC (rev 3463)
@@ -56,12 +56,11 @@
 		GlobalEnv=1 << 9,
 		ToplevelEnv=1 << 10,
 		PackageEnv=1 << 11,
-		HasMetaObject=1 << 12,
-		Misplaced=1 << 13,		/** < the object is not in the namespace where it would be expected */
-		Numeric=1 << 14,
-		Factor=2 << 14,
-		Character=3 << 14,
-		Logical=4 << 14,
+		Misplaced=1 << 12,		/** < the object is not in the namespace where it would be expected */
+		Numeric=1 << 13,
+		Factor=2 << 13,
+		Character=3 << 13,
+		Logical=4 << 13,
 		DataTypeMask=Numeric | Factor | Character | Logical,
 		Updating=1 << 27, /** < The object is about to be updated from R */
 		Incomplete=1 << 28,	/** < The information on this object is not complete (typically, it's children have not been scanned, yet). */
@@ -100,7 +99,7 @@
 	bool isVariable () const { return (type & Variable); };
 	/** see RObjectType */
 	bool isType (int type) const { return (RObject::type & type); };
-	bool hasMetaObject () const { return (type & HasMetaObject); };
+	bool hasMetaObject () const { return (meta_map); };
 	/** see RObjectType::Pending */
 	bool isPending () const { return type & Pending; };
 
@@ -148,10 +147,10 @@
 
 	RDataType getDataType () const { return (typeToDataType (type)); };
 	int getType () const { return type; };
-	static RDataType typeToDataType (int ftype) { return ((RDataType) ((ftype & DataTypeMask) >> 14)); };
+	static RDataType typeToDataType (int ftype) { return ((RDataType) ((ftype & DataTypeMask) >> 13)); };
 	void setDataType (RDataType new_type) {
 		int n_type = type - (type & DataTypeMask);
-		type = n_type + (new_type << 14);
+		type = n_type + (new_type << 13);
 	};
 /** returns a textual representation of the given RDataType */
 	static QString typeToText (RDataType);

Modified: trunk/rkward/rkward/rbackend/rkstructuregetter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkstructuregetter.cpp	2011-03-03 11:42:36 UTC (rev 3462)
+++ trunk/rkward/rkward/rbackend/rkstructuregetter.cpp	2011-03-03 12:28:35 UTC (rev 3463)
@@ -248,14 +248,12 @@
 	// get meta data, if any
 	RData *metadata = new RData;
 	if (!Rf_isNull (Rf_getAttrib (value, meta_attrib))) {
-		type |= RObject::HasMetaObject;
-
 		SEXP meta_s = RKRSupport::callSimpleFun (get_meta_fun, value, R_GlobalEnv);
 		PROTECT (meta_s);
 		metadata->setData (RKRSupport::SEXPToStringList (meta_s));
 		UNPROTECT (1);	/* meta_s */
 	} else {
-		metadata->setData (QStringList (QString ("")));
+		metadata->setData (QStringList ());
 	}
 
 	// store type

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-03-03 11:42:36 UTC (rev 3462)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-03-03 12:28:35 UTC (rev 3463)
@@ -249,7 +249,7 @@
 	eval (substitute (x <- y), envir=envir)
 }
 
-".rk.get.structure.new" <- function (x, name, envlevel=0, namespacename=NULL) {
+".rk.get.structure" <- function (x, name, envlevel=0, namespacename=NULL) {
 	.Call ("rk.get.structure", x, as.character (name), as.integer (envlevel), namespacename)
 }
 
@@ -257,8 +257,6 @@
 	tryCatch (asNamespace (name), error = function(e) NULL)
 }
 
-".rk.get.structure" <- .rk.get.structure.new
-
 ".rk.get.structure.global" <- function (name, envlevel=0, namespacename=NULL) {
 	.Call ("rk.get.structure.global", as.character (name), as.integer (envlevel), namespacename)
 }


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