[Orxonox-commit 5852] r10512 - in code/branches/core7/src/libraries/core: . class
landauf at orxonox.net
landauf at orxonox.net
Sat May 30 22:59:13 CEST 2015
Author: landauf
Date: 2015-05-30 22:59:13 +0200 (Sat, 30 May 2015)
New Revision: 10512
Modified:
code/branches/core7/src/libraries/core/CoreIncludes.h
code/branches/core7/src/libraries/core/class/Identifier.cc
code/branches/core7/src/libraries/core/class/Identifier.h
Log:
fixed issue: Class(T) may not be allowed in StaticallyInitializedIdentifier::load() because T may not yet be initialized.
now the inheritance is resolved in Identifier::finishInitialization()
Modified: code/branches/core7/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core7/src/libraries/core/CoreIncludes.h 2015-05-30 19:59:31 UTC (rev 10511)
+++ code/branches/core7/src/libraries/core/CoreIncludes.h 2015-05-30 20:59:13 UTC (rev 10512)
@@ -217,31 +217,18 @@
*/
class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance
{
- struct InheritsFrom
- {
- virtual ~InheritsFrom() {}
- virtual Identifier* getParent() = 0;
- };
-
template <class T>
- struct InheritsFromClass : public InheritsFrom
+ struct InheritsFromClass : public Identifier::InheritsFrom
{
- virtual Identifier* getParent() { return Class(T); }
+ virtual Identifier* getParent() const { return Class(T); }
};
public:
StaticallyInitializedIdentifier(Identifier* identifier) : identifier_(identifier) {}
- ~StaticallyInitializedIdentifier()
- {
- for (size_t i = 0; i < this->parents_.size(); ++i)
- delete parents_[i];
- }
virtual void load()
{
IdentifierManager::getInstance().addIdentifier(this->identifier_);
- for (size_t i = 0; i < this->parents_.size(); ++i)
- this->identifier_->inheritsFrom(this->parents_[i]->getParent());
}
virtual void unload()
@@ -254,14 +241,13 @@
template <class T>
inline StaticallyInitializedIdentifier& inheritsFrom()
- { this->parents_.push_back(new InheritsFromClass<T>()); return *this; }
+ { this->identifier_->inheritsFrom(new InheritsFromClass<T>()); return *this; }
inline StaticallyInitializedIdentifier& virtualBase()
{ this->identifier_->setVirtualBase(true); return *this; }
private:
Identifier* identifier_;
- std::vector<InheritsFrom*> parents_;
};
typedef StaticallyInitializedIdentifier SI_I;
Modified: code/branches/core7/src/libraries/core/class/Identifier.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.cc 2015-05-30 19:59:31 UTC (rev 10511)
+++ code/branches/core7/src/libraries/core/class/Identifier.cc 2015-05-30 20:59:13 UTC (rev 10512)
@@ -78,6 +78,9 @@
if (this->factory_)
delete this->factory_;
+ for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)
+ delete (*it);
+
for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
delete (it->second);
for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)
@@ -120,12 +123,12 @@
/**
* @brief Used to define the direct parents of an Identifier of an abstract class.
*/
- Identifier& Identifier::inheritsFrom(Identifier* directParent)
+ Identifier& Identifier::inheritsFrom(InheritsFrom* directParent)
{
- if (this->parents_.empty())
- this->directParents_.push_back(directParent);
+ if (this->directParents_.empty())
+ this->manualDirectParents_.push_back(directParent);
else
- orxout(internal_error) << "Trying to add " << directParent->getName() << " as a direct parent of " << this->getName() << " after the latter was already initialized" << endl;
+ orxout(internal_error) << "Trying to manually add direct parent of " << this->getName() << " after the latter was already initialized" << endl;
return *this;
}
@@ -182,13 +185,17 @@
this->verifyIdentifierTrace();
}
- else if (!this->directParents_.empty())
+ else if (!this->manualDirectParents_.empty())
{
// no parents defined -> this class was manually initialized by calling inheritsFrom<Class>()
// initialize all direct parents
- for (std::list<const Identifier*>::const_iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
- const_cast<Identifier*>(*it)->finishInitialization(); // initialize parent
+ for (std::list<const InheritsFrom*>::const_iterator it = this->manualDirectParents_.begin(); it != this->manualDirectParents_.end(); ++it)
+ {
+ Identifier* directParent = (*it)->getParent();
+ this->directParents_.push_back(directParent);
+ directParent->finishInitialization(); // initialize parent
+ }
// direct parents and their parents are also parents of this identifier (but only add them once)
for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
Modified: code/branches/core7/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.h 2015-05-30 19:59:31 UTC (rev 10511)
+++ code/branches/core7/src/libraries/core/class/Identifier.h 2015-05-30 20:59:13 UTC (rev 10512)
@@ -111,6 +111,13 @@
class _CoreExport Identifier : public Destroyable
{
public:
+ struct InheritsFrom //! helper class to manually define inheritance
+ {
+ virtual ~InheritsFrom() {}
+ virtual Identifier* getParent() const = 0;
+ };
+
+ public:
Identifier(const std::string& name, Factory* factory, bool bLoadable);
Identifier(const Identifier& identifier); // don't copy
virtual ~Identifier();
@@ -148,7 +155,7 @@
/////////////////////////////
////// Class Hierarchy //////
/////////////////////////////
- Identifier& inheritsFrom(Identifier* directParent);
+ Identifier& inheritsFrom(InheritsFrom* directParent);
void initializeParents(const std::list<const Identifier*>& initializationTrace);
void finishInitialization();
@@ -218,6 +225,7 @@
void verifyIdentifierTrace() const;
void addIfNotExists(std::list<const Identifier*>& list, const Identifier* identifierToAdd) const;
+ std::list<const InheritsFrom*> manualDirectParents_; //!< Manually defined direct parents
std::list<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to (sorted by their order of initialization)
std::list<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to (sorted by their order of initialization)
More information about the Orxonox-commit
mailing list