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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Sep 27 19:33:49 UTC 2006


Revision: 771
          http://svn.sourceforge.net/rkward/?rev=771&view=rev
Author:   tfry
Date:     2006-09-27 12:33:42 -0700 (Wed, 27 Sep 2006)

Log Message:
-----------
make findObject a recursive function, cause it is one

Modified Paths:
--------------
    trunk/rkward/rkward/core/rcontainerobject.cpp
    trunk/rkward/rkward/core/rcontainerobject.h
    trunk/rkward/rkward/core/robject.cpp
    trunk/rkward/rkward/core/robject.h
    trunk/rkward/rkward/core/robjectlist.cpp
    trunk/rkward/rkward/core/robjectlist.h

Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp	2006-09-27 17:12:10 UTC (rev 770)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp	2006-09-27 19:33:42 UTC (rev 771)
@@ -2,7 +2,7 @@
                           rcontainerobject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -159,6 +159,28 @@
 	return (it.data ());
 }
 
+RObject *RContainerObject::findObject (const QString &name, bool is_canonified) {
+	RK_TRACE (OBJECTS);
+
+	QString canonified = name;
+	if (!is_canonified) {
+		// yeah, ok, this could be made more efficient relatively easily ...
+		canonified = canonified.replace ("[\"", "$").replace ('[', "").replace ("\"]", "").replace (']', "");
+	}
+
+	// TODO: there could be objects with "$" in their names!
+	QString current_level = canonified.section (QChar ('$'), 0, 0);
+	QString remainder = canonified.section (QChar ('$'), 1);
+
+	RObjectMap::iterator it = childmap.find (current_level);
+	if (it == childmap.end ()) return 0;
+
+	RObject *found = it.data ();
+	if (remainder.isEmpty ()) return found;
+
+	return (found->findObject (remainder, true));
+}
+
 RObject *RContainerObject::createNewChild (const QString &name, RKEditor *creator, bool container, bool data_frame) {
 	RK_TRACE (OBJECTS);
 	RK_ASSERT (childmap.find (name) == childmap.end ());

Modified: trunk/rkward/rkward/core/rcontainerobject.h
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.h	2006-09-27 17:12:10 UTC (rev 770)
+++ trunk/rkward/rkward/core/rcontainerobject.h	2006-09-27 19:33:42 UTC (rev 771)
@@ -2,7 +2,7 @@
                           rcontainerobject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -56,6 +56,9 @@
 
 	/** given child_name, constructs a name which is as close as possible to the orginial but valid (i.e. not alreay in use, not contaning illegal characters */
 	QString validizeName (const QString &child_name);
+
+	/** reimplemented from RObject to actually search for the object */
+	RObject *findObject (const QString &name, bool is_canonified=false);
 private:
 	friend class RObject;
 	friend class RKVariable;

Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp	2006-09-27 17:12:10 UTC (rev 770)
+++ trunk/rkward/rkward/core/robject.cpp	2006-09-27 19:33:42 UTC (rev 771)
@@ -2,7 +2,7 @@
                           robject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -67,6 +67,11 @@
 	return getMetaProperty ("label");
 }
 
+RObject *RObject::findObject (const QString &, bool) {
+	RK_TRACE (OBJECTS);
+	return 0;
+}
+
 QString RObject::getMetaProperty (const QString &id) {
 	RK_TRACE (OBJECTS);
 	if (meta_map) {

Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h	2006-09-27 17:12:10 UTC (rev 770)
+++ trunk/rkward/rkward/core/robject.h	2006-09-27 19:33:42 UTC (rev 771)
@@ -2,7 +2,7 @@
                           robject  -  description
                              -------------------
     begin                : Thu Aug 19 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -119,6 +119,12 @@
 		int from_index;
 		int to_index;
 	};
+
+/** try to find the object as a child object of this object. Default implementation always returns 0, as this is not a container
+ at param name of the object (relative to this object)
+ at param is_canonified the object name may usually have to be canonified. Since this function may be called recursively, canonification may already have occured on a higher level. In this case the argument is set to true to avoid some duplicate work. When calling from outside always leave the default false.
+ at returns a pointer to the object (if found) or 0 if not found */
+	virtual RObject *findObject (const QString &name, bool is_canonified=false);
 protected:
 // why do I need those to compile? I thought they were derived classes!
 	friend class RContainerObject;

Modified: trunk/rkward/rkward/core/robjectlist.cpp
===================================================================
--- trunk/rkward/rkward/core/robjectlist.cpp	2006-09-27 17:12:10 UTC (rev 770)
+++ trunk/rkward/rkward/core/robjectlist.cpp	2006-09-27 19:33:42 UTC (rev 771)
@@ -2,7 +2,7 @@
                           robjectlist  -  description
                              -------------------
     begin                : Wed Aug 18 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -192,37 +192,4 @@
 	delete object;
 }
 
-RObject *RObjectList::findObject (const QString &full_name) {
-	RK_TRACE (OBJECTS);
-	
-	// yeah, ok, this could be made more efficient relatively easily ...
-	QString canonified = full_name;
-	canonified = canonified.replace ("[\"", "$").replace ('[', "").replace ("\"]", "").replace (']', "");
-	
-	QStringList list = QStringList::split ('$', canonified);
-	RContainerObject *cobject = this;
-	RObject *object = 0;
-	RObjectMap::iterator oit;
-	for (QStringList::iterator it = list.begin (); it != list.end ();) {
-		oit = cobject->childmap.find (*it);
-		if (oit == cobject->childmap.end ()) {
-			return 0;
-		}
-		object = oit.data ();
-		++it;
-		if (object->isContainer ()) {
-			cobject = static_cast<RContainerObject *> (object);
-	// found a non-container-object, although path is not finished
-		} else {
-			if (it != list.end ()) {
-				object = 0;
-				// end loop
-				it = list.end ();
-			}
-		}
-	}
-	
-	return object;
-}
-
 #include "robjectlist.moc"

Modified: trunk/rkward/rkward/core/robjectlist.h
===================================================================
--- trunk/rkward/rkward/core/robjectlist.h	2006-09-27 17:12:10 UTC (rev 770)
+++ trunk/rkward/rkward/core/robjectlist.h	2006-09-27 19:33:42 UTC (rev 771)
@@ -2,7 +2,7 @@
                           robjectlist  -  description
                              -------------------
     begin                : Wed Aug 18 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -39,11 +39,11 @@
 @author Thomas Friedrichsmeier
 */
 class RObjectList : public QObject, public RContainerObject {
-  Q_OBJECT
+	Q_OBJECT
 public:
-    RObjectList ();
+	RObjectList ();
+	~RObjectList ();
 
-    ~RObjectList ();
 	void updateFromR ();
 	
 	void createFromR (RContainerObject *parent, const QString &cname);
@@ -57,8 +57,6 @@
 	
 	void childUpdateComplete ();
 
-	RObject *findObject (const QString &full_name);
-	
 	KURL getWorkspaceURL () { return current_url; };
 public slots:
 	void timeout ();


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