#1292 Fixed CppCheck Issues in AppFwk/cafProjectDataModel

This commit is contained in:
Magne Sjaastad 2017-03-06 15:58:24 +01:00
parent 9179ae2a14
commit 63baebc698
16 changed files with 32 additions and 46 deletions

View File

@ -97,8 +97,7 @@ TEST(ChildArrayFieldHandle, DerivedObjects)
containerObj->derivedObjs.push_back(s1);
containerObj->derivedObjs.push_back(s2);
SimpleObjDerived* myObj = NULL;
myObj = findObjectById<SimpleObjDerived*>(containerObj->derivedObjs.begin(), containerObj->derivedObjs.end(), 2);
SimpleObjDerived* myObj = findObjectById<SimpleObjDerived*>(containerObj->derivedObjs.begin(), containerObj->derivedObjs.end(), 2);
EXPECT_EQ(s2, myObj);
myObj = findObjectById<SimpleObjDerived*>(containerObj->derivedObjs.begin(), containerObj->derivedObjs.end(), -1);
@ -121,8 +120,7 @@ TEST(ChildArrayFieldHandle, DerivedOtherObjects)
containerObj->derivedOtherObjs.push_back(s1);
containerObj->derivedOtherObjs.push_back(s2);
SimpleObjDerivedOther* myObj = NULL;
myObj = findObjectById<SimpleObjDerivedOther*>(containerObj->derivedOtherObjs.begin(), containerObj->derivedOtherObjs.end(), s2Id);
SimpleObjDerivedOther* myObj = findObjectById<SimpleObjDerivedOther*>(containerObj->derivedOtherObjs.begin(), containerObj->derivedOtherObjs.end(), s2Id);
EXPECT_EQ(s2, myObj);
myObj = findObjectById<SimpleObjDerivedOther*>(containerObj->derivedOtherObjs.begin(), containerObj->derivedOtherObjs.end(), -1);

View File

@ -212,7 +212,7 @@ TEST(BaseTest, NormalPdmField)
class A : public caf::PdmObjectHandle
{
public:
A(const std::vector<double>& testValue) : field2(testValue), field3(field2)
explicit A(const std::vector<double>& testValue) : field2(testValue), field3(field2)
{
this->addField(&field1, "field1");
this->addField(&field2, "field2");
@ -440,7 +440,9 @@ TEST(BaseTest, PdmChildField)
class A : public caf::PdmObjectHandle
{
public:
A(Child* a) :field2(a)
explicit A(Child* a)
: field2(a),
b(0)
{
this->addField(&field2, "field2");
}
@ -455,7 +457,6 @@ TEST(BaseTest, PdmChildField)
};
{
Parent* parent = new Parent;
Child* testValue = new Child;
// Constructor assignment
@ -464,7 +465,7 @@ TEST(BaseTest, PdmChildField)
// Guarded
delete testValue;
EXPECT_EQ((Child*)0, a.field2);
EXPECT_EQ(static_cast<Child*>(nullptr), a.field2);
}
{
A a(NULL);
@ -492,13 +493,11 @@ TEST(BaseTest, PdmPtrField)
InheritedDemoObj* ihd2 = new InheritedDemoObj;
// Direct access
EXPECT_EQ((InheritedDemoObj*)NULL, ihd1->m_ptrField);
InheritedDemoObj* accessedIhd = NULL;
EXPECT_EQ(static_cast<InheritedDemoObj*>(nullptr), ihd1->m_ptrField);
// Assignment
ihd1->m_ptrField = ihd1;
accessedIhd = ihd1->m_ptrField;
InheritedDemoObj* accessedIhd = ihd1->m_ptrField;
EXPECT_EQ(ihd1, accessedIhd);
ihd1->m_ptrField = caf::PdmPointer<InheritedDemoObj>(ihd2);

View File

@ -16,7 +16,8 @@
class SimpleObj : public caf::PdmObjectHandle
{
public:
SimpleObj() : PdmObjectHandle()
SimpleObj() : PdmObjectHandle(),
m_doubleMember(0.0)
{
this->addField(&m_position, "m_position");
this->addField(&m_dir, "m_dir");

View File

@ -121,7 +121,7 @@ void PdmObjectHandle::addField(PdmFieldHandle* field, const QString& keyword)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle* PdmObjectHandle::findField(const QString& keyword)
PdmFieldHandle* PdmObjectHandle::findField(const QString& keyword) const
{
std::vector<PdmFieldHandle*> fields;
this->fields(fields);

View File

@ -28,7 +28,7 @@ public:
/// The registered fields contained in this PdmObject.
void fields(std::vector<PdmFieldHandle*>& fields) const;
PdmFieldHandle* findField(const QString& keyword);
PdmFieldHandle* findField(const QString& keyword) const;
/// The field referencing this object as a child
PdmFieldHandle* parentField() const;

View File

@ -11,14 +11,6 @@ caf::Tristate::Tristate()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::Tristate::operator=(const Tristate& other)
{
m_state = other.m_state;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -20,7 +20,6 @@ public:
public:
Tristate();
void operator=(const Tristate& other);
void operator=(const State& state);
bool operator==(const Tristate& other) const;

View File

@ -97,7 +97,7 @@ private:
class PdmUiProxyEditorHandle: public PdmUiEditorHandle
{
public:
PdmUiProxyEditorHandle(PdmUiEditorHandle* mainEditorHandle) : PdmUiEditorHandle() { m_mainEditorHandle = mainEditorHandle; }
explicit PdmUiProxyEditorHandle(PdmUiEditorHandle* mainEditorHandle) : PdmUiEditorHandle() { m_mainEditorHandle = mainEditorHandle; }
virtual ~PdmUiProxyEditorHandle() {};
protected: // Interface to override:

View File

@ -137,7 +137,7 @@ bool PdmOptionItemInfo::findValues(const QList<PdmOptionItemInfo>& optionList, Q
for (int i = 0; i < valuesSelectedInField.size(); ++i)
{
std::list<std::pair<QVariant, unsigned int> >::iterator it;
for (it = optionVariantAndIndexPairs.begin(); it != optionVariantAndIndexPairs.end(); it++)
for (it = optionVariantAndIndexPairs.begin(); it != optionVariantAndIndexPairs.end(); ++it)
{
if (PdmUiFieldSpecialization<T>::isDataElementEqual(valuesSelectedInField[i], it->first))
{

View File

@ -75,7 +75,7 @@ PdmUiGroup* PdmUiOrdering::addNewGroup(QString displayName)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmUiOrdering::contains(const PdmUiItem* item)
bool PdmUiOrdering::contains(const PdmUiItem* item) const
{
for (size_t i = 0; i < m_ordering.size(); ++i)
{

View File

@ -70,7 +70,7 @@ public:
void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; }
const std::vector<PdmUiItem*>& uiItems() const { return m_ordering; }
bool contains(const PdmUiItem* item);
bool contains(const PdmUiItem* item) const;
private:
// Private copy constructor and assignment to prevent this. (The vectors below will make trouble)

View File

@ -71,7 +71,7 @@ void PdmUiTreeOrdering::add(PdmFieldHandle* field, QString uiConfigName)
}
else
{
PdmUiTreeOrdering* child = new PdmUiTreeOrdering(this, field);
new PdmUiTreeOrdering(this, field);
}
}
@ -82,7 +82,7 @@ void PdmUiTreeOrdering::add(PdmObjectHandle* object)
{
assert(object);
PdmUiTreeOrdering* child = new PdmUiTreeOrdering(this, object);
new PdmUiTreeOrdering(this, object);
}
//--------------------------------------------------------------------------------------------------

View File

@ -63,8 +63,8 @@ class PdmUiTreeOrdering;
class PdmUiTreeOrdering
{
public:
PdmUiTreeOrdering(PdmObjectHandle* pdmItem );
PdmUiTreeOrdering(PdmFieldHandle* pdmField );
explicit PdmUiTreeOrdering(PdmObjectHandle* pdmItem );
explicit PdmUiTreeOrdering(PdmFieldHandle* pdmField );
PdmUiTreeOrdering(const QString & title, const QString& iconResourceName );
~PdmUiTreeOrdering();

View File

@ -28,7 +28,7 @@ public:
CAF_PDM_XML_InitField(&m_name, "Name");
}
ItemPdmObject(QString name) : PdmObjectHandle(), PdmXmlObjectHandle(this, false)
explicit ItemPdmObject(QString name) : PdmObjectHandle(), PdmXmlObjectHandle(this, false)
{
CAF_PDM_XML_InitField(&m_name, "Name");
m_name = name;

View File

@ -192,7 +192,8 @@ class SimpleObj : public caf::PdmObjectHandle, public caf::PdmXmlObjectHandle
{
CAF_PDM_XML_HEADER_INIT;
public:
SimpleObj() : PdmObjectHandle(), PdmXmlObjectHandle(this, false)
SimpleObj() : PdmObjectHandle(), PdmXmlObjectHandle(this, false),
m_doubleMember(0.0)
{
CAF_PDM_XML_InitField(&m_position, "Position");
CAF_PDM_XML_InitField(&m_dir, "Dir");

View File

@ -61,7 +61,8 @@ class SimpleObj: public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
SimpleObj() : PdmObject()
SimpleObj() : PdmObject(),
m_doubleMember(0.0)
{
CAF_PDM_InitObject("SimpleObj", "", "Tooltip SimpleObj", "WhatsThis SimpleObj");
@ -93,6 +94,7 @@ public:
m_dir = other.m_dir;
m_up = other.m_up;
m_numbers = other.m_numbers;
m_doubleMember = other.m_doubleMember;
}
~SimpleObj() {}
@ -751,31 +753,26 @@ TEST(BaseTest, PdmPointer)
TEST(BaseTest, PdmObjectFactory)
{
{
SimpleObj* s = NULL;
s = dynamic_cast<SimpleObj*> (caf::PdmDefaultObjectFactory::instance()->create("SimpleObj"));
SimpleObj* s = dynamic_cast<SimpleObj*> (caf::PdmDefaultObjectFactory::instance()->create("SimpleObj"));
EXPECT_TRUE(s != NULL);
}
{
DemoPdmObject* s = NULL;
s = dynamic_cast<DemoPdmObject*> (caf::PdmDefaultObjectFactory::instance()->create("DemoPdmObject"));
DemoPdmObject* s = dynamic_cast<DemoPdmObject*> (caf::PdmDefaultObjectFactory::instance()->create("DemoPdmObject"));
EXPECT_TRUE(s != NULL);
delete s;
}
{
InheritedDemoObj* s = NULL;
s = dynamic_cast<InheritedDemoObj*> (caf::PdmDefaultObjectFactory::instance()->create("InheritedDemoObj"));
InheritedDemoObj* s = dynamic_cast<InheritedDemoObj*> (caf::PdmDefaultObjectFactory::instance()->create("InheritedDemoObj"));
EXPECT_TRUE(s != NULL);
}
{
caf::PdmDocument* s = NULL;
s = dynamic_cast<caf::PdmDocument*> (caf::PdmDefaultObjectFactory::instance()->create("PdmDocument"));
caf::PdmDocument* s = dynamic_cast<caf::PdmDocument*> (caf::PdmDefaultObjectFactory::instance()->create("PdmDocument"));
EXPECT_TRUE(s != NULL);
}
{
caf::PdmObjectGroup* s = NULL;
s = dynamic_cast<caf::PdmObjectGroup*> (caf::PdmDefaultObjectFactory::instance()->create("PdmObjectGroup"));
caf::PdmObjectGroup* s = dynamic_cast<caf::PdmObjectGroup*> (caf::PdmDefaultObjectFactory::instance()->create("PdmObjectGroup"));
EXPECT_TRUE(s != NULL);
}
@ -959,7 +956,6 @@ TEST(BaseTest, PdmReferenceHelper)
s3->m_position = 3000;
InheritedDemoObj* ihd1 = new InheritedDemoObj;
caf::PdmChildArrayFieldHandle* listField = &(ihd1->m_simpleObjectsField);
ihd1->m_simpleObjectsField.push_back(new SimpleObj);
ihd1->m_simpleObjectsField.push_back(s1);