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

tfry at users.sf.net tfry at users.sf.net
Wed Jan 23 18:44:08 UTC 2013


Revision: 4502
          http://sourceforge.net/p/rkward/code/4502
Author:   tfry
Date:     2013-01-23 18:43:50 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
Implement basic handling of dependencies on the version of RKWard itself.
No useful error reporting, and no handling of alternative versions, yet.
Other dependencies are parsed, but never used, so far.

Modified Paths:
--------------
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp
    trunk/rkward/rkward/plugin/rkcomponentmap.h
    trunk/rkward/rkward/plugins/import_export.pluginmap

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2013-01-23 18:42:10 UTC (rev 4501)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2013-01-23 18:43:50 UTC (rev 4502)
@@ -170,6 +170,8 @@
 		delete (it.value ());
 	}
 	pluginmapfiles.clear ();
+	component_attributes.clear ();
+	component_dependencies.clear ();
 
 	clearGUIDescription ();
 
@@ -375,8 +377,18 @@
 	list = xml->getChildElements (element, "component", DL_INFO);
 
 	for (XMLChildList::const_iterator it=list.begin (); it != list.end (); ++it) {
+		QString id = cnamespace + xml->getStringAttribute((*it), "id", QString::null, DL_WARNING);
+
+		// check dependencies, first
+		QDomElement cdependencies = xml->getChildElement (*it, "dependencies", DL_INFO);
+		if (!cdependencies.isNull ()) {
+			if (!RKComponentDependency::isRKWardVersionCompatible (cdependencies)) {
+				RK_DEBUG (PLUGIN, DL_INFO, "Skipping component '%s': Not compatible with this version of RKWard", qPrintable (id));
+				continue;
+			}
+		}
+
 		QString filename = xml->getStringAttribute((*it), "file", QString::null, DL_WARNING);
-		QString id = cnamespace + xml->getStringAttribute((*it), "id", QString::null, DL_WARNING);
 		int type = xml->getMultiChoiceAttribute ((*it), "type", "standard", 0, DL_WARNING);
 		QString label = xml->getStringAttribute ((*it), "label", i18n ("(no label)"), DL_WARNING);
 
@@ -391,6 +403,7 @@
 			for (XMLChildList::const_iterator ait=attributes_list.begin (); ait != attributes_list.end (); ++ait) {
 				handle->addAttribute (xml->getStringAttribute (*ait, "id", "noid", DL_WARNING), xml->getStringAttribute (*ait, "value", QString::null, DL_ERROR), xml->getStringAttribute (*ait, "label", QString::null, DL_ERROR));
 			}
+			if (!cdependencies.isNull ()) handle->addDependencies (RKComponentDependency::parseDependencies (cdependencies));
 			components.insert (id, handle);
 		}
 	}
@@ -441,14 +454,11 @@
 	RKComponentHandle::label = label;
 	RKComponentHandle::plugin_map = pluginmap;
 
-	attributes = 0;
 	is_accessible = false;
 }
 
 RKComponentHandle::~RKComponentHandle () {
 	RK_TRACE (PLUGIN);
-
-	delete attributes;
 }
 
 bool RKComponentHandle::isPlugin () {
@@ -474,38 +484,43 @@
 QString RKComponentHandle::getAttributeValue (const QString &attribute_id) {
 	RK_TRACE (PLUGIN);
 
-	if (!attributes) return QString ();
-	AttributeMap::const_iterator it = attributes->find (attribute_id);
-	if (it == attributes->constEnd ()) return QString ();
-	return ((*it).first);
+	QMap<QString, RKComponentMap::AttributeValueMap>::const_iterator it = RKComponentMap::getMap ()->component_attributes.find (attribute_id);
+	if (it == RKComponentMap::getMap ()->component_attributes.constEnd ()) return QString ();
+	return (*it).valuemap.value (this);
 }
 
 QString RKComponentHandle::getAttributeLabel (const QString &attribute_id) {
 	RK_TRACE (PLUGIN);
 
-	if (!attributes) return QString ();
-	AttributeMap::const_iterator it = attributes->find (attribute_id);
-	if (it == attributes->constEnd ()) return QString ();
-	return ((*it).second);
+	QMap<QString, RKComponentMap::AttributeValueMap>::const_iterator it = RKComponentMap::getMap ()->component_attributes.find (attribute_id);
+	if (it == RKComponentMap::getMap ()->component_attributes.constEnd ()) return QString ();
+	return (*it).labelmap.value (this);
 }
 
-bool RKComponentHandle::hasAttribute (const QString &attribute_id) {
+void RKComponentHandle::addAttribute (const QString &id, const QString &value, const QString &label) {
 	RK_TRACE (PLUGIN);
 
-	if (!attributes) return false;
-	return (attributes->contains (attribute_id));
+	RKComponentMap::AttributeValueMap & map = RKComponentMap::getMap ()->component_attributes[id];	// NOTE: auto-created, if needed
+	map.valuemap.insert (this, value);
+	map.labelmap.insert (this, label);
 }
 
-void RKComponentHandle::addAttribute (const QString &id, const QString &value, const QString &label) {
+void RKComponentHandle::addDependencies (const QList<RKComponentDependency>& deps) {
+	if (deps.isEmpty ()) return;
 	RK_TRACE (PLUGIN);
 
-	if (!attributes) {
-		attributes = new AttributeMap;
-	}
-	AttributeValue value_p (value, label);
-	attributes->insert (id, value_p);
+	RKComponentMap::getMap ()->component_dependencies[this].append (deps);
 }
 
+QList <RKComponentDependency> RKComponentHandle::getDependencies () {
+	RK_TRACE (PLUGIN);
+
+	QList <RKComponentDependency> ret = plugin_map->getDependencies ();
+	QHash<RKComponentHandle*, QList<RKComponentDependency> >::const_iterator it = RKComponentMap::getMap ()->component_dependencies.find (this);
+	if (it == RKComponentMap::getMap ()->component_dependencies.constEnd ()) return ret;
+	return (ret + (*it));
+}
+
 ///########################### END RKComponentHandle ###############################
 
 #include "rkcomponentmap.moc"

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.h	2013-01-23 18:42:10 UTC (rev 4501)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.h	2013-01-23 18:43:50 UTC (rev 4502)
@@ -30,6 +30,7 @@
 
 	QString getBaseDir () { return basedir; };
 	QString makeFileName (const QString &filename);
+	QList<RKComponentDependency> getDependencies () { return dependencies; };
 private:
 friend class RKComponentMap;
 	QString basedir;
@@ -70,9 +71,13 @@
 
 	RKStandardComponent *invoke (RKComponent *parent_component, QWidget *parent_widget);
 
+/** Gets the dependencies of this plugin. This *includes* the dependencies of the parent pluginmap */
+	QList<RKComponentDependency> getDependencies ();
+/** Adds dependencies for this plugin. */
+	void addDependencies (const QList<RKComponentDependency> & deps);
+
 	QString getAttributeValue (const QString &attribute_id);
 	QString getAttributeLabel (const QString &attribute_id);
-	bool hasAttribute (const QString &attribute_id);
 	void addAttribute (const QString &id, const QString &value, const QString &label);
 	void setAccessible (bool accessible) { is_accessible = accessible; };
 /** Returns whether this component is accessible from the menu, somewhere (else it might be in a context) */
@@ -87,10 +92,6 @@
 	QString filename;
 	QString label;
 	RKComponentType type;
-
-	typedef QPair<QString, QString> AttributeValue;
-	typedef QMap<QString, AttributeValue> AttributeMap;
-	AttributeMap *attributes;
 private:
 	bool is_accessible;
 };
@@ -206,6 +207,16 @@
 	PluginMapFileMap pluginmapfiles;
 
 	static RKComponentMap *component_map;
+friend class RKComponentHandle;
+	// most components have neither attributes specific dependencies (other than dependencies shared by all plugins in a pluginmap).
+	// therefore, it saves a few bytes to store attributes and specific dependencies in a central map, rather than keeping structures
+	// per plugin
+	struct AttributeValueMap {
+		QHash<RKComponentHandle*, QString> valuemap;
+		QHash<RKComponentHandle*, QString> labelmap;
+	};
+	QMap<QString, AttributeValueMap> component_attributes;
+	QHash<RKComponentHandle*, QList<RKComponentDependency> > component_dependencies;
 protected:
 	void addedEntry (const QString &id, RKComponentHandle *handle);
 };

Modified: trunk/rkward/rkward/plugins/import_export.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/import_export.pluginmap	2013-01-23 18:42:10 UTC (rev 4501)
+++ trunk/rkward/rkward/plugins/import_export.pluginmap	2013-01-23 18:43:50 UTC (rev 4502)
@@ -2,17 +2,13 @@
 
 <document base_prefix="00saveload/" namespace="rkward">
 
-	<about>
-		<!-- "save_r" needs at least R 2.10 for bzip2/xz compression -->
-		<dependencies R_min_version="2.10.0">
-		</dependencies>
-	</about>
-
 	<components>
 		<component type="standard" id="load_r_object" file="import/load_data.xml" label="Load R data file" />
 		<component type="standard" id="load_source" file="import/source.xml" label="Source an R file" />
 
-		<component type="standard" id="save_r" file="save/save.xml" label="Save objects as R data" />
+		<component type="standard" id="save_r" file="save/save.xml" label="Save objects as R data">
+			<dependencies R_min_version="2.10.0"/> <!-- "save_r" needs at least R 2.10 for bzip2/xz compression -->
+		</component>
 		<component type="standard" id="save_skeleton" file="save/skeleton/description.xml" label="Create package skeleton" />
 		<component type="standard" id="save_variables" file="save/write.xml" label="Export vector or matrix data" />
 		<component type="standard" id="save_table" file="save/write_table.xml" label="Export tabular data" />





More information about the rkward-tracker mailing list