[rkward-cvs] SF.net SVN: rkward: [776] trunk/rkward/rkward/core
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri Sep 29 12:44:56 UTC 2006
Revision: 776
http://svn.sourceforge.net/rkward/?rev=776&view=rev
Author: tfry
Date: 2006-09-29 05:44:47 -0700 (Fri, 29 Sep 2006)
Log Message:
-----------
Adding raw version of REnvironmentObject to allow access to environments other than .GlobalEnv. This is not yet integrated (or even compiled) in any way
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
Added Paths:
-----------
trunk/rkward/rkward/core/renvironmentobject.cpp
trunk/rkward/rkward/core/renvironmentobject.h
Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp 2006-09-28 14:29:41 UTC (rev 775)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp 2006-09-29 12:44:47 UTC (rev 776)
@@ -55,6 +55,13 @@
RKGlobals::rInterface ()->issueCommand (command, RKGlobals::rObjectList()->getUpdateCommandChain ());
}
+//virtual
+QString RContainerObject::listChildrenCommand () {
+ RK_TRACE (OBJECTS);
+
+ return ("names (" + getFullName () + ")");
+}
+
void RContainerObject::rCommandDone (RCommand *command) {
RK_TRACE (OBJECTS);
@@ -72,7 +79,7 @@
RCommand *command = new RCommand ("class (" + getFullName () + ")", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, UPDATE_CLASS_COMMAND);
RKGlobals::rInterface ()->issueCommand (command, RKGlobals::rObjectList()->getUpdateCommandChain ());
- command = new RCommand ("names (" + getFullName () + ")", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, UPDATE_CHILD_LIST_COMMAND);
+ command = new RCommand (listChildrenCommand (), RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, UPDATE_CHILD_LIST_COMMAND);
RKGlobals::rInterface ()->issueCommand (command, RKGlobals::rObjectList()->getUpdateCommandChain ());
if (properties_changed) RKGlobals::tracker ()->objectMetaChanged (this);
Modified: trunk/rkward/rkward/core/rcontainerobject.h
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.h 2006-09-28 14:29:41 UTC (rev 775)
+++ trunk/rkward/rkward/core/rcontainerobject.h 2006-09-29 12:44:47 UTC (rev 776)
@@ -30,9 +30,9 @@
class RContainerObject : public RObject {
public:
- RContainerObject(RContainerObject *parent, const QString &name);
+ RContainerObject (RContainerObject *parent, const QString &name);
- ~RContainerObject();
+ ~RContainerObject ();
void writeChildMetaData (RCommandChain *chain);
@@ -60,6 +60,8 @@
/** reimplemented from RObject to actually search for the object */
RObject *findObject (const QString &name, bool is_canonified=false);
+
+ virtual QString listChildrenCommand ();
private:
friend class RObject;
friend class RKVariable;
Added: trunk/rkward/rkward/core/renvironmentobject.cpp
===================================================================
--- trunk/rkward/rkward/core/renvironmentobject.cpp (rev 0)
+++ trunk/rkward/rkward/core/renvironmentobject.cpp 2006-09-29 12:44:47 UTC (rev 776)
@@ -0,0 +1,103 @@
+/***************************************************************************
+ renvironmentobject - description
+ -------------------
+ begin : Wed Sep 27 2006
+ copyright : (C) 2006 by Thomas Friedrichsmeier
+ email : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "renvironmentobject.h"
+
+#include "../debug.h"
+
+REnvironmentObject::REnvironmentObject (RContainerObject *parent, const QString &name) : RContainerObject (parent, name) {
+ RK_TRACE (OBJECTS);
+
+ type = Environment;
+ if (name == ".GlobalEnv") {
+ type |= GlobalEnv;
+ }
+
+ // TODO: determine namespace_name
+ // TODO: determine if this is an environment var (or maybe this is done from the parent)
+}
+
+REnvironmentObject::~REnvironmentObject () {
+ RK_TRACE (OBJECTS);
+}
+
+QString REnvironmentObject::getFullName () {
+ RK_TRACE (OBJECTS);
+
+ if (type & EnvironmentVar) return (parent->makeChildName (name));
+ return ("as.environment (\"" + name + "\")");
+}
+
+QString REnvironmentObject::makeChildName (const QString &short_child_name) {
+ RK_TRACE (OBJECTS);
+
+ if (type & GlobalEnv) return (short_child_name);
+ if (type & EnvironmentVar) return (name + "$" + short_child_name);
+ return (namespace_name + "::" + short_child_name);
+}
+
+void REnvironmentObject::writeMetaData (RCommandChain *chain) {
+ RK_TRACE (OBJECTS);
+
+ if (type & EnvironmentVar) RContainerObject::writeMetaData (chain);
+}
+
+QString REnvironmentObject::listChildrenCommand () {
+ RK_TRACE (OBJECTS);
+
+ return ("ls (as.environment (" + getFullName () + ", all.names=TRUE)");
+}
+
+void REnvironmentObject::renameChild (RObject *object, const QString &new_name) {
+ RK_TRACE (OBJECTS);
+
+ if (type & GlobalEnv) {
+ RObjectMap::iterator it = childmap.find (object->getShortName ());
+ RK_ASSERT (it.data () == object);
+
+ RCommand *command = new RCommand (makeChildName (new_name) + " <- " + object->getFullName ());
+ RKGlobals::rInterface ()->issueCommand (command, 0);
+ command = new RCommand ("remove (" + object->getFullName () + ")", RCommand::App | RCommand::Sync);
+ RKGlobals::rInterface ()->issueCommand (command, 0);
+
+ childmap.remove (it);
+ childmap.insert (new_name, object);
+
+ object->name = new_name;
+ } else {
+ RK_ASSERT (false);
+ }
+}
+
+void REnvironmentObject::removeChild (RObject *object, bool removed_in_workspace) {
+ RK_TRACE (OBJECTS);
+
+ if ((type & GlobalEnv) || removed_in_workspace) {
+ RObjectMap::iterator it = childmap.find (object->getShortName ());
+ RK_ASSERT (it.data () == object);
+
+ if (!removed_in_workspace) {
+ RCommand *command = new RCommand ("remove (" + object->getFullName () + ")", RCommand::App | RCommand::Sync);
+ RKGlobals::rInterface ()->issueCommand (command, 0);
+ }
+
+ childmap.remove (it);
+ delete object;
+ } else {
+ RK_ASSERT (false);
+ }
+}
Added: trunk/rkward/rkward/core/renvironmentobject.h
===================================================================
--- trunk/rkward/rkward/core/renvironmentobject.h (rev 0)
+++ trunk/rkward/rkward/core/renvironmentobject.h 2006-09-29 12:44:47 UTC (rev 776)
@@ -0,0 +1,74 @@
+/***************************************************************************
+ renvironmentobject - description
+ -------------------
+ begin : Wed Sep 27 2006
+ copyright : (C) 2006 by Thomas Friedrichsmeier
+ email : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef RENVIRONMENTOBJECT_H
+#define RENVIRONMENTOBJECT_H
+
+#include "rcontainerobject.h"
+
+class RCommand;
+class RCommandChain;
+
+/**
+This class roughly corresponds to an enviroment in R. It keeps a list of all objects in that environment.
+
+ at author Thomas Friedrichsmeier
+*/
+class REnvironmentObject : public RContainerObject {
+public:
+ REnvironmentObject (RContainerObject *parent, const QString &name);
+ ~REnvironmentObject ();
+
+ QString getFullName ();
+ QString makeChildName (const QString &short_child_name);
+/** reimplemented from RContainerObject: If this is an environment var, call RContainerObject::writeMetaData (). Else, do nothing. An environment has no meta data. */
+ void writeMetaData (RCommandChain *chain);
+
+ bool isGlobalEnv () { return (type & GlobalEnv); };
+
+ QString listChildrenCommand ();
+/**
+# search ()
+or rather
+# loadedNamespaces?! No, namespaces are evil! maybe rename to RKNamespaceObject? No. Let's deal with envirs for now.
+# ls (envir=as.environment ("package:base"))
+name is base::something
+
+How to deal with those names?
+You can't assign like this:
+envir::object <- something
+Probably it's best not to support assignments outside the .GlobalEnv at all.
+It's important to find out, when objects are masked, however. If they are, reading should return a full qualified name. Writing should return a simple name, to allow creation of a masking object in .GlobalEnv
+
+What should be the algorithm?
+1) Maybe we should always return the full qualified name.
+2) When editing an object in any other env, *first* (suggest to?) make a copy to the .GlobalEnv, and edit that copy
+3) Essentially objects in any other environment remain read-only
+
+4) check whether objects are masked, and warn when viewing / editing (only needed for objects outside the global env)
+
+RContainerObject::findObjectsMatching (...) for code completion popups
+RContainerObject::canonifyName
+*/
+protected:
+/** reimplemented from RContainerObject to raise an assert if this is not the isGlobalEnv (). Otherwise calls "remove (objectname)" instead of objectname <- NULL" */
+ void renameChild (RObject *object, const QString &new_name);
+/** reimplemented from RContainerObject to raise an assert if this is not the isGlobalEnv (). Otherwise calls "remove (objectname)" instead of objectname <- NULL" */
+ void removeChild (RObject *object, bool removed_in_workspace);
+ QString namespace_name;
+};
+
+#endif
Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp 2006-09-28 14:29:41 UTC (rev 775)
+++ trunk/rkward/rkward/core/robject.cpp 2006-09-29 12:44:47 UTC (rev 776)
@@ -355,7 +355,7 @@
RK_TRACE (OBJECTS);
// TODO: only for now! Currently only a single editor may operate on an object
- RK_ASSERT (!data)
+ RK_ASSERT (!data);
if (!data) {
allocateEditData ();
Modified: trunk/rkward/rkward/core/robject.h
===================================================================
--- trunk/rkward/rkward/core/robject.h 2006-09-28 14:29:41 UTC (rev 775)
+++ trunk/rkward/rkward/core/robject.h 2006-09-29 12:44:47 UTC (rev 776)
@@ -41,7 +41,7 @@
virtual ~RObject ();
/** types of objects, RKWard knows about */
- enum RObjectType { DataFrame=1, Matrix=2, Array=4, List=8, Container=16, Variable=32, Workspace=64, Function=128, HasMetaObject=256 };
+ enum RObjectType { DataFrame=1, Matrix=2, Array=4, List=8, Container=16, Variable=32, Workspace=64, Function=128, Environment=256, GlobalEnv=512, EnvironmentVar=1024, HasMetaObject=2048 };
#define ROBJECT_TYPE_INTERNAL_MASK (RObject::Container | RObject::Variable | RObject::Workspace | RObject::Function)
/** @returns false if an object of the given old type cannot represent an object of the given new type (e.g. (new_type & RObjectType::Variable), but (old_type & RObjectType::Container)). */
static bool isMatchingType (int old_type, int new_type) { return ((old_type & ROBJECT_TYPE_INTERNAL_MASK) == (new_type & ROBJECT_TYPE_INTERNAL_MASK)); };
@@ -63,6 +63,15 @@
bool isType (int type) { return (RObject::type & type); };
bool hasMetaObject () { return (type & HasMetaObject); };
+/* Is the object writable? Recurses upwards to find any locked environments/bindings TODO */
+// virtual bool isWriteAble ();
+// virtual bool isRemovable ();
+/* @returns 0 if the object is not masked, else the *highest* environment masking the object (i.e. preferentially the .GlobalEnv */
+// virtual REnvironmentObject *findMaskingEnvironment ();
+/* Is the object inside the global env? Else we better not support writing to it TODO*/
+// virtual bool isInGlobalEnv ();
+// virtual REnvironmentObject *parentEnvironment ();
+
void rename (const QString &new_short_name);
void remove (bool removed_in_workspace);
Modified: trunk/rkward/rkward/core/robjectlist.cpp
===================================================================
--- trunk/rkward/rkward/core/robjectlist.cpp 2006-09-28 14:29:41 UTC (rev 775)
+++ trunk/rkward/rkward/core/robjectlist.cpp 2006-09-29 12:44:47 UTC (rev 776)
@@ -111,6 +111,12 @@
// TODO: signal change
}
+QString RObjectList::listChildrenCommand () {
+ RK_TRACE (OBJECTS);
+
+ return ("ls (all.names=TRUE)");
+}
+
void RObjectList::updateFromR () {
RK_TRACE (OBJECTS);
if (update_chain) {
@@ -123,7 +129,7 @@
emit (updateStarted ());
update_chain = RKGlobals::rInterface ()->startChain (0);
- RCommand *command = new RCommand ("ls (all.names=TRUE)", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, UPDATE_LIST_COMMAND);
+ RCommand *command = new RCommand (listChildrenCommand (), RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, UPDATE_LIST_COMMAND);
RKGlobals::rInterface ()->issueCommand (command, update_chain);
}
Modified: trunk/rkward/rkward/core/robjectlist.h
===================================================================
--- trunk/rkward/rkward/core/robjectlist.h 2006-09-28 14:29:41 UTC (rev 775)
+++ trunk/rkward/rkward/core/robjectlist.h 2006-09-29 12:44:47 UTC (rev 776)
@@ -56,6 +56,7 @@
RCommandChain *getUpdateCommandChain () { return update_chain; };
void childUpdateComplete ();
+ QString listChildrenCommand ();
KURL getWorkspaceURL () { return current_url; };
public slots:
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