[rkward-cvs] SF.net SVN: rkward:[3996] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Tue Oct 25 10:19:32 UTC 2011
Revision: 3996
http://rkward.svn.sourceforge.net/rkward/?rev=3996&view=rev
Author: tfry
Date: 2011-10-25 10:19:32 +0000 (Tue, 25 Oct 2011)
Log Message:
-----------
Change RData data getters to make it easier to write safe code. Also make the getters inlineable and const.
We might want to return references, instead, again, later.
Modified Paths:
--------------
trunk/rkward/rkward/core/rcontainerobject.cpp
trunk/rkward/rkward/core/renvironmentobject.cpp
trunk/rkward/rkward/core/rfunctionobject.cpp
trunk/rkward/rkward/core/rkvariable.cpp
trunk/rkward/rkward/core/robject.cpp
trunk/rkward/rkward/core/robjectlist.cpp
trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
trunk/rkward/rkward/rbackend/rdata.cpp
trunk/rkward/rkward/rbackend/rdata.h
trunk/rkward/rkward/rbackend/rinterface.cpp
trunk/rkward/rkward/rbackend/rkrbackend.cpp
trunk/rkward/rkward/rbackend/rktransmitter.cpp
trunk/rkward/rkward/settings/rksettingsmoduler.cpp
trunk/rkward/rkward/windows/rkhelpsearchwindow.cpp
Modified: trunk/rkward/rkward/core/rcontainerobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rcontainerobject.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/core/rcontainerobject.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -64,10 +64,10 @@
int child_index = childmap.indexOf (child);
RK_ASSERT (child_index >= 0);
if (RKGlobals::tracker ()->removeObject (child, 0, true)) {
- RData *child_name_data = new_data->getStructureVector ()[StoragePositionName];
+ RData *child_name_data = new_data->structureVector ().at (StoragePositionName);
RK_ASSERT (child_name_data->getDataType () == RData::StringVector);
RK_ASSERT (child_name_data->getDataLength () >= 1);
- QString child_name = child_name_data->getStringVector ()[0];
+ QString child_name = child_name_data->stringVector ().at (0);
return (createChildFromStructure (new_data, child_name, child_index));
} else {
@@ -88,7 +88,7 @@
if (data_length > StorageSizeBasicInfo) {
RK_ASSERT (data_length == (StorageSizeBasicInfo + 1));
- RData *children_sub = new_data->getStructureVector ()[StoragePositionChildren];
+ RData *children_sub = new_data->structureVector ().at (StoragePositionChildren);
RK_ASSERT (children_sub->getDataType () == RData::StructureVector);
updateChildren (children_sub);
updateRowNamesObject ();
@@ -104,11 +104,11 @@
RK_ASSERT (child_data->getDataType () == RData::StructureVector);
RK_ASSERT (child_data->getDataLength () >= (StoragePositionType + 1)); // need to see at least the type at this point
- RData *type_data = child_data->getStructureVector ()[StoragePositionType];
+ RData *type_data = child_data->structureVector ().at (StoragePositionType);
RK_ASSERT (type_data->getDataType () == RData::IntVector);
RK_ASSERT (type_data->getDataLength () == 1);
- int child_type = type_data->getIntVector ()[0];
+ int child_type = type_data->intVector ().at (0);
RObject *child_object;
if (child_type & RObject::Environment) {
@@ -147,14 +147,15 @@
// first find out, which children are now available, copy the old ones, create the new ones
RObjectMap new_childmap, old_childmap;
old_childmap = childmap;
+ RData::RDataStorage nc_data = new_children->structureVector ();
for (unsigned int i = 0; i < new_child_count; ++i) {
- RData *child_data = new_children->getStructureVector ()[i];
+ RData *child_data = nc_data.at (i);
RK_ASSERT (child_data->getDataType () == RData::StructureVector);
RK_ASSERT (child_data->getDataLength () >= (StoragePositionName + 1));
- RData *child_name_data = child_data->getStructureVector ()[StoragePositionName];
+ RData *child_name_data = child_data->structureVector ().at (StoragePositionName);
RK_ASSERT (child_name_data->getDataType () == RData::StringVector);
RK_ASSERT (child_name_data->getDataLength () >= 1);
- QString child_name = child_name_data->getStringVector ()[0];
+ QString child_name = child_name_data->stringVector ().at (0);
RObject *child_object = 0;
for (int j = 0; j < old_childmap.size (); ++j) {
Modified: trunk/rkward/rkward/core/renvironmentobject.cpp
===================================================================
--- trunk/rkward/rkward/core/renvironmentobject.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/core/renvironmentobject.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -154,15 +154,16 @@
if (!RObject::updateStructure (new_data)) return false;
}
+ RData::RDataStorage new_data_data = new_data->structureVector ();
if (new_data->getDataLength () > StorageSizeBasicInfo) {
- RData *children_sub = new_data->getStructureVector ()[StoragePositionChildren];
+ RData *children_sub = new_data_data.at (StoragePositionChildren);
RK_ASSERT (children_sub->getDataType () == RData::StructureVector);
updateChildren (children_sub);
// a namespace to go with that?
if (new_data->getDataLength () > (StorageSizeBasicInfo + 1)) {
RK_ASSERT (new_data->getDataLength () == (StorageSizeBasicInfo + 2));
- updateNamespace (new_data->getStructureVector ()[StoragePositionNamespace]);
+ updateNamespace (new_data_data.at (StoragePositionNamespace));
} else updateNamespace (0);
} else {
RK_ASSERT (false);
@@ -187,7 +188,7 @@
added = true;
RKGlobals::tracker ()->lockUpdates (true);
}
- namespace_envir->updateStructure (new_data->getStructureVector ()[0]);
+ namespace_envir->updateStructure (new_data->structureVector ().at (0));
if (added) {
RKGlobals::tracker ()->lockUpdates (false);
Modified: trunk/rkward/rkward/core/rfunctionobject.cpp
===================================================================
--- trunk/rkward/rkward/core/rfunctionobject.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/core/rfunctionobject.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -63,14 +63,9 @@
RK_ASSERT (new_data->getDataLength () == (StoragePositionFunValues + 1));
RK_ASSERT (new_data->getDataType () == RData::StructureVector);
- RData *argnames_data = new_data->getStructureVector ()[StoragePositionFunArgs];
- RData *argvalues_data = new_data->getStructureVector ()[StoragePositionFunValues];
-
- RK_ASSERT (argnames_data->getDataType () == RData::StringVector);
- RK_ASSERT (argvalues_data->getDataType () == RData::StringVector);
-
- QStringList new_argnames = argnames_data->getStringVector ();
- QStringList new_argvalues = argvalues_data->getStringVector ();
+ RData::RDataStorage new_data_data = new_data->structureVector ();
+ QStringList new_argnames = new_data_data.at (StoragePositionFunArgs)->stringVector ();
+ QStringList new_argvalues = new_data_data.at (StoragePositionFunValues)->stringVector ();
RK_ASSERT (new_argnames.size () == new_argvalues.size ());
if ((new_argnames != argnames) || (new_argvalues != argvalues)) {
Modified: trunk/rkward/rkward/core/rkvariable.cpp
===================================================================
--- trunk/rkward/rkward/core/rkvariable.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/core/rkvariable.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -127,21 +127,23 @@
RK_ASSERT (command->getDataType () == RData::StructureVector);
RK_ASSERT (command->getDataLength () == 3);
- RData *cdata = command->getStructureVector ()[0];
- RData *levels = command->getStructureVector ()[1];
- RData *invalids = command->getStructureVector ()[2];
+ RData::RDataStorage top = command->structureVector ();
+ RData *cdata = top.at (0);
+ RData *levels = top.at (1);
+ RData *invalids = top.at (2);
// set factor levels first
RK_ASSERT (levels->getDataType () == RData::StringVector);
- unsigned int levels_len = levels->getDataLength ();
+ QStringList new_levels = levels->stringVector ();
+ int levels_len = new_levels.size ();
RK_ASSERT (levels_len >= 1);
delete data->value_labels;
data->value_labels = new RObject::ValueLabels;
- if ((levels_len == 1) && levels->getStringVector ()[0].isEmpty ()) {
+ if ((levels_len == 1) && new_levels.at (0).isEmpty ()) {
// no levels
} else {
- for (unsigned int i=0; i < levels_len; ++i) {
- data->value_labels->insert (QString::number (i+1), levels->getStringVector ()[i]);
+ for (int i=0; i < levels_len; ++i) {
+ data->value_labels->insert (QString::number (i+1), new_levels.at (i));
}
}
@@ -149,16 +151,17 @@
RK_ASSERT (cdata->getDataLength () == (unsigned int) getLength ()); // not really a problem due to the line below, I'd still like to know if / when this happens.
extendToLength (cdata->getDataLength ());
if (cdata->getDataType () == RData::StringVector) {
- setCharacterFromR (0, getLength () - 1, cdata->getStringVector ());
+ setCharacterFromR (0, getLength () - 1, cdata->stringVector ());
} else if (cdata->getDataType () == RData::RealVector) {
- setNumericFromR (0, getLength () - 1, cdata->getRealVector ());
+ setNumericFromR (0, getLength () - 1, cdata->realVector ());
} else if (cdata->getDataType () == RData::IntVector) {
+ RData::IntStorage int_data = cdata->intVector ();
unsigned int len = getLength ();
QVector<double> dd;
dd.reserve (len);
for (unsigned int i = 0; i < len; ++i) {
- if (RInterface::isNaInt (cdata->getIntVector ()[i])) dd.append (NAN);
- else dd.append ((double) cdata->getIntVector ()[i]);
+ if (RInterface::isNaInt (int_data.at (i))) dd.append (NAN);
+ else dd.append ((double) int_data.at (i));
}
setNumericFromR (0, getLength () - 1, dd);
}
@@ -169,13 +172,14 @@
// no invalids
} else {
RK_ASSERT (invalids->getDataType () == RData::StringVector);
- unsigned int invalids_length = invalids->getDataLength ();
+ QStringList invalids_list = invalids->stringVector ();
+ int invalids_length = invalids_list.size ();
RK_ASSERT ((invalids_length % 2) == 0);
- unsigned int invalids_count = invalids_length / 2;
- for (unsigned int i=0; i < invalids_count; ++i) {
- int row = invalids->getStringVector ()[i].toInt () - 1;
+ int invalids_count = invalids_length / 2;
+ for (int i=0; i < invalids_count; ++i) {
+ int row = invalids_list.at (i).toInt () - 1;
if (data->cell_states[row] & RKVarEditData::NA) {
- setText (row, invalids->getStringVector ()[invalids_count + i]);
+ setText (row, invalids_list.at (invalids_count + i));
}
}
}
Modified: trunk/rkward/rkward/core/robject.cpp
===================================================================
--- trunk/rkward/rkward/core/robject.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/core/robject.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -281,12 +281,13 @@
bool properties_change = false;
- properties_change = updateName (new_data->getStructureVector ()[StoragePositionName]);
- properties_change = updateType (new_data->getStructureVector ()[StoragePositionType]);
- properties_change = updateClasses (new_data->getStructureVector ()[StoragePositionClass]);
- properties_change = updateMeta (new_data->getStructureVector ()[StoragePositionMeta]);
- properties_change = updateDimensions (new_data->getStructureVector ()[StoragePositionDims]);
- properties_change = updateSlots (new_data->getStructureVector ()[StoragePositionSlots]);
+ RData::RDataStorage new_data_data = new_data->structureVector ();
+ properties_change = updateName (new_data_data.at (StoragePositionName));
+ properties_change = updateType (new_data_data.at (StoragePositionType));
+ properties_change = updateClasses (new_data_data.at (StoragePositionClass));
+ properties_change = updateMeta (new_data_data.at (StoragePositionMeta));
+ properties_change = updateDimensions (new_data_data.at (StoragePositionDims));
+ properties_change = updateSlots (new_data_data.at (StoragePositionSlots));
if (properties_change) RKGlobals::tracker ()->objectMetaChanged (this);
if (type & NeedDataUpdate) updateDataFromR (0);
@@ -328,8 +329,9 @@
RK_ASSERT (new_data->getDataLength () >= StorageSizeBasicInfo);
RK_ASSERT (new_data->getDataType () == RData::StructureVector);
- if (!isValidName (new_data->getStructureVector ()[StoragePositionName])) return false;
- if (!isValidType (new_data->getStructureVector ()[StoragePositionType])) return false;
+ RData::RDataStorage new_data_data = new_data->structureVector ();
+ if (!isValidName (new_data_data.at (StoragePositionName))) return false;
+ if (!isValidType (new_data_data.at (StoragePositionType))) return false;
return true;
}
@@ -338,9 +340,10 @@
RK_ASSERT (new_data->getDataLength () == 1);
RK_ASSERT (new_data->getDataType () == RData::StringVector);
- if (name != new_data->getStringVector ()[0]) {
+ QString new_name = new_data->stringVector ().at (0);
+ if (name != new_name) {
RK_ASSERT (false);
- name = new_data->getStringVector ()[0];
+ name = new_name;
return false;
}
return true;
@@ -352,10 +355,11 @@
RK_ASSERT (new_data->getDataType () == RData::StringVector);
bool changed = false;
- if (name != new_data->getStringVector ()[0]) {
+ QString new_name = new_data->stringVector ().at (0);
+ if (name != new_name) {
changed = true;
RK_ASSERT (false);
- name = new_data->getStringVector ()[0];
+ name = new_name;
}
return changed;
}
@@ -365,7 +369,7 @@
RK_ASSERT (new_data->getDataLength () == 1);
RK_ASSERT (new_data->getDataType () == RData::IntVector);
- int new_type = new_data->getIntVector ()[0];
+ int new_type = new_data->intVector ().at (0);
if (!isMatchingType (type, new_type)) return false;
return true;
@@ -377,7 +381,7 @@
RK_ASSERT (new_data->getDataType () == RData::IntVector);
bool changed = false;
- int new_type = new_data->getIntVector ()[0];
+ int new_type = new_data->intVector ().at (0);
if (type & PseudoObject) new_type |= PseudoObject;
if (type & Misplaced) new_type |= Misplaced;
if (type & Pending) new_type |= Pending; // NOTE: why don't we just clear the pending flag, here? Well, we don't want to generate a change notification for this. TODO: rethink the logic, and maybe use an appropriate mask
@@ -396,7 +400,7 @@
bool change = false;
- QStringList new_classes = new_data->getStringVector ();
+ QStringList new_classes = new_data->stringVector ();
if (new_classes != classnames) {
change = true;
classnames = new_classes;
@@ -410,16 +414,17 @@
RK_ASSERT (new_data->getDataType () == RData::StringVector);
- unsigned int len = new_data->getDataLength ();
+ QStringList data= new_data->stringVector ();
+ int len = data.size ();
bool change = false;
if (len) {
if (!meta_map) meta_map = new MetaMap;
else meta_map->clear ();
RK_ASSERT (!(len % 2));
- unsigned int cut = len/2;
- for (unsigned int i=0; i < cut; ++i) {
- meta_map->insert (new_data->getStringVector ()[i], new_data->getStringVector ()[i+cut]);
+ int cut = len/2;
+ for (int i=0; i < cut; ++i) {
+ meta_map->insert (data.at (i), data.at (i+cut));
}
// TODO: only signal change, if there really was a change!
@@ -439,7 +444,7 @@
RK_ASSERT (new_data->getDataLength () >= 1);
RK_ASSERT (new_data->getDataType () == RData::IntVector);
- QVector<qint32> new_dimensions = new_data->getIntVector ();
+ QVector<qint32> new_dimensions = new_data->intVector ();
if (new_dimensions != dimensions) {
if (new_dimensions.isEmpty ()) {
if (dimensions != RObjectPrivate::dim_null) {
@@ -468,7 +473,7 @@
added = true;
RKGlobals::tracker ()->lockUpdates (true);
}
- bool ret = slots_pseudo_object->updateStructure (new_data->getStructureVector ()[0]);
+ bool ret = slots_pseudo_object->updateStructure (new_data->structureVector ().at (0));
if (added) {
RKGlobals::tracker ()->lockUpdates (false);
Modified: trunk/rkward/rkward/core/robjectlist.cpp
===================================================================
--- trunk/rkward/rkward/core/robjectlist.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/core/robjectlist.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -139,14 +139,10 @@
RK_TRACE (OBJECTS);
if (command->getFlags () == ROBJECTLIST_UDPATE_ENVIRONMENTS_COMMAND) {
- unsigned int num_new_environments = command->getDataLength ();
RK_ASSERT (command->getDataType () == RData::StringVector);
- RK_ASSERT (num_new_environments >= 2);
+ QStringList new_environments = command->stringVector ();
+ RK_ASSERT (new_environments.size () >= 2);
- QStringList new_environments;
- for (unsigned int i = 0; i < num_new_environments; ++i) {
- new_environments.append (command->getStringVector ()[i]);
- }
updateEnvironments (new_environments, true);
RKGlobals::rInterface ()->issueCommand (QString (), RCommand::App | RCommand::Sync | RCommand::EmptyCommand, QString (), this, ROBJECTLIST_UDPATE_COMPLETE_COMMAND, update_chain);
Modified: trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -163,10 +163,7 @@
if (command->getFlags () == GET_CURRENT_LIBLOCS_COMMAND) {
RK_ASSERT (command->getDataType () == RData::StringVector);
RK_ASSERT (command->getDataLength () > 0);
- library_locations.clear ();
- for (unsigned int i=0; i < command->getDataLength (); ++i) {
- library_locations.append (command->getStringVector ()[i]);
- }
+ library_locations = command->stringVector ();
emit (libraryLocationsChanged (library_locations));
} else {
RK_ASSERT (false);
@@ -458,32 +455,33 @@
if (command->getFlags () == GET_INSTALLED_PACKAGES) {
RK_ASSERT (command->getDataLength () == 5);
- RData *package = command->getStructureVector ()[0];
- RData *title = command->getStructureVector ()[1];
- RData *version = command->getStructureVector ()[2];
- RData *libpath = command->getStructureVector ()[3];
+ RData::RDataStorage data = command->structureVector ();
+ QStringList package = data.at (0)->stringVector ();
+ QStringList title = data.at (1)->stringVector ();
+ QStringList version = data.at (2)->stringVector ();
+ QStringList libpath = data.at (3)->stringVector ();
- unsigned int count = package->getDataLength ();
- RK_ASSERT (count == title->getDataLength ());
- RK_ASSERT (count == version->getDataLength ());
- RK_ASSERT (count == libpath->getDataLength ());
- for (unsigned int i=0; i < count; ++i) {
+ int count = package.size ();
+ RK_ASSERT (count == title.size ());
+ RK_ASSERT (count == version.size ());
+ RK_ASSERT (count == libpath.size ());
+ for (int i=0; i < count; ++i) {
QTreeWidgetItem* item = new QTreeWidgetItem (installed_view);
- item->setText (0, package->getStringVector ()[i]);
- item->setText (1, title->getStringVector ()[i]);
- item->setText (2, version->getStringVector ()[i]);
- item->setText (3, libpath->getStringVector ()[i]);
+ item->setText (0, package.at (i));
+ item->setText (1, title.at (i));
+ item->setText (2, version.at (i));
+ item->setText (3, libpath.at (i));
}
installed_view->resizeColumnToContents (0);
installed_view->setSortingEnabled (true);
installed_view->sortItems (0, Qt::AscendingOrder);
} else if (command->getFlags () == GET_LOADED_PACKAGES) {
RK_ASSERT (command->getDataType () == RData::StringVector);
-
- for (unsigned int i=0; i < command->getDataLength (); ++i) {
+ QStringList data = command->stringVector ();
+ for (int i=0; i < data.size (); ++i) {
QTreeWidgetItem* item = new QTreeWidgetItem (loaded_view);
- item->setText (0, command->getStringVector ()[i]);
- if (RKSettingsModuleRPackages::essentialPackages ().contains (command->getStringVector ()[i])) {
+ item->setText (0, data.at (i));
+ if (RKSettingsModuleRPackages::essentialPackages ().contains (data.at (i))) {
#if QT_VERSION >= 0x040400
item->setFlags (Qt::NoItemFlags);
#else
@@ -886,32 +884,32 @@
RK_ASSERT (command->getDataType () == RCommand::StructureVector);
RK_ASSERT (command->getDataLength () == 5);
- RData::RDataStorage top = command->getStructureVector ();
- RData::RDataStorage available = top[0]->getStructureVector ();
- available_packages = available[0]->getStringVector ();
- available_titles = available[1]->getStringVector ();
- available_versions = available[2]->getStringVector ();
- available_repos = available[3]->getStringVector ();
- enhance_rk_in_available = available[4]->getIntVector ();
+ RData::RDataStorage top = command->structureVector ();
+ RData::RDataStorage available = top[0]->structureVector ();
+ available_packages = available[0]->stringVector ();
+ available_titles = available[1]->stringVector ();
+ available_versions = available[2]->stringVector ();
+ available_repos = available[3]->stringVector ();
+ enhance_rk_in_available = available[4]->intVector ();
- RData::RDataStorage installed = top[1]->getStructureVector ();
- installed_packages = installed[0]->getStringVector ();
- installed_titles = installed[1]->getStringVector ();
- installed_versions = installed[2]->getStringVector ();
- installed_libpaths = installed[3]->getStringVector ();
- enhance_rk_in_installed = installed[4]->getIntVector ();
+ RData::RDataStorage installed = top[1]->structureVector ();
+ installed_packages = installed[0]->stringVector ();
+ installed_titles = installed[1]->stringVector ();
+ installed_versions = installed[2]->stringVector ();
+ installed_libpaths = installed[3]->stringVector ();
+ enhance_rk_in_installed = installed[4]->intVector ();
installed_has_update.fill (false, installed_packages.count ());
- new_packages_in_available = top[2]->getIntVector ();
- RData::RDataStorage updateable = top[3]->getStructureVector ();
- updateable_packages_in_installed = updateable[0]->getIntVector ();
- updateable_packages_in_available = updateable[1]->getIntVector ();
+ new_packages_in_available = top[2]->intVector ();
+ RData::RDataStorage updateable = top[3]->structureVector ();
+ updateable_packages_in_installed = updateable[0]->intVector ();
+ updateable_packages_in_available = updateable[1]->intVector ();
for (int i = updateable_packages_in_installed.count () - 1; i >= 0; --i) {
installed_has_update[updateable_packages_in_installed[i]] = true;
}
- current_repos = top[4]->getStringVector ();
+ current_repos = top[4]->stringVector ();
clearStatus ();
}
Modified: trunk/rkward/rkward/rbackend/rdata.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rdata.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/rbackend/rdata.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -33,27 +33,19 @@
discardData ();
}
-RData::RealStorage &RData::getRealVector () const {
- return (*static_cast<RealStorage *> (data));
+void RData::doAssert(RData::RDataType requested_type) const {
+ if (this == 0) {
+ RK_DO (qDebug ("Requested data from a NULL RData"), RBACKEND, DL_ERROR);
+ } else {
+ RK_DO (qDebug ("Reqeusted data of type %d, while %p has type %d", requested_type, this, datatype), RBACKEND, DL_ERROR);
+ }
}
-RData::IntStorage &RData::getIntVector () const {
- return (*static_cast<IntStorage *> (data));
-}
-
-RData::StringStorage &RData::getStringVector () const {
- return (*static_cast<StringStorage *> (data));
-}
-
-RData::RDataStorage &RData::getStructureVector () const {
- return (*static_cast<RDataStorage *> (data));
-}
-
void RData::discardData () {
RK_TRACE (RBACKEND);
if (datatype == StructureVector) {
- RDataStorage sdata = getStructureVector ();
+ RDataStorage sdata = *(static_cast<RDataStorage *> (data));
for (int i=sdata.size ()-1; i >= 0; --i) {
delete (sdata[i]);
}
@@ -73,10 +65,11 @@
}
unsigned int RData::getDataLength() const {
- if (datatype == RealVector) return (getRealVector ().size ());
- if (datatype == IntVector) return (getIntVector ().size ());
- if (datatype == StringVector) return (getStringVector ().size ());
- if (datatype == StructureVector) return (getStructureVector ().size ());
+ if (!this) return 0;
+ if (datatype == RealVector) return (static_cast<RealStorage *> (data)->size ());
+ if (datatype == IntVector) return (static_cast<IntStorage *> (data)->size ());
+ if (datatype == StringVector) return (static_cast<StringStorage *> (data)->size ());
+ if (datatype == StructureVector) return (static_cast<RDataStorage *> (data)->size ());
return 0;
}
@@ -109,37 +102,35 @@
}
void RData::printStructure (const QString &prefix) {
- switch (datatype) {
- case NoData:
- qDebug ("%s: NoData, length %d", prefix.toLatin1().data(), getDataLength ());
- break;
- case IntVector:
- qDebug ("%s: IntVector, length %d", prefix.toLatin1().data(), getDataLength ());
- for (unsigned int i = 0; i < getDataLength (); ++i) {
- qDebug ("%s%d: %d", prefix.toLatin1().data(), i, getIntVector ()[i]);
- }
- break;
- case RealVector:
- qDebug ("%s: RealVector, length %d", prefix.toLatin1().data(), getDataLength ());
- for (unsigned int i = 0; i < getDataLength (); ++i) {
- qDebug ("%s%d: %f", prefix.toLatin1().data(), i, getRealVector ()[i]);
- }
- break;
- case StringVector:
- qDebug ("%s: StringVector, length %d", prefix.toLatin1().data(), getDataLength ());
- for (unsigned int i = 0; i < getDataLength (); ++i) {
- qDebug ("%s%d: %s", prefix.toLatin1().data(), i, getStringVector ()[i].toLatin1().data());
- }
- break;
- case StructureVector:
- qDebug ("%s: StructureVector, length %d", prefix.toLatin1().data(), getDataLength ());
- for (unsigned int i = 0; i < getDataLength (); ++i) {
- QString sub_prefix = prefix + QString::number (i);
- getStructureVector ()[i]->printStructure (sub_prefix);
- }
- break;
- default:
- qDebug ("%s: INVALID %d, length %d", prefix.toLatin1().data(), datatype, getDataLength ());
+ if (datatype == NoData) {
+ qDebug ("%s: NoData, length %d", prefix.toLatin1().data(), getDataLength ());
+ } else if (datatype == IntVector) {
+ qDebug ("%s: IntVector, length %d", prefix.toLatin1().data(), getDataLength ());
+ IntStorage data = intVector ();
+ for (int i = 0; i < data.size (); ++i) {
+ qDebug ("%s%d: %d", prefix.toLatin1().data(), i, data.at (i));
+ }
+ } else if (datatype == RealVector) {
+ qDebug ("%s: RealVector, length %d", prefix.toLatin1().data(), getDataLength ());
+ RealStorage data = realVector ();
+ for (int i = 0; i < data.size (); ++i) {
+ qDebug ("%s%d: %f", prefix.toLatin1().data(), i, data.at (i));
+ }
+ } else if (datatype == StringVector) {
+ qDebug ("%s: StringVector, length %d", prefix.toLatin1().data(), getDataLength ());
+ StringStorage data = stringVector ();
+ for (int i = 0; i < data.size (); ++i) {
+ qDebug ("%s%d: %s", prefix.toLatin1().data(), i, qPrintable (data.at (i)));
+ }
+ } else if (datatype == StructureVector) {
+ qDebug ("%s: StructureVector, length %d", prefix.toLatin1().data(), getDataLength ());
+ RDataStorage data = structureVector ();
+ for (int i = 0; i < data.size (); ++i) {
+ QString sub_prefix = prefix + QString::number (i);
+ data.at (i)->printStructure (sub_prefix);
+ }
+ } else {
+ qDebug ("%s: INVALID %d, length %d", prefix.toLatin1().data(), datatype, getDataLength ());
}
qDebug ("%s: END\n\n", prefix.toLatin1 ().data());
}
Modified: trunk/rkward/rkward/rbackend/rdata.h
===================================================================
--- trunk/rkward/rkward/rbackend/rdata.h 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/rbackend/rdata.h 2011-10-25 10:19:32 UTC (rev 3996)
@@ -42,14 +42,38 @@
RDataType getDataType () const { return datatype; };
/** returns the length (size) of the data array. @see RCommand::GetStringVector @see RCommand::GetRealVector @see RCommand::GetIntVector @see RCommand:GetStructure */
unsigned int getDataLength () const;
-/** returns an array of double, if that is the type of data contained (else 0). @see RCommand::GetRealVector @see RData::getDataLength () @see RData::getDataType () */
- RealStorage &getRealVector () const;
-/** returns an array of int, if that is the type of data contained (else 0). @see RCommand::GetIntVector @see RData::getDataLength () @see RData::getDataType () */
- IntStorage &getIntVector () const;
-/** returns an array of QString, if that is the type of data contained (else 0). @see RCommand::GetStringVector @see RData::getDataLength () @see RData::getDataType () */
- StringStorage &getStringVector () const;
-/** returns an array of RData*, if that is the type of data contained (else 0). @see RCommand::GetStructureVector @see RData::getDataLength () @see RData::getDataType () */
- RDataStorage &getStructureVector () const;
+/** returns a vector of double, if that is the type of data contained (else, an assert is raised, and an empty vector is returned). Can be used safely on a null RData pointer (but raises an assert in this case). @see RCommand::GetRealVector @see RData::getDataType () */
+ const RealStorage realVector () const {
+ if (this && (datatype == RealVector)) {
+ return (*static_cast<RealStorage *> (data));
+ }
+ doAssert (RealVector);
+ return RealStorage ();
+ }
+/** returns a vector of int, if that is the type of data contained (else, an assert is raised, and an empty vector is returned). Can be used safely on a null RData pointer (but raises an assert in this case). @see RCommand::GetIntVector @see RData::getDataType () */
+ const IntStorage intVector () const {
+ if (this && (datatype == IntVector)) {
+ return (*static_cast<IntStorage *> (data));
+ }
+ doAssert (IntVector);
+ return IntStorage ();
+ }
+/** returns a QStringList, if that is the type of data contained (else, an assert is raised, and an empty vector is returned). Can be used safely on a null RData pointer (but raises an assert in this case). @see RCommand::GetStringVector @see RData::getDataType () */
+ const StringStorage stringVector () const {
+ if (this && (datatype == StringVector)) {
+ return (*static_cast<StringStorage *> (data));
+ }
+ doAssert (StringVector);
+ return StringStorage ();
+ }
+/** returns a vector of RData*, if that is the type of data contained (else, an assert is raised, and an empty vector is returned). Can be used safely on a null RData pointer (but raises an assert in this case). @see RCommand::GetStructureVector @see RData::getDataType () */
+ const RDataStorage structureVector () const {
+ if (this && (datatype == StructureVector)) {
+ return (*static_cast<RDataStorage *> (data));
+ }
+ doAssert (StructureVector);
+ return RDataStorage ();
+ }
void discardData ();
/** purely for debugging! */
void printStructure (const QString &prefix);
@@ -61,6 +85,7 @@
/** public for technical reasons only. Do not use! Move data from the given RData to this RData. The source RData is emptied! */
void swallowData (RData &from);
private:
+ void doAssert (RDataType requested_type) const;
RDataType datatype;
void *data;
};
Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -263,9 +263,7 @@
if (command->getFlags () == GET_LIB_PATHS) {
RK_ASSERT (command->getDataType () == RData::StringVector);
- for (unsigned int i = 0; i < command->getDataLength (); ++i) {
- RKSettingsModuleRPackages::defaultliblocs.append (command->getStringVector ()[i]);
- }
+ RKSettingsModuleRPackages::defaultliblocs += command->stringVector ();
RCommandStack *stack = RCommandStack::currentStack ();
RCommandChain *chain = stack->currentChain ();
@@ -284,7 +282,7 @@
} else if (command->getFlags () == GET_HELP_BASE) {
RK_ASSERT (command->getDataType () == RData::StringVector);
RK_ASSERT (command->getDataLength () == 1);
- RKSettingsModuleR::help_base_url = command->getStringVector ()[0];
+ RKSettingsModuleR::help_base_url = command->stringVector ().value (0);
} else if (command->getFlags () == SET_RUNTIME_OPTS) {
// no special handling. In case of failures, staturt_fail was set to true, above.
} else if (command->getFlags () == STARTUP_PHASE2_COMPLETE) {
Modified: trunk/rkward/rkward/rbackend/rkrbackend.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkrbackend.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/rbackend/rkrbackend.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -343,7 +343,7 @@
int n_frames = 0;
RCommandProxy *dummy = RKRBackend::this_pointer->runDirectCommand ("sys.nframe()", RCommand::GetIntVector);
if ((dummy->getDataType () == RData::IntVector) && (dummy->getDataLength () == 1)) {
- n_frames = dummy->getIntVector ()[0];
+ n_frames = dummy->intVector ().at (0);
}
// What the ??? Why does this simple version always return 0?
//int n_frames = RKRSupport::SEXPToInt (RKRSupport::callSimpleFun0 (Rf_install ("sys.nframe"), R_GlobalEnv));
@@ -387,10 +387,11 @@
request_type = RBackendRequest::Debugger;
if ((dummy->getDataType () == RData::StructureVector) && (dummy->getDataLength () >= 4)) {
- params["calls"] = QVariant (dummy->getStructureVector ()[0]->getStringVector ());
- params["funs"] = QVariant (dummy->getStructureVector ()[1]->getStringVector ());
- params["envs"] = QVariant (dummy->getStructureVector ()[2]->getStringVector ());
- params["locals"] = QVariant (dummy->getStructureVector ()[3]->getStringVector ());
+ RData::RDataStorage dummy_data = dummy->structureVector ();
+ params["calls"] = QVariant (dummy_data.at (0)->stringVector ());
+ params["funs"] = QVariant (dummy_data.at (1)->stringVector ());
+ params["envs"] = QVariant (dummy_data.at (2)->stringVector ());
+ params["locals"] = QVariant (dummy_data.at (3)->stringVector ());
} else {
RK_ASSERT (false);
}
@@ -1069,7 +1070,7 @@
// get info on R runtime version
RCommandProxy *dummy = runDirectCommand ("as.numeric (R.version$major) * 1000 + as.numeric (R.version$minor) * 10", RCommand::GetIntVector);
if ((dummy->getDataType () == RData::IntVector) && (dummy->getDataLength () == 1)) {
- r_version = dummy->getIntVector ()[0];
+ r_version = dummy->intVector ().at (0);
} else {
RK_ASSERT (false);
r_version = 0;
@@ -1528,14 +1529,14 @@
// TODO: avoid parsing this over and over again
RK_DO (qDebug ("checkObjectUpdatesNeeded: getting search list"), RBACKEND, DL_TRACE);
RCommandProxy *dummy = runDirectCommand ("search ()\n", RCommand::GetStringVector);
- if (dummy->getStringVector () != toplevel_env_names) search_update_needed = true;
- if (search_update_needed) toplevel_env_names = dummy->getStringVector ();
+ if (dummy->stringVector () != toplevel_env_names) search_update_needed = true;
+ if (search_update_needed) toplevel_env_names = dummy->stringVector ();
delete dummy;
// TODO: avoid parsing this over and over again
RK_DO (qDebug ("checkObjectUpdatesNeeded: getting globalenv symbols"), RBACKEND, DL_TRACE);
dummy = runDirectCommand ("ls (globalenv (), all.names=TRUE)\n", RCommand::GetStringVector);
- QStringList new_globalenv_toplevel_names = dummy->getStringVector ();
+ QStringList new_globalenv_toplevel_names = dummy->stringVector ();
if (new_globalenv_toplevel_names.count () != global_env_toplevel_names.count ()) {
globalenv_update_needed = true;
} else {
Modified: trunk/rkward/rkward/rbackend/rktransmitter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rktransmitter.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/rbackend/rktransmitter.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -105,11 +105,11 @@
RData::RDataType type = data.getDataType ();
stream << (qint8) type;
- if (type == RData::IntVector) stream << data.getIntVector ();
- else if (type == RData::StringVector) stream << data.getStringVector ();
- else if (type == RData::RealVector) stream << data.getRealVector ();
+ if (type == RData::IntVector) stream << data.intVector ();
+ else if (type == RData::StringVector) stream << data.stringVector ();
+ else if (type == RData::RealVector) stream << data.realVector ();
else if (type == RData::StructureVector) {
- RData::RDataStorage list = data.getStructureVector ();
+ RData::RDataStorage list = data.structureVector ();
qint32 len = list.size ();
stream << len;
for (qint32 i = 0; i < list.size (); ++i) {
Modified: trunk/rkward/rkward/settings/rksettingsmoduler.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduler.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/settings/rksettingsmoduler.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -423,7 +423,7 @@
if (command->getFlags () == SELECT_CRAN_MIRROR_COMMAND) {
if (command->succeeded ()) {
RK_ASSERT (command->getDataLength () >= 1);
- cran_mirror_input->setText (command->getStringVector ()[0]);
+ cran_mirror_input->setText (command->stringVector ().value (0));
}
} else {
RK_ASSERT (false);
Modified: trunk/rkward/rkward/windows/rkhelpsearchwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkhelpsearchwindow.cpp 2011-10-24 09:08:06 UTC (rev 3995)
+++ trunk/rkward/rkward/windows/rkhelpsearchwindow.cpp 2011-10-25 10:19:32 UTC (rev 3996)
@@ -247,7 +247,7 @@
RK_ASSERT (false);
} else {
RK_ASSERT (command->getDataType () == RData::StringVector);
- res = command->getStringVector ();
+ res = command->stringVector ();
}
results->setResults (res);
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