[rkward-cvs] rkward/rkward/core rfunctionobject.cpp,NONE,1.1 rfunctionobject.h,NONE,1.1 Makefile.am,1.4,1.5 robject.h,1.23,1.24 robjectlist.cpp,1.26,1.27

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Apr 28 13:36:35 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12419/rkward/core

Modified Files:
	Makefile.am robject.h robjectlist.cpp 
Added Files:
	rfunctionobject.cpp rfunctionobject.h 
Log Message:
Adding first draft of RFunctionObject. Does not do much, yet, but seems to work ok

Index: robject.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/core/robject.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** robject.h	16 Mar 2006 22:31:07 -0000	1.23
--- robject.h	28 Apr 2006 13:36:33 -0000	1.24
***************
*** 43,47 ****
  /** 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 };
! 	#define ROBJECT_TYPE_INTERNAL_MASK (RObject::Container | RObject::Variable | RObject::Workspace)
  /** @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)); };
--- 43,47 ----
  /** 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 };
! 	#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)); };

Index: robjectlist.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/core/robjectlist.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** robjectlist.cpp	29 Mar 2006 15:35:28 -0000	1.26
--- robjectlist.cpp	28 Apr 2006 13:36:33 -0000	1.27
***************
*** 30,33 ****
--- 30,34 ----
  
  #include "rkvariable.h"
+ #include "rfunctionobject.h"
  
  #include "../rbackend/rinterface.h"
***************
*** 93,99 ****
  		PendingObject *pobj = pending_objects[command];
  		RObject *robj;
! 		// TODO: handle special types like functions, etc.!
  		if (command->getIntVector ()[0] == 1) {
  			robj = new RContainerObject (pobj->parent, pobj->name);
  		} else {
  			robj = new RKVariable (pobj->parent, pobj->name);
--- 94,102 ----
  		PendingObject *pobj = pending_objects[command];
  		RObject *robj;
! 		// TODO: handle more special types!
  		if (command->getIntVector ()[0] == 1) {
  			robj = new RContainerObject (pobj->parent, pobj->name);
+ 		} else if (command->getIntVector ()[0] == 2) {
+ 			robj = new RFunctionObject (pobj->parent, pobj->name);
  		} else {
  			robj = new RKVariable (pobj->parent, pobj->name);

Index: Makefile.am
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/core/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile.am	31 Aug 2004 22:13:36 -0000	1.4
--- Makefile.am	28 Apr 2006 13:36:33 -0000	1.5
***************
*** 2,5 ****
  METASOURCES = AUTO
  noinst_LIBRARIES =  libcore.a
! libcore_a_SOURCES = rkvariable.cpp robjectlist.cpp robject.cpp rcontainerobject.cpp rkmodificationtracker.cpp
! noinst_HEADERS = rkvariable.h robjectlist.h robject.h rcontainerobject.h rkmodificationtracker.h
--- 2,7 ----
  METASOURCES = AUTO
  noinst_LIBRARIES =  libcore.a
! libcore_a_SOURCES = rkvariable.cpp robjectlist.cpp robject.cpp rcontainerobject.cpp rkmodificationtracker.cpp \
! 	rfunctionobject.cpp
! noinst_HEADERS = rkvariable.h robjectlist.h robject.h rcontainerobject.h rkmodificationtracker.h \
! 	rfunctionobject.h

--- NEW FILE: rfunctionobject.h ---
/***************************************************************************
                          rfunctionobject  -  description
                             -------------------
    begin                : Wed Apr 26 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 RFUNCTION_H
#define RFUNCTION_H

#include "robject.h"

#include <qpair.h>
#include <qvaluelist.h>

class RCommand;

/**
Internal representation of function objects in the R workspace

@author Thomas Friedrichsmeier
*/

class RFunctionObject : public RObject {
public:
	RFunctionObject (RContainerObject *parent, const QString &name);
	~RFunctionObject ();

	void updateFromR ();
protected:
	void rCommandDone (RCommand *command);

	typedef QPair<QString, QString> FunctionArg;
	typedef QValueList<FunctionArg *> FunctionArguments;
	FunctionArguments function_args;
};

#endif

--- NEW FILE: rfunctionobject.cpp ---
/***************************************************************************
                          rfunctionobject  -  description
                             -------------------
    begin                : Wed Apr 26 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 "rfunctionobject.h"

#include "../rbackend/rinterface.h"
#include "robjectlist.h"
#include "../rkglobals.h"
#include "../debug.h"

#define CLASSIFY_COMMAND 1
#define UPDATE_ARGS_COMMAND 2

RFunctionObject::RFunctionObject (RContainerObject *parent, const QString &name) : RObject (parent, name) {
	RK_TRACE (OBJECTS);
	type = Function;
}

RFunctionObject::~RFunctionObject () {
	RK_TRACE (OBJECTS);
}

void RFunctionObject::updateFromR () {
	RK_TRACE (OBJECTS);

// TODO: move classification / type mismatch-checking to RObject
	RCommand *command = new RCommand (".rk.classify (" + getFullName () + ")", RCommand::App | RCommand::Sync | RCommand::GetIntVector, QString::null, this, CLASSIFY_COMMAND);
	RKGlobals::rInterface ()->issueCommand (command, RKGlobals::rObjectList()->getUpdateCommandChain ());
}

void RFunctionObject::rCommandDone (RCommand *command) {
	RK_TRACE (OBJECTS);

	bool dummy;
	if (command->getFlags () == CLASSIFY_COMMAND) {
		if (!handleClassifyCommand (command, &dummy)) {
			return; // will be deleted!
		}

		RCommand *command = new RCommand ("c (as.character (names (formals (" + getFullName () +"))), as.character (formals (" +getFullName () + ")))", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, UPDATE_ARGS_COMMAND);
		RKGlobals::rInterface ()->issueCommand (command, RKGlobals::rObjectList()->getUpdateCommandChain ());

	} else if (command->getFlags () == UPDATE_ARGS_COMMAND) {
		RK_ASSERT (command->stringVectorLength () % 2 == 0);

		function_args.clear ();
		for (int i = 0; i < command->stringVectorLength (); i += 2) {
			function_args.append (new FunctionArg (command->getStringVector ()[i], command->getStringVector ()[i+1]));
		}

		parent->childUpdateComplete ();
	}
}





More information about the rkward-tracker mailing list