[Orxonox-commit 2566] r7271 - in code/trunk/src: libraries/core libraries/core/input modules/objects/triggers

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Aug 30 20:07:38 CEST 2010


Author: rgrieder
Date: 2010-08-30 20:07:38 +0200 (Mon, 30 Aug 2010)
New Revision: 7271

Modified:
   code/trunk/src/libraries/core/CorePrereqs.h
   code/trunk/src/libraries/core/Event.cc
   code/trunk/src/libraries/core/Identifier.h
   code/trunk/src/libraries/core/Iterator.h
   code/trunk/src/libraries/core/ObjectList.h
   code/trunk/src/libraries/core/XMLPort.h
   code/trunk/src/libraries/core/input/InputDevice.h
   code/trunk/src/modules/objects/triggers/MultiTrigger.h
Log:
There is no such word as "casted".
Also inserted 4 static_casts and replaced dynamic_cast with orxonox_cast in WeakPtr and SmartPtr.
Moreover found some weird code in Iterator.h with casting. Casting a NULL pointer always yields another NULL pointer.

Modified: code/trunk/src/libraries/core/CorePrereqs.h
===================================================================
--- code/trunk/src/libraries/core/CorePrereqs.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/CorePrereqs.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -115,6 +115,9 @@
 {
     typedef std::string LanguageEntryLabel;
 
+    template <class T, class U>
+    T orxonox_cast(U*);
+
     class ArgumentCompleter;
     class ArgumentCompletionListElement;
     class BaseObject;

Modified: code/trunk/src/libraries/core/Event.cc
===================================================================
--- code/trunk/src/libraries/core/Event.cc	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/Event.cc	2010-08-30 18:07:38 UTC (rev 7271)
@@ -102,8 +102,8 @@
                     else
                     {
                         // else cast the pointer to the desired class
-                        void* castedOriginator = event.originator_->getDerivedPointer(this->subclass_->getClassID());
-                        (*this->statefunction_)(event.activate_, castedOriginator);
+                        void* castOriginator = event.originator_->getDerivedPointer(this->subclass_->getClassID());
+                        (*this->statefunction_)(event.activate_, castOriginator);
                     }
                 }
             }

Modified: code/trunk/src/libraries/core/Identifier.h
===================================================================
--- code/trunk/src/libraries/core/Identifier.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/Identifier.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -483,7 +483,7 @@
         Also note that the function is implemented differently for GCC/MSVC.
     */
     template <class T, class U>
-    FORCEINLINE T orxonox_cast(U source)
+    FORCEINLINE T orxonox_cast(U* source)
     {
 #ifdef ORXONOX_COMPILER_MSVC
         typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;

Modified: code/trunk/src/libraries/core/Iterator.h
===================================================================
--- code/trunk/src/libraries/core/Iterator.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/Iterator.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -31,7 +31,7 @@
     @brief Definition and implementation of the Iterator class.
 
     The Iterator of a given class allows to iterate through an ObjectList. Objects in
-    this list are casted to the template argument of the Iterator.
+    this list are cast to the template argument of the Iterator.
 
     Usage:
     for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it)
@@ -94,7 +94,7 @@
             template <class O>
             inline Iterator(ObjectListElement<O>* element)
             {
-                this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
+                this->element_ = element;
                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
                 this->list_->registerIterator(this);
             }
@@ -106,7 +106,7 @@
             template <class O>
             inline Iterator(const ObjectListIterator<O>& other)
             {
-                this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
+                this->element_ = other.element_;
                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
                 this->list_->registerIterator(this);
             }
@@ -161,7 +161,7 @@
                 if (this->list_)
                     this->list_->unregisterIterator(this);
 
-                this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
+                this->element_ = element;
                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
                 this->list_->registerIterator(this);
 
@@ -178,7 +178,7 @@
                 if (this->list_)
                     this->list_->unregisterIterator(this);
 
-                this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
+                this->element_ = other.element_;
                 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
                 this->list_->registerIterator(this);
 

Modified: code/trunk/src/libraries/core/ObjectList.h
===================================================================
--- code/trunk/src/libraries/core/ObjectList.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/ObjectList.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -60,19 +60,31 @@
 
             /** @brief Returns an Iterator to the first element in the list. @return The Iterator */
             inline static ObjectListElement<T>* begin()
-                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->begin().element_); }
+            {
+                ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
+                return static_cast<ObjectListElement<T>*>(list->begin().element_);
+            }
 
             /** @brief Returns an Iterator to the element after the last element in the list. @return The Iterator */
             inline static ObjectListElement<T>* end()
-                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->end().element_); }
+            {
+                ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
+                return static_cast<ObjectListElement<T>*>(list->end().element_);
+            }
 
             /** @brief Returns an Iterator to the last element in the list. @return The Iterator */
             inline static ObjectListElement<T>* rbegin()
-                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->rbegin().element_); }
+            {
+                ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
+                return static_cast<ObjectListElement<T>*>(list->rbegin().element_);
+            }
 
             /** @brief Returns an Iterator to the element before the first element in the list. @return The Iterator */
             inline static ObjectListElement<T>* rend()
-                { return ((ObjectListElement<T>*)ClassIdentifier<T>::getIdentifier()->getObjects()->rend().element_); }
+            {
+                ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects();
+                return static_cast<ObjectListElement<T>*>(list->rend().element_);
+            }
     };
 }
 

Modified: code/trunk/src/libraries/core/XMLPort.h
===================================================================
--- code/trunk/src/libraries/core/XMLPort.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/XMLPort.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -540,12 +540,12 @@
 
             void callLoadExecutor(BaseObject* object, BaseObject* newObject)
             {
-                T* castedObject = orxonox_cast<T*>(object);
-                assert(castedObject);
-                O* castedNewObject = orxonox_cast<O*>(newObject);
-                assert(castedNewObject);
+                T* castObject = orxonox_cast<T*>(object);
+                assert(castObject);
+                O* castNewObject = orxonox_cast<O*>(newObject);
+                assert(castNewObject);
 
-                (*this->loadexecutor_)(castedObject, castedNewObject);
+                (*this->loadexecutor_)(castObject, castNewObject);
             }
 
             virtual XMLPortObjectContainer& description(const std::string& description)

Modified: code/trunk/src/libraries/core/input/InputDevice.h
===================================================================
--- code/trunk/src/libraries/core/input/InputDevice.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/libraries/core/input/InputDevice.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -131,7 +131,7 @@
             , oisInputManager_(oisInputManager)
         {
             oisDevice_ = static_cast<OISDeviceClass*>(oisInputManager_->createInputObject(OISDeviceValue, true));
-            // Note: after the static_cast here, the casted this pointer becomes
+            // Note: after the static_cast here, the cast this pointer becomes
             //       invalid right until the subclass has been constructed!
             oisDevice_->setEventCallback(static_cast<DeviceClass*>(this));
             COUT(4) << "Instantiated a " << this->getClassName() << std::endl;

Modified: code/trunk/src/modules/objects/triggers/MultiTrigger.h
===================================================================
--- code/trunk/src/modules/objects/triggers/MultiTrigger.h	2010-08-30 17:52:33 UTC (rev 7270)
+++ code/trunk/src/modules/objects/triggers/MultiTrigger.h	2010-08-30 18:07:38 UTC (rev 7271)
@@ -81,7 +81,7 @@
             'invert':                   Invert is a bool, if true the trigger is in invert-mode, meaning, that if the triggering condition is fulfilled the MultiTrigger will have the state not triggered and and if the condition is not fulfilled it will have the state triggered. In short it just inverts the behaviour of the MultiTrigger. The default is false.
             'simultaniousTriggerers':   The number of simultanious triggerers limits the number of object that are allowed to trigger the MultiTrigger at the same time. Or a little more precisely, the number of distinct objects the MultiTrigger has 'triggered' states for, at each point in time.
             'mode':                     The mode describes how the MultiTrigger acts in relation to all the MultiTriggers, that are appended to it. There are 3 modes: 'and', meaning that the MultiTrigger can only be triggered if all the appended MultiTriggers are active. 'or', meaning that the MultiTrigger can only triggered if at least one of the appendend MultiTriggers is active. And 'xor', meaning that the MultiTrigger can only be triggered if one and only one appended MultiTrigger is active. Notice, that I wrote 'can only be active', that implies, that there is an addtitional condition to the activity of the MultiTrigger and that is the fulfillment of the triggering condition (the MultiTrigger itself doesn't have one, but all derived classes should). Also bear in mind, that the activity of a MultiTrigger is still coupled to the object that triggered it. The default is 'and'.
-            'broadcast'                 Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaining, that all trigger events that are caused by no originator (originator is NULL) are broadcasted as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger.
+            'broadcast'                 Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaining, that all trigger events that are caused by no originator (originator is NULL) are broadcast as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger.
             'target':                   The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is 'Pawn'.
             Also there is the possibility of appending MultiTriggers to the MultiTrigger just by adding them as subobjects in the XML description of your MultiTrigger.
 




More information about the Orxonox-commit mailing list