Commit 15f0cf0d authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'attribute-asserts'

4bf0da63 In attributes, add asserts to unchecked vector element access.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Bob Obara's avatarBob Obara <bob.obara@kitware.com>
Merge-request: !364
parents cd344b64 4bf0da63
......@@ -37,6 +37,7 @@ SMTK_THIRDPARTY_PRE_INCLUDE
#include "boost/algorithm/string.hpp"
SMTK_THIRDPARTY_POST_INCLUDE
#include <cassert>
#include <iostream>
using namespace smtk::attribute;
......@@ -473,6 +474,7 @@ smtk::attribute::ItemPtr Attribute::find(
}
i = -1; // Nothing found.
}
assert(i < 0 || this->m_items.size() > static_cast<std::size_t>(i));
return (i < 0) ?
smtk::attribute::ItemPtr() :
this->m_items[static_cast<std::size_t>(i)];
......@@ -499,6 +501,7 @@ smtk::attribute::ConstItemPtr Attribute::find(
}
i = -1; // Nothing found.
}
assert(i < 0 || this->m_items.size() > static_cast<std::size_t>(i));
return (i < 0) ?
smtk::attribute::ConstItemPtr() :
smtk::const_pointer_cast<const Item>(this->m_items[static_cast<std::size_t>(i)]);
......
......@@ -17,6 +17,7 @@
#include "smtk/attribute/ModelEntityItemDefinition.h"
#include "smtk/attribute/System.h"
#include <cassert>
#include <iostream>
#include <sstream>
......@@ -324,6 +325,7 @@ smtk::attribute::ItemDefinitionPtr Definition::itemDefinition(int ith) const
// Is the item in this defintion?
if (ith >= static_cast<int>(this->m_baseItemOffset))
{
assert(this->m_itemDefs.size() > static_cast<std::size_t>(ith-this->m_baseItemOffset));
return this->m_itemDefs[static_cast<std::size_t>(ith-this->m_baseItemOffset)];
}
else if (this->m_baseDefinition)
......
......@@ -12,6 +12,7 @@
#include "smtk/attribute/FileSystemItem.h"
#include "smtk/attribute/FileSystemItemDefinition.h"
#include "smtk/attribute/Attribute.h"
#include <cassert>
#include <iostream>
#include <stdio.h>
......@@ -152,6 +153,8 @@ bool FileSystemItem::setValue(std::size_t element, const std::string &val)
static_cast<const FileSystemItemDefinition *>(this->definition().get());
if ((def == NULL) || (def->isValueValid(val)))
{
assert(this->m_values.size() > element);
assert(this->m_isSet.size() > element);
this->m_values[element] = val;
this->m_isSet[element] = true;
return true;
......@@ -165,6 +168,7 @@ FileSystemItem::valueAsString(std::size_t element,
{
// For the initial design we will use sprintf and force a limit of 300 char
char dummy[300];
assert(this->m_values.size() > element);
if (format != "")
{
sprintf(dummy, format.c_str(), this->m_values[element].c_str());
......@@ -305,6 +309,8 @@ bool FileSystemItem::isUsingDefault() const
std::size_t i, n = this->numberOfValues();
std::string dval = def->defaultValue();
assert(this->m_isSet.size() >= n);
assert(this->m_values.size() >= n);
for (i = 0; i < n; i++)
{
if (!(this->m_isSet[i] && (this->m_values[i] == dval)))
......@@ -318,6 +324,8 @@ bool FileSystemItem::isUsingDefault() const
bool FileSystemItem::isUsingDefault(std::size_t element) const
{
auto def = static_cast<const FileSystemItemDefinition *>(this->definition().get());
assert(this->m_isSet.size() > element);
assert(this->m_values.size() > element);
if (def->hasDefault() && this->m_isSet[element] &&
this->m_values[element] == def->defaultValue())
{
......
......@@ -13,6 +13,8 @@
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/FileSystemItem.h"
#include <cassert>
using namespace smtk::attribute;
//----------------------------------------------------------------------------
......@@ -88,6 +90,7 @@ void FileSystemItemDefinition::setValueLabel(std::size_t element, const std::str
this->m_valueLabels.resize(this->m_numberOfRequiredValues);
}
this->m_useCommonLabel = false;
assert(this->m_valueLabels.size() > element);
this->m_valueLabels[element] = elabel;
}
//----------------------------------------------------------------------------
......@@ -106,10 +109,12 @@ std::string FileSystemItemDefinition::valueLabel(std::size_t element) const
{
if (this->m_useCommonLabel)
{
assert(this->m_valueLabels.size() > 0);
return this->m_valueLabels[0];
}
if (this->m_valueLabels.size())
{
assert(this->m_valueLabels.size() > element);
return this->m_valueLabels[element];
}
return ""; // If we threw execeptions this method could return const string &
......
......@@ -219,6 +219,7 @@ bool GroupItem::removeGroup(std::size_t element)
return false; // min number of groups reached
}
assert(this->m_items.size() > element);
std::vector<smtk::attribute::ItemPtr> &items = this->m_items[element];
std::size_t j, m = items.size();
for(j = 0; j < m; j++)
......@@ -288,6 +289,8 @@ smtk::attribute::ItemPtr GroupItem::find(std::size_t element, const std::string
const GroupItemDefinition *def =
static_cast<const GroupItemDefinition *>(this->definition().get());
int i = def->findItemPosition(inName);
assert(this->m_items.size() > element);
assert(this->m_items[element].size() > static_cast<std::size_t>(i));
return (i < 0) ? smtk::attribute::ItemPtr() : this->m_items[element][static_cast<std::size_t>(i)];
}
//----------------------------------------------------------------------------
......@@ -300,6 +303,8 @@ smtk::attribute::ConstItemPtr GroupItem::find(std::size_t element, const std::st
{
return smtk::attribute::ConstItemPtr();
}
assert(this->m_items.size() > element);
assert(this->m_items[element].size() > static_cast<std::size_t>(i));
return this->m_items[element][static_cast<std::size_t>(i)];
}
//----------------------------------------------------------------------------
......
......@@ -16,6 +16,7 @@
#include "smtk/CoreExports.h"
#include "smtk/attribute/Item.h"
#include <cassert>
#include <vector>
namespace smtk
{
......@@ -47,7 +48,11 @@ namespace smtk
smtk::attribute::ItemPtr item(std::size_t ith) const
{return this->item(0, ith);}
smtk::attribute::ItemPtr item(std::size_t element, std::size_t ith) const
{return this->m_items[element][ith];}
{
assert(this->m_items.size() > element);
assert(this->m_items[element].size() > ith);
return this->m_items[element][ith];
}
smtk::attribute::ItemPtr find(const std::string &inName)
{return this->find(0, inName);}
......
......@@ -18,6 +18,8 @@
#include "smtk/model/Manager.h"
#include "smtk/common/UUID.h"
#include <cassert>
using namespace smtk::attribute;
/// Construct an item definition given a name. Names should be unique and non-empty.
......@@ -177,10 +179,12 @@ std::string ModelEntityItemDefinition::valueLabel(std::size_t i) const
{
if (this->m_useCommonLabel)
{
assert(!this->m_valueLabels.empty());
return this->m_valueLabels[0];
}
if (this->m_valueLabels.size())
{
assert(this->m_valueLabels.size() > i);
return this->m_valueLabels[i];
}
return "";
......
......@@ -99,7 +99,7 @@ bool RefItem::isValid() const
return false;
}
}
return true;
}
//----------------------------------------------------------------------------
......@@ -120,6 +120,7 @@ bool RefItem::setValue(std::size_t element, smtk::attribute::AttributePtr att)
static_cast<const RefItemDefinition *>(this->definition().get());
if (def->isValueValid(att))
{
assert(this->m_values.size() > element);
Attribute *attPtr = this->m_values[element].lock().get();
if (attPtr != NULL)
{
......@@ -138,6 +139,7 @@ RefItem::valueAsString(std::size_t element,
{
// For the initial design we will use sprintf and force a limit of 300 char
char dummy[300];
assert(this->m_values.size() > element);
if (format != "")
{
sprintf(dummy, format.c_str(), this->m_values[element].lock()->name().c_str());
......@@ -197,6 +199,7 @@ RefItem::removeValue(std::size_t element)
return false; // The number of values is fixed
}
// Tell the attribute we are no longer referencing it (if needed)
assert(this->m_values.size() > element);
Attribute *att = this->m_values[element].lock().get();
if (att != NULL)
{
......@@ -227,6 +230,7 @@ RefItem::setNumberOfValues(std::size_t newSize)
{
std::size_t i;
Attribute *att;
assert(this->m_values.size() >= n);
for (i = newSize; i < n; i++)
{
att = this->m_values[i].lock().get();
......@@ -243,6 +247,7 @@ RefItem::setNumberOfValues(std::size_t newSize)
void
RefItem::unset(std::size_t element)
{
assert(this->m_values.size() > element);
Attribute *att = this->m_values[element].lock().get();
if (att == NULL)
{
......@@ -292,7 +297,7 @@ bool RefItem::assign(ConstItemPtr &sourceItem, unsigned int options)
{
return Item::assign(sourceItem, options);
}
// Get reference to attribute system
System *system = this->attribute()->system();
......@@ -323,7 +328,7 @@ bool RefItem::assign(ConstItemPtr &sourceItem, unsigned int options)
this->unset(i);
}
}
return Item::assign(sourceItem, options);
}
//----------------------------------------------------------------------------
......@@ -17,6 +17,7 @@
#include "smtk/CoreExports.h"
#include "smtk/PublicPointerDefs.h"
#include "smtk/attribute/Item.h"
#include <cassert>
#include <vector>
namespace smtk
......@@ -36,10 +37,10 @@ namespace smtk
smtkTypeMacro(RefItem);
virtual ~RefItem();
virtual Item::Type type() const;
// A RefItem is valid if it is either no enabled or if all of
// A RefItem is valid if it is either no enabled or if all of
// its values are set and the attributes it references exist
// It does NOT check to see if the attribute(s) it refers to are
// valid - the reason for this is to avoid infinite loops if 2
// It does NOT check to see if the attribute(s) it refers to are
// valid - the reason for this is to avoid infinite loops if 2
// attributes contain items that reference each other.
virtual bool isValid() const;
......@@ -48,7 +49,10 @@ namespace smtk
bool setNumberOfValues(std::size_t newSize);
std::size_t numberOfRequiredValues() const;
smtk::attribute::AttributePtr value(std::size_t element=0) const
{return this->m_values[element].lock();}
{
assert(this->m_values.size() > element);
return this->m_values[element].lock();
}
bool setValue( smtk::attribute::AttributePtr val)
{return this->setValue(0, val);}
bool setValue(std::size_t element, smtk::attribute::AttributePtr val);
......@@ -59,7 +63,10 @@ namespace smtk
{return this->valueAsString(0, format);}
virtual std::string valueAsString(std::size_t element, const std::string &format="") const;
virtual bool isSet(std::size_t element=0) const
{return this->m_values[element].lock().get() != NULL;}
{
assert(this->m_values.size() > element);
return this->m_values[element].lock().get() != NULL;
}
virtual void unset(std::size_t element=0);
// Iterator-style access to values:
......
......@@ -87,7 +87,7 @@ bool ValueItem::setDefinition(smtk::attribute::ConstItemDefinitionPtr vdef)
ValueItem::~ValueItem()
{
// we need to detach all items that are owned by this. i.e. the expression items
std::size_t i, n = m_expressions.size();
std::size_t i, n = this->m_expressions.size();
for (i = 0; i < n; i++)
{
this->m_expressions[i]->detachOwningItem();
......@@ -102,6 +102,7 @@ bool ValueItem::isValid() const
{
return true;
}
assert(!this->allowsExpressions() || this->m_expressions.size() >= this->m_isSet.size());
for (std::size_t i = 0; i < this->m_isSet.size(); ++i)
{
if (!this->m_isSet[i])
......@@ -110,7 +111,7 @@ bool ValueItem::isValid() const
}
// Is this using an expression?
if (this->allowsExpressions() && (this->m_expressions[i]->value()!= nullptr))
{
{
if (!this->m_expressions[i]->isValid())
{
return false;
......@@ -118,7 +119,7 @@ bool ValueItem::isValid() const
}
}
// Now we need to check the active items
for (auto it = this->m_activeChildrenItems.begin();
for (auto it = this->m_activeChildrenItems.begin();
it != this->m_activeChildrenItems.end(); ++it)
{
if (!(*it)->isValid())
......@@ -198,12 +199,14 @@ bool ValueItem::allowsExpressions() const
//----------------------------------------------------------------------------
smtk::attribute::AttributePtr ValueItem::expression(std::size_t element) const
{
assert(this->m_isSet.size() > element);
if (this->m_isSet[element])
{
const ValueItemDefinition *def =
static_cast<const ValueItemDefinition*>(this->m_definition.get());
if (def->allowsExpressions())
{
assert(this->m_expressions.size() > element);
return this->m_expressions[element]->value();
}
}
......@@ -219,8 +222,10 @@ bool ValueItem::setExpression(std::size_t element,
{
if (!exp)
{
assert(this->m_expressions.size() > element);
if (this->m_expressions[element]->value())
{
assert(this->m_isSet.size() > element);
this->m_isSet[element] = false;
this->m_expressions[element]->unset();
}
......@@ -228,7 +233,9 @@ bool ValueItem::setExpression(std::size_t element,
}
if (def->isValidExpression(exp))
{
assert(this->m_isSet.size() > element);
this->m_isSet[element] = true;
assert(this->m_expressions.size() > element);
this->m_expressions[element]->setValue(exp);
return true;
}
......@@ -288,6 +295,8 @@ bool ValueItem::setDiscreteIndex(std::size_t element, int index)
if (def->isDiscreteIndexValid(index))
{
// Is this a different value then what is set already?
assert(this->m_isSet.size() > element);
assert(this->m_discreteIndices.size() > element);
if (this->m_isSet[element] && (this->m_discreteIndices[element] == index))
{
// Nothing is changed
......@@ -296,6 +305,7 @@ bool ValueItem::setDiscreteIndex(std::size_t element, int index)
this->m_discreteIndices[element] = index;
if (def->allowsExpressions())
{
assert(this->m_expressions.size() > element);
this->m_expressions[element]->unset();
}
this->m_isSet[element] = true;
......@@ -322,6 +332,7 @@ void ValueItem::updateActiveChildrenItems()
// Check to see if the index is valid
const ValueItemDefinition *def =
static_cast<const ValueItemDefinition*>(this->m_definition.get());
assert(!this->m_discreteIndices.empty());
if (!def->isDiscreteIndexValid(this->m_discreteIndices[0]))
{
return;
......@@ -344,12 +355,12 @@ bool ValueItem::assign(ConstItemPtr &sourceItem, unsigned int options)
// Cast input pointer to ValueItem
smtk::shared_ptr<const ValueItem > sourceValueItem =
smtk::dynamic_pointer_cast<const ValueItem>(sourceItem);
if (!sourceValueItem)
{
return false; //Source is not a value item!
}
this->setNumberOfValues(sourceValueItem->numberOfValues());
// Get reference to attribute system
......@@ -394,7 +405,7 @@ bool ValueItem::assign(ConstItemPtr &sourceItem, unsigned int options)
this->setDiscreteIndex(i, sourceValueItem->discreteIndex(i));
}
} // for
// Update children items
std::map<std::string, smtk::attribute::ItemPtr>::const_iterator sourceIter =
sourceValueItem->m_childrenItems.begin();
......
......@@ -19,6 +19,8 @@
#include "smtk/PublicPointerDefs.h"
#include "smtk/CoreExports.h"
#include <cassert>
namespace smtk
{
namespace attribute
......@@ -52,7 +54,10 @@ namespace smtk
virtual bool setNumberOfValues(std::size_t newSize) = 0;
int discreteIndex(std::size_t elementIndex=0) const
{return this->m_discreteIndices[elementIndex];}
{
assert(this->m_discreteIndices.size() > elementIndex);
return this->m_discreteIndices[elementIndex];
}
bool isDiscrete() const;
bool isDiscreteIndexValid(int value) const;
bool setDiscreteIndex(int value)
......@@ -78,11 +83,17 @@ namespace smtk
virtual std::string valueAsString(std::size_t elementIndex) const = 0;
virtual bool isSet(std::size_t elementIndex = 0) const
{return this->m_isSet[elementIndex];}
{
assert(this->m_isSet.size() > elementIndex);
return this->m_isSet[elementIndex];
}
virtual void unset(std::size_t elementIndex=0)
{this->m_isSet[elementIndex] = false;}
smtk::attribute::RefItemPtr expressionReference(std::size_t elementIndex=0) const
{return this->m_expressions[elementIndex];}
{
assert(this->m_expressions.size() > elementIndex);
return this->m_expressions[elementIndex];
}
// Interface for getting discrete-value based children items
std::size_t numberOfChildrenItems() const
......
......@@ -84,6 +84,7 @@ void ValueItemDefinition::setValueLabel(std::size_t element, const std::string &
this->m_valueLabels.resize(this->m_numberOfRequiredValues);
}
this->m_useCommonLabel = false;
assert(this->m_valueLabels.size() > element);
this->m_valueLabels[element] = elabel;
}
//----------------------------------------------------------------------------
......@@ -94,6 +95,7 @@ void ValueItemDefinition::setCommonValueLabel(const std::string &elabel)
this->m_valueLabels.resize(1);
}
this->m_useCommonLabel = true;
assert(!this->m_valueLabels.empty());
this->m_valueLabels[0] = elabel;
}
......@@ -102,6 +104,7 @@ std::string ValueItemDefinition::valueLabel(std::size_t element) const
{
if (this->m_useCommonLabel)
{
assert(!this->m_valueLabels.empty());
return this->m_valueLabels[0];
}
if (element < this->m_valueLabels.size())
......@@ -144,6 +147,7 @@ ValueItemDefinition::buildExpressionItem(ValueItem *vitem, int position) const
smtk::dynamic_pointer_cast<smtk::attribute::RefItem>
(this->m_expressionDefinition->buildItem(vitem, position, -1));
aref->setDefinition(this->m_expressionDefinition);
assert(vitem->m_expressions.size() > static_cast<size_t>(position));
vitem->m_expressions[static_cast<size_t>(position)] = aref;
}
//----------------------------------------------------------------------------
......@@ -254,9 +258,9 @@ copyTo(ValueItemDefinitionPtr def,
ItemDefinition::copyTo(def);
if (m_units != "")
if (this->m_units != "")
{
def->setUnits(m_units);
def->setUnits(this->m_units);
}
if (this->allowsExpressions())
......@@ -278,29 +282,30 @@ copyTo(ValueItemDefinitionPtr def,
}
}
def->setNumberOfRequiredValues(m_numberOfRequiredValues);
def->setMaxNumberOfValues(m_maxNumberOfValues);
def->setIsExtensible(m_isExtensible);
def->setNumberOfRequiredValues(this->m_numberOfRequiredValues);
def->setMaxNumberOfValues(this->m_maxNumberOfValues);
def->setIsExtensible(this->m_isExtensible);
// Add label(s)
if (m_useCommonLabel)
if (this->m_useCommonLabel)
{
def->setCommonValueLabel(m_valueLabels[0]);
assert(!this->m_valueLabels.empty());
def->setCommonValueLabel(this->m_valueLabels[0]);
}
else if (this->hasValueLabels())
{
for (i=0; i<m_valueLabels.size(); ++i)
for (i=0; i<this->m_valueLabels.size(); ++i)
{
def->setValueLabel(i, m_valueLabels[i]);
def->setValueLabel(i, this->m_valueLabels[i]);
}
}
// Add children item definitions
if (m_itemDefs.size() > 0)
if (this->m_itemDefs.size() > 0)
{
std::map<std::string, smtk::attribute::ItemDefinitionPtr>::const_iterator
itemDefMapIter = m_itemDefs.begin();
for (; itemDefMapIter != m_itemDefs.end(); itemDefMapIter++)
itemDefMapIter = this->m_itemDefs.begin();
for (; itemDefMapIter != this->m_itemDefs.end(); itemDefMapIter++)
{
smtk::attribute::ItemDefinitionPtr itemDef =
itemDefMapIter->second->createCopy(info);
......@@ -309,13 +314,13 @@ copyTo(ValueItemDefinitionPtr def,
}
// Add condition items
if (m_valueToItemAssociations.size() > 0)
if (this->m_valueToItemAssociations.size() > 0)
{
std::map<std::string, std::vector<std::string> >::const_iterator mapIter =
m_valueToItemAssociations.begin();
this->m_valueToItemAssociations.begin();
std::string value;
std::vector<std::string>::const_iterator itemIter;
for (; mapIter != m_valueToItemAssociations.end(); mapIter++)
for (; mapIter != this->m_valueToItemAssociations.end(); mapIter++)
{
value = mapIter->first;
itemIter = mapIter->second.begin();
......
......@@ -20,6 +20,7 @@
#ifndef __smtk_attribute_ValueItemDefinition_h
#define __smtk_attribute_ValueItemDefinition_h
#include <cassert>
#include <string>
#include <set>
#include <map>
......@@ -58,7 +59,10 @@ namespace smtk
std::size_t numberOfDiscreteValues() const
{return this->m_discreteValueEnums.size();}
const std::string &discreteEnum(std::size_t ith) const
{return this->m_discreteValueEnums[ith];}
{
assert(this->m_discreteValueEnums.size() > ith);
return this->m_discreteValueEnums[ith];
}
int defaultDiscreteIndex() const
{return this->m_defaultDiscreteIndex;}
void setDefaultDiscreteIndex(int discreteIndex);
......
......@@ -15,6 +15,7 @@
#define __smtk_attribute_ValueItemDefinitionTemplate_h
#include "smtk/attribute/ValueItemDefinition.h"
#include <cassert>
#include <iostream>
#include <sstream>
......@@ -104,6 +105,7 @@ namespace smtk
template<typename DataT>
void ValueItemDefinitionTemplate<DataT>::updateDiscreteValue()
{
assert(this->m_discreteValues.size() > this->m_defaultDiscreteIndex);
this->setDefaultValue(this->m_discreteValues[this->m_defaultDiscreteIndex]);
}
//----------------------------------------------------------------------------
......@@ -281,6 +283,7 @@ namespace smtk
const DataT& ValueItemDefinitionTemplate<DataT>::defaultValue(std::size_t element) const
{
bool vectorDefault = this->m_defaultValue.size() == this->numberOfRequiredValues();
assert(!vectorDefault || this->m_defaultValue.size() > element);
return this->m_defaultValue.empty() ? this->m_dummy : this->m_defaultValue[vectorDefault ? element : 0];
}
......@@ -324,13 +327,14 @@ namespace smtk
// Copy values & labels
DataT value;
std::string labelStr;
for (std::size_t i=0; i<m_discreteValues.size(); ++i)
assert(this->m_discreteValueEnums.size() >= this->m_discreteValues.size());
for (std::size_t i=0; i < this->m_discreteValues.size(); ++i)
{
value = m_discreteValues[i];
labelStr = m_discreteValueEnums[i];
value = this->m_discreteValues[i];
labelStr = this->m_discreteValueEnums[i];
vdef->addDiscreteValue(value, labelStr);
}
vdef->setDefaultDiscreteIndex(m_defaultDiscreteIndex);
vdef->setDefaultDiscreteIndex(this->m_defaultDiscreteIndex);
}
// Copy superclass *after* our stuff, so that discrete values are set up
......
......@@ -17,6 +17,7 @@
#include "smtk/attribute/RefItem.h"
#include "smtk/attribute/ValueItem.h"
#include "smtk/attribute/ValueItemDefinitionTemplate.h"
#include <cassert>
#include <vector>
#include <stdio.h>
#include <sstream>
......@@ -160,6 +161,7 @@ namespace smtk
{
int index = def->findDiscreteIndex(val);
// Is this the current value?
assert(this->m_discreteIndices.size() > element);
if (index == this->m_discreteIndices[element] )
{
return true;
......@@ -168,11 +170,14 @@ namespace smtk
if (index != -1)
{
this->m_discreteIndices[element] = index;
assert(this->m_values.size() > element);
this->m_values[element] = val;
if (def->allowsExpressions())
{
assert(this->m_expressions.size() > element);
this->m_expressions[element]->unset();
}
assert(this->m_isSet.size() > element);
this->m_isSet[element] = true;
// Update active children if needed - note that
// we currently only support active children based on the
......@@ -187,10 +192,13 @@ namespace smtk
}
if (def->isValueValid(val))
{
assert(this->m_values.size() > element);
this->m_values[element] = val;
assert(this->m_isSet.size() > element);
this->m_isSet[element] = true;
if (def->allowsExpressions())
{
assert(this->m_expressions.size() > element);
this->m_expressions[element]->unset();
}
return true;
......@@ -210,6 +218,7 @@ namespace smtk
std::string
ValueItemTemplate<DataT>::valueAsString(std::size_t element) const
{
assert(this->m_isSet.size() > element);
if (this->m_isSet[element])
{
if (this->isExpression(element))
......@@ -219,6 +228,7 @@ namespace smtk
else
{
std::stringstream buffer;
assert(this->m_values.size() > element);
buffer << this->m_values[element];
return buffer.str();
}
......@@ -312,6 +322,7 @@ namespace smtk
if (def->allowsExpressions())
{
std::size_t i;
assert(this->m_expressions.size() >= n);
for (i = newSize; i < n; i++)
{
this->m_expressions[i]->detachOwningItem();
......@@ -375,6 +386,7 @@ namespace smtk
}
if (def->allowsExpressions())
{
assert(this->m_expressions.size() > element);
this->m_expressions[element]->detachOwningItem();
this->m_expressions.erase(this->m_expressions.begin()+element);
}
......@@ -403,6 +415,7 @@ namespace smtk
}
else
{
assert(def->defaultValues().size() > element);
this->setValue(element,
def->defaultValues().size() > 1 ?
def->defaultValues()[element] :
......@@ -427,6 +440,8 @@ namespace smtk
bool vectorDefault = (dvals.size() == n);
for (i = 0; i < n; i++)
{
assert(this->m_isSet.size() > i);
assert(this->m_values.size() > i);
if (!(this->m_isSet[i] && (vectorDefault ? this->m_values[i] == dvals[i] : this->m_values[i] == dval)))
{
return false;
......@@ -440,6 +455,7 @@ namespace smtk
ValueItemTemplate<DataT>::isUsingDefault(std::size_t element) const
{
const DefType *def = static_cast<const DefType *>(this->definition().get());
assert(this->m_isSet.size() > element);
if (!(def->hasDefault() && this->m_isSet[element]))
{
return false; // Doesn't have a default value
......@@ -448,6 +464,7 @@ namespace smtk
DataT dval = def->defaultValue();
const std::vector<DataT>& dvals = def->defaultValues();
bool vectorDefault = (dvals.size() == def->numberOfRequiredValues());
assert(this->m_values.size() > element);
return (vectorDefault ?
this->m_values[element] == dvals[element] :
this->m_values[element] == dval);
......@@ -507,6 +524,7 @@ namespace smtk
// If we can have expressions then clear them
if (def->allowsExpressions())
{
assert(this->m_expressions.size() >= n);
for (i = 0; i < n; i++)
{
this->m_expressions[i]->unset();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment