[Orxonox-commit 1058] r5778 - in code/branches/core5/src/libraries: core network/packet
landauf at orxonox.net
landauf at orxonox.net
Thu Sep 24 02:47:53 CEST 2009
Author: landauf
Date: 2009-09-24 02:47:53 +0200 (Thu, 24 Sep 2009)
New Revision: 5778
Removed:
code/branches/core5/src/libraries/core/Factory.cc
code/branches/core5/src/libraries/core/Factory.h
Modified:
code/branches/core5/src/libraries/core/ArgumentCompletionFunctions.cc
code/branches/core5/src/libraries/core/CMakeLists.txt
code/branches/core5/src/libraries/core/ClassFactory.h
code/branches/core5/src/libraries/core/CommandExecutor.cc
code/branches/core5/src/libraries/core/ConfigFileManager.cc
code/branches/core5/src/libraries/core/Core.cc
code/branches/core5/src/libraries/core/CoreIncludes.h
code/branches/core5/src/libraries/core/Identifier.cc
code/branches/core5/src/libraries/core/Identifier.h
code/branches/core5/src/libraries/core/XMLPort.h
code/branches/core5/src/libraries/network/packet/ClassID.cc
Log:
Removed the Factory class.
Moved the networkID<->Identifier map from Factory to Identifier.
Replaced the name<->Identifier map from Factory with the already existing Identifier map in Identifier. This map additionally contains Identifiers without Factory. You can separate them with the new function identifier->hasFactory().
Modified: code/branches/core5/src/libraries/core/ArgumentCompletionFunctions.cc
===================================================================
--- code/branches/core5/src/libraries/core/ArgumentCompletionFunctions.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/ArgumentCompletionFunctions.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -99,7 +99,7 @@
{
ArgumentCompletionList classlist;
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
+ for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
if ((*it).second->hasConfigValues())
classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first)));
@@ -109,9 +109,9 @@
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname)
{
ArgumentCompletionList configvalues;
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname);
+ std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getStringIdentifierMap().find(classname);
- if (identifier != Identifier::getIdentifierMapEnd() && (*identifier).second->hasConfigValues())
+ if (identifier != Identifier::getStringIdentifierMapEnd() && (*identifier).second->hasConfigValues())
{
for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it)
configvalues.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first)));
@@ -123,8 +123,8 @@
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname)
{
ArgumentCompletionList oldvalue;
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
+ std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
+ if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
{
std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
Modified: code/branches/core5/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/core5/src/libraries/core/CMakeLists.txt 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/CMakeLists.txt 2009-09-24 00:47:53 UTC (rev 5778)
@@ -48,7 +48,6 @@
Executor.cc
# hierarchy
- Factory.cc
Identifier.cc
MetaObjectList.cc
@@ -67,7 +66,7 @@
Shell.cc
TclBind.cc
TclThreadManager.cc
-
+
# multithreading
Thread.cc
ThreadPool.cc
Modified: code/branches/core5/src/libraries/core/ClassFactory.h
===================================================================
--- code/branches/core5/src/libraries/core/ClassFactory.h 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/ClassFactory.h 2009-09-24 00:47:53 UTC (rev 5778)
@@ -41,7 +41,6 @@
#include <string>
#include "util/Debug.h"
-#include "Factory.h"
#include "Identifier.h"
namespace orxonox
@@ -70,10 +69,9 @@
};
/**
- @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.
+ @brief Adds the ClassFactory to the Identifier of the same type.
@param name The name of the class
@param bLoadable True if the class can be loaded through XML
- @return Always true (this is needed because the compiler only allows assignments before main())
*/
template <class T>
ClassFactory<T>::ClassFactory(const std::string& name, bool bLoadable)
@@ -81,7 +79,6 @@
COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
- Factory::add(name, ClassIdentifier<T>::getIdentifier());
}
/**
Modified: code/branches/core5/src/libraries/core/CommandExecutor.cc
===================================================================
--- code/branches/core5/src/libraries/core/CommandExecutor.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/CommandExecutor.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -467,7 +467,7 @@
{
CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear();
std::string lowercase = getLowercase(fragment);
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
+ for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapBegin(); it != Identifier::getLowercaseStringIdentifierMapEnd(); ++it)
if ((*it).second->hasConsoleCommands())
if ((*it).first.find(lowercase) == 0 || fragment == "")
CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
@@ -515,8 +515,8 @@
Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name)
{
std::string lowercase = getLowercase(name);
- std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(lowercase);
- if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands())
+ std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMap().find(lowercase);
+ if ((it != Identifier::getLowercaseStringIdentifierMapEnd()) && (*it).second->hasConsoleCommands())
return (*it).second;
return 0;
Modified: code/branches/core5/src/libraries/core/ConfigFileManager.cc
===================================================================
--- code/branches/core5/src/libraries/core/ConfigFileManager.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/ConfigFileManager.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -47,8 +47,8 @@
bool config(const std::string& classname, const std::string& varname, const std::string& value)
{
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
+ std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
+ if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
{
std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
@@ -59,8 +59,8 @@
bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)
{
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseIdentifierMapEnd())
+ std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
+ if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
{
std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
@@ -375,8 +375,8 @@
{
for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
{
- std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName());
- if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues())
+ std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getStringIdentifierMap().find((*it1)->getName());
+ if (it2 != Identifier::getStringIdentifierMapEnd() && (*it2).second->hasConfigValues())
{
// The section exists, delete comment
if (bCleanComments)
@@ -454,7 +454,7 @@
{
if (this->type_ == ConfigFileType::Settings)
{
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
+ for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
{
if (it->second->hasConfigValues())
{
Modified: code/branches/core5/src/libraries/core/Core.cc
===================================================================
--- code/branches/core5/src/libraries/core/Core.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/Core.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -68,7 +68,6 @@
#include "ConfigValueIncludes.h"
#include "CoreIncludes.h"
#include "DynLibManager.h"
-#include "Factory.h"
#include "GameMode.h"
#include "GraphicsManager.h"
#include "GUIManager.h"
@@ -333,7 +332,7 @@
this->languageInstance_.reset(new Language());
// creates the class hierarchy for all classes with factories
- Factory::createClassHierarchy();
+ Identifier::createClassHierarchy();
// Do this soon after the ConfigFileManager has been created to open up the
// possibility to configure everything below here
Modified: code/branches/core5/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core5/src/libraries/core/CoreIncludes.h 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/CoreIncludes.h 2009-09-24 00:47:53 UTC (rev 5778)
@@ -28,7 +28,7 @@
/**
@file
- @brief Definition of macros for Identifier and Factory.
+ @brief Definition of macros for Identifiers
Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
@@ -45,7 +45,6 @@
#include "util/Debug.h"
#include "Identifier.h"
#include "SubclassIdentifier.h"
-#include "Factory.h"
#include "ClassFactory.h"
#include "ObjectList.h"
@@ -76,14 +75,14 @@
InternRegisterObject(ClassName, true)
/**
- @brief Creates the entry in the Factory.
+ @brief Creates the Factory.
@param ClassName The name of the class
*/
#define CreateFactory(ClassName) \
BaseFactory* ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true)
/**
- @brief Creates the entry in the Factory for classes which should not be loaded through XML.
+ @brief Creates the Factory for classes which should not be loaded through XML.
@param ClassName The name of the class
*/
#define CreateUnloadableFactory(ClassName) \
@@ -105,7 +104,7 @@
*/
inline Identifier* ClassByString(const std::string& name)
{
- return Factory::getIdentifier(name);
+ return Identifier::getIdentifierByString(name);
}
/**
@@ -114,7 +113,7 @@
*/
inline Identifier* ClassByID(uint32_t id)
{
- return Factory::getIdentifier(id);
+ return Identifier::getIdentifierByID(id);
}
}
Deleted: code/branches/core5/src/libraries/core/Factory.cc
===================================================================
--- code/branches/core5/src/libraries/core/Factory.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/Factory.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -1,129 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the Factory class.
-*/
-
-#include "Factory.h"
-
-#include "util/Debug.h"
-#include "Identifier.h"
-#include "BaseObject.h"
-
-namespace orxonox
-{
- /**
- @brief Returns the Identifier with a given name.
- @param name The name of the wanted Identifier
- @return The Identifier
- */
- Identifier* Factory::getIdentifier(const std::string& name)
- {
- std::map<std::string, Identifier*>::const_iterator it = getFactoryPointer()->identifierStringMap_.find(name);
- if (it != getFactoryPointer()->identifierStringMap_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
- @brief Returns the Identifier with a given network ID.
- @param id The network ID of the wanted Identifier
- @return The Identifier
- */
- Identifier* Factory::getIdentifier(const uint32_t id)
- {
- std::map<uint32_t, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id);
- if (it != getFactoryPointer()->identifierNetworkIDMap_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
- @brief Adds a new Identifier to both maps.
- @param name The name of the identifier
- @param identifier The identifier to add
- */
- void Factory::add(const std::string& name, Identifier* identifier)
- {
- getFactoryPointer()->identifierStringMap_[name] = identifier;
- getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
- }
-
- /**
- @brief Removes the entry with the old network ID and adds a new one.
- @param identifier The identifier to change
- @param oldID The old networkID
- @param newID The new networkID
- */
- void Factory::changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID)
- {
-// getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
- getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier;
- }
-
- /**
- @brief Cleans the NetworkID map (needed on clients for correct initialization)
- */
- void Factory::cleanNetworkIDs()
- {
- getFactoryPointer()->identifierNetworkIDMap_.clear();
- }
-
- /**
- @brief Creates the class-hierarchy by creating and destroying one object of each type.
- */
- void Factory::createClassHierarchy()
- {
- COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
- std::map<std::string, Identifier*>::iterator it;
- it = getFactoryPointer()->identifierStringMap_.begin();
- (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
- for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
- {
- // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
- BaseObject* temp = (*it).second->fabricate(0);
- delete temp;
- }
- (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
- COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
- }
-
- /**
- @brief Ensures the Factory gets created in the right moment.
- @return The Factory.
- */
- Factory* Factory::getFactoryPointer()
- {
- static Factory theOneAndOnlyFactoryInstance = Factory();
- return &theOneAndOnlyFactoryInstance;
- }
-}
Deleted: code/branches/core5/src/libraries/core/Factory.h
===================================================================
--- code/branches/core5/src/libraries/core/Factory.h 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/Factory.h 2009-09-24 00:47:53 UTC (rev 5778)
@@ -1,90 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the Factory and the BaseFactory class.
-
- The Factory is a singleton, containing two maps to map either the name or the network ID
- of a class with the corresponding Identifier.
-
- Usage:
- ID(classname) or ID(networkID) returns the corresponding Identifier.
-
-
- BaseObject is the parent of ClassFactory which is defined in ClassFactory.h.
- It can't be defined in ClassFactory.h, because of circular dependencies.
-*/
-
-#ifndef _Factory_H__
-#define _Factory_H__
-
-#include "CorePrereqs.h"
-
-#include <map>
-#include <string>
-
-namespace orxonox
-{
- // ###############################
- // ### Factory ###
- // ###############################
- //! The Factory is used to map the name or the network ID of a class with its Identifier.
- class _CoreExport Factory
- {
- public:
- static Identifier* getIdentifier(const std::string& name);
- static Identifier* getIdentifier(const uint32_t id);
- static void add(const std::string& name, Identifier* identifier);
- static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID);
- static void cleanNetworkIDs();
- static void createClassHierarchy();
-
- static Factory* getFactoryPointer(); // avoid overriding order problem in the static intialisation process
-
- /** @brief Returns the factory-map. */
- static const std::map<std::string, Identifier*>& getFactoryMap()
- { return Factory::getFactoryPointer()->identifierStringMap_; }
- /** @brief Returns the begin-iterator of the factory-map. */
- static std::map<std::string, Identifier*>::const_iterator getFactoryMapBegin()
- { return Factory::getFactoryPointer()->identifierStringMap_.begin(); }
- /** @brief Returns the end-iterator of the factory-map. */
- static std::map<std::string, Identifier*>::const_iterator getFactoryMapEnd()
- { return Factory::getFactoryPointer()->identifierStringMap_.end(); }
-
- private:
- Factory() {} // don't create
- Factory(const Factory& factory); // don't copy
- ~Factory() {} // don't delete
-
- std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier
- std::map<uint32_t, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier
- };
-}
-
-#endif /* _Factory_H__ */
Modified: code/branches/core5/src/libraries/core/Identifier.cc
===================================================================
--- code/branches/core5/src/libraries/core/Identifier.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/Identifier.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -195,6 +195,28 @@
}
/**
+ @brief Creates the class-hierarchy by creating and destroying one object of each type.
+ */
+ void Identifier::createClassHierarchy()
+ {
+ COUT(3) << "*** Identifier: Create class-hierarchy" << std::endl;
+ std::map<std::string, Identifier*>::const_iterator it;
+ it = Identifier::getStringIdentifierMap().begin();
+ Identifier::getStringIdentifierMap().begin()->second->startCreatingHierarchy();
+ for (it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
+ {
+ // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
+ if (it->second->hasFactory())
+ {
+ BaseObject* temp = it->second->fabricate(0);
+ delete temp;
+ }
+ }
+ Identifier::getStringIdentifierMap().begin()->second->stopCreatingHierarchy();
+ COUT(3) << "*** Identifier: Finished class-hierarchy creation" << std::endl;
+ }
+
+ /**
@brief Destroys all Identifiers. Called when exiting the program.
*/
void Identifier::destroyAllIdentifiers()
@@ -213,8 +235,9 @@
{
this->name_ = name;
this->bSetName_ = true;
- Identifier::getIdentifierMapIntern()[name] = this;
- Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
+ Identifier::getStringIdentifierMapIntern()[name] = this;
+ Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
+ Identifier::getIDIdentifierMapIntern()[this->networkID_] = this;
}
}
@@ -239,12 +262,13 @@
}
/**
- @brief Sets the network ID to a new value and changes the entry in the Factory.
+ @brief Sets the network ID to a new value and changes the entry in the ID-Identifier-map.
@param id The new network ID
*/
void Identifier::setNetworkID(uint32_t id)
{
- Factory::changeNetworkID(this, this->networkID_, id);
+// Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
+ Identifier::getIDIdentifierMapIntern()[id] = this;
this->networkID_ = id;
}
@@ -303,26 +327,72 @@
}
/**
- @brief Returns the map that stores all Identifiers.
+ @brief Returns the map that stores all Identifiers with their names.
@return The map
*/
- std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
+ std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
{
static std::map<std::string, Identifier*> identifierMap;
return identifierMap;
}
/**
- @brief Returns the map that stores all Identifiers.
+ @brief Returns the map that stores all Identifiers with their names in lowercase.
@return The map
*/
- std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
+ std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
{
static std::map<std::string, Identifier*> lowercaseIdentifierMap;
return lowercaseIdentifierMap;
}
/**
+ @brief Returns the map that stores all Identifiers with their network IDs.
+ @return The map
+ */
+ std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
+ {
+ static std::map<uint32_t, Identifier*> identifierMap;
+ return identifierMap;
+ }
+
+ /**
+ @brief Returns the Identifier with a given name.
+ @param name The name of the wanted Identifier
+ @return The Identifier
+ */
+ Identifier* Identifier::getIdentifierByString(const std::string& name)
+ {
+ std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
+ if (it != Identifier::getStringIdentifierMapIntern().end())
+ return it->second;
+ else
+ return 0;
+ }
+
+ /**
+ @brief Returns the Identifier with a given network ID.
+ @param id The network ID of the wanted Identifier
+ @return The Identifier
+ */
+ Identifier* Identifier::getIdentifierByID(const uint32_t id)
+ {
+ std::map<uint32_t, Identifier*>::const_iterator it = Identifier::getIDIdentifierMapIntern().find(id);
+ if (it != Identifier::getIDIdentifierMapIntern().end())
+ return it->second;
+ else
+ return 0;
+ }
+
+ /**
+ @brief Cleans the NetworkID map (needed on clients for correct initialization)
+ */
+ void Identifier::clearNetworkIDs()
+ {
+ Identifier::getIDIdentifierMapIntern().clear();
+ }
+
+ /**
@brief Adds the ConfigValueContainer of a variable, given by the string of its name.
@param varname The name of the variablee
@param container The container
Modified: code/branches/core5/src/libraries/core/Identifier.h
===================================================================
--- code/branches/core5/src/libraries/core/Identifier.h 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/Identifier.h 2009-09-24 00:47:53 UTC (rev 5778)
@@ -86,16 +86,33 @@
*/
class _CoreExport Identifier
{
- template <class T>
- friend class SubclassIdentifier;
+ public:
+ /** @brief Returns the name of the class the Identifier belongs to. @return The name */
+ inline const std::string& getName() const { return this->name_; }
+ void setName(const std::string& name);
- friend class Factory;
+ /** @brief Returns the network ID to identify a class through the network. @return the network ID */
+ inline const uint32_t getNetworkID() const { return this->networkID_; }
+ void setNetworkID(uint32_t id);
- public:
+ /** @brief Returns the unique ID of the class */
+ FORCEINLINE unsigned int getClassID() const { return this->classID_; }
+
+ /** @brief Returns the list of all existing objects of this class. @return The list */
+ inline ObjectListBase* getObjects() const { return this->objects_; }
+
/** @brief Sets the Factory. @param factory The factory to assign */
inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
+ /** @brief Returns true if the Identifier has a Factory. */
+ inline bool hasFactory() const { return (this->factory_ != 0); }
BaseObject* fabricate(BaseObject* creator);
+
+ /** @brief Returns true if the class can be loaded through XML. */
+ inline bool isLoadable() const { return this->bLoadable_; }
+ /** @brief Set the class to be loadable through XML or not. */
+ inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
+
bool isA(const Identifier* identifier) const;
bool isExactlyA(const Identifier* identifier) const;
bool isChildOf(const Identifier* identifier) const;
@@ -103,21 +120,15 @@
bool isParentOf(const Identifier* identifier) const;
bool isDirectParentOf(const Identifier* identifier) const;
- /** @brief Returns true if the class can be loaded through XML. */
- inline bool isLoadable() const { return this->bLoadable_; }
- /** @brief Set the class to be loadable through XML or not. */
- inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
- /** @brief Returns the list of all existing objects of this class. @return The list */
- inline ObjectListBase* getObjects() const
- { return this->objects_; }
+ /////////////////////////////
+ ////// Class Hierarchy //////
+ /////////////////////////////
+ static void createClassHierarchy();
- /** @brief Returns the name of the class the Identifier belongs to. @return The name */
- inline const std::string& getName() const { return this->name_; }
- void setName(const std::string& name);
+ /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
+ inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
- virtual void updateConfigValues(bool updateChildren = true) const = 0;
-
/** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
/** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
@@ -147,21 +158,46 @@
inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
- /** @brief Returns the map that stores all Identifiers. @return The map */
- static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); }
- /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); }
+ //////////////////////////
+ ///// Identifier Map /////
+ //////////////////////////
+ static void destroyAllIdentifiers();
+ static Identifier* getIdentifierByString(const std::string& name);
+ static Identifier* getIdentifierByID(uint32_t id);
+
+ static void clearNetworkIDs();
+
+ /** @brief Returns the map that stores all Identifiers with their names. @return The map */
+ static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); }
+ /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. @return The const_iterator */
+ static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); }
+ /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names. @return The const_iterator */
+ static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
+
/** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
- static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }
+ static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); }
/** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }
+ static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); }
/** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
- static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); }
+ static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
+ /** @brief Returns the map that stores all Identifiers with their IDs. @return The map */
+ static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); }
+ /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. @return The const_iterator */
+ static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); }
+ /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. @return The const_iterator */
+ static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
+
+ /////////////////////////
+ ///// Config Values /////
+ /////////////////////////
+ virtual void updateConfigValues(bool updateChildren = true) const = 0;
+
+ /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
+ inline bool hasConfigValues() const { return this->bHasConfigValues_; }
+
/** @brief Returns the map that stores all config values. @return The const_iterator */
inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }
/** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */
@@ -176,7 +212,17 @@
/** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */
inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
+ void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
+ ConfigValueContainer* getConfigValueContainer(const std::string& varname);
+ ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
+
+ ////////////////////////////
+ ///// Console Commands /////
+ ////////////////////////////
+ /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
+ inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
+
/** @brief Returns the map that stores all console commands. @return The const_iterator */
inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; }
/** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
@@ -191,6 +237,14 @@
/** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
+ ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
+ ConsoleCommand* getConsoleCommand(const std::string& name) const;
+ ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
+
+
+ ///////////////////
+ ///// XMLPort /////
+ ///////////////////
/** @brief Returns the map that stores all XMLPort params. @return The const_iterator */
inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; }
/** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort params. @return The const_iterator */
@@ -212,27 +266,6 @@
/** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */
inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); }
- /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
- inline bool hasConfigValues() const { return this->bHasConfigValues_; }
- /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
- inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
-
- /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
- inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
-
- /** @brief Returns the network ID to identify a class through the network. @return the network ID */
- inline const uint32_t getNetworkID() const { return this->networkID_; }
-
- /** @brief Sets the network ID to a new value. @param id The new value */
- void setNetworkID(uint32_t id);
-
- /** @brief Returns the unique ID of the class */
- FORCEINLINE unsigned int getClassID() const { return this->classID_; }
-
- void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
- ConfigValueContainer* getConfigValueContainer(const std::string& varname);
- ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
-
void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
@@ -242,14 +275,7 @@
void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container);
XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname);
- ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
- ConsoleCommand* getConsoleCommand(const std::string& name) const;
- ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
- void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
-
- static void destroyAllIdentifiers();
-
protected:
Identifier();
Identifier(const Identifier& identifier); // don't copy
@@ -258,10 +284,14 @@
static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
virtual void createSuperFunctionCaller() const = 0;
- /** @brief Returns the map that stores all Identifiers. @return The map */
- static std::map<std::string, Identifier*>& getIdentifierMapIntern();
+ void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
+
+ /** @brief Returns the map that stores all Identifiers with their names. @return The map */
+ static std::map<std::string, Identifier*>& getStringIdentifierMapIntern();
/** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
- static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
+ static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern();
+ /** @brief Returns the map that stores all Identifiers with their network IDs. @return The map */
+ static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
/** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
@@ -344,8 +374,8 @@
#include "Super.h"
public:
- static ClassIdentifier<T> *getIdentifier();
- static ClassIdentifier<T> *getIdentifier(const std::string& name);
+ static ClassIdentifier<T>* getIdentifier();
+ static ClassIdentifier<T>* getIdentifier(const std::string& name);
bool initialiseObject(T* object, const std::string& className, bool bRootClass);
@@ -376,8 +406,8 @@
template <class T>
inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
{
- // check if the static field has already been filled
- if (ClassIdentifier<T>::classIdentifier_s == 0)
+ // check if the Identifier already exists
+ if (!ClassIdentifier<T>::classIdentifier_s)
ClassIdentifier<T>::initialiseIdentifier();
return ClassIdentifier<T>::classIdentifier_s;
Modified: code/branches/core5/src/libraries/core/XMLPort.h
===================================================================
--- code/branches/core5/src/libraries/core/XMLPort.h 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/core/XMLPort.h 2009-09-24 00:47:53 UTC (rev 5778)
@@ -50,7 +50,6 @@
#include "util/Exception.h"
#include "util/MultiType.h"
#include "util/OrxAssert.h"
-#include "Factory.h"
#include "Identifier.h"
#include "Executor.h"
#include "BaseObject.h"
@@ -547,7 +546,7 @@
{
for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
{
- Identifier* identifier = Factory::getIdentifier(child->Value());
+ Identifier* identifier = Identifier::getIdentifierByString(child->Value());
if (identifier)
{
if (identifier->isA(ClassIdentifier<O>::getIdentifier()))
Modified: code/branches/core5/src/libraries/network/packet/ClassID.cc
===================================================================
--- code/branches/core5/src/libraries/network/packet/ClassID.cc 2009-09-23 22:15:20 UTC (rev 5777)
+++ code/branches/core5/src/libraries/network/packet/ClassID.cc 2009-09-24 00:47:53 UTC (rev 5778)
@@ -48,17 +48,17 @@
ClassID::ClassID( ) : Packet(){
Identifier *id;
std::string classname;
- unsigned int nrOfClasses=0;
+ unsigned int nrOfClasses=0;
unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
uint32_t network_id;
flags_ = flags_ | PACKET_FLAGS_CLASSID;
std::queue<std::pair<uint32_t, std::string> > tempQueue;
-
+
//calculate total needed size (for all strings and integers)
- std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
- for(;it != Factory::getFactoryMapEnd();++it){
+ std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin();
+ for(;it != Identifier::getStringIdentifierMapEnd();++it){
id = (*it).second;
- if(id == NULL)
+ if(id == NULL || !id->hasFactory())
continue;
classname = id->getName();
network_id = id->getNetworkID();
@@ -69,17 +69,17 @@
++nrOfClasses;
packetSize += (classname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t);
}
-
+
this->data_=new uint8_t[ packetSize ];
//set the appropriate packet id
assert(this->data_);
*(Type::Value *)(this->data_ + _PACKETID ) = Type::ClassID;
-
+
uint8_t *temp=data_+sizeof(uint32_t);
// save the number of all classes
*(uint32_t*)temp = nrOfClasses;
temp += sizeof(uint32_t);
-
+
// now save all classids and classnames
std::pair<uint32_t, std::string> tempPair;
while( !tempQueue.empty() ){
@@ -90,9 +90,9 @@
memcpy(temp+2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);
temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
}
-
+
COUT(5) << "classid packetSize is " << packetSize << endl;
-
+
}
ClassID::ClassID( uint8_t* data, unsigned int clientID )
@@ -110,7 +110,7 @@
uint32_t nrOfClasses = *(uint32_t*)temp;
temp += sizeof(uint32_t);
totalsize += sizeof(uint32_t); // storage size for nr of all classes
-
+
for(unsigned int i=0; i<nrOfClasses; i++){
totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));
}
@@ -124,18 +124,18 @@
uint32_t networkID;
uint32_t stringsize;
unsigned char *classname;
-
-
- //clean the map of network ids
- Factory::cleanNetworkIDs();
-
+
+
+ //clear the map of network ids
+ Identifier::clearNetworkIDs();
+
COUT(4) << "=== processing classids: " << endl;
std::pair<uint32_t, std::string> tempPair;
Identifier *id;
// read the total number of classes
nrOfClasses = *(uint32_t*)temp;
temp += sizeof(uint32_t);
-
+
for( int i=0; i<nrOfClasses; i++){
networkID = *(uint32_t*)temp;
stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
More information about the Orxonox-commit
mailing list