diff --git a/panda/src/graph/multiTransition.T b/panda/src/graph/multiTransition.T index 1d8d4d4f1b..a572f2dde1 100644 --- a/panda/src/graph/multiTransition.T +++ b/panda/src/graph/multiTransition.T @@ -22,6 +22,20 @@ template TypeHandle MultiTransition::_type_handle; +//////////////////////////////////////////////////////////////////// +// Function: MultiTransition::SortByFirstOfPair function operator +// Access: Public +// Description: Implements the STL function object that sorts +// elements in the vector according to the first +// component of each element. +//////////////////////////////////////////////////////////////////// +template +INLINE_GRAPH bool MultiTransition::SortByFirstOfPair:: +operator ()(const MultiTransition::Element &a, + const MultiTransition::Element &b) const { + return a.first < b.first; +} + //////////////////////////////////////////////////////////////////// // Function: MultiTransition::Constructor // Access: Public @@ -139,7 +153,20 @@ get_default_dir() const { template void MultiTransition:: set_identity(const Property &property) { - _properties[property] = TD_identity; + Properties::iterator pi; + for (pi = _properties.begin(); pi != _properties.end(); ++pi) { + if ((*pi).first == property) { + (*pi).second = TD_identity; + state_changed(); + return; + } + } + + // It wasn't already on the list; append it. + _properties.push_back(Element(property, TD_identity)); + + // And now we need to re-sort the list. + sort(_properties.begin(), _properties.end(), SortByFirstOfPair()); state_changed(); } @@ -153,7 +180,20 @@ set_identity(const Property &property) { template void MultiTransition:: set_on(const Property &property) { - _properties[property] = TD_on; + Properties::iterator pi; + for (pi = _properties.begin(); pi != _properties.end(); ++pi) { + if ((*pi).first == property) { + (*pi).second = TD_on; + state_changed(); + return; + } + } + + // It wasn't already on the list; append it. + _properties.push_back(Element(property, TD_on)); + + // And now we need to re-sort the list. + sort(_properties.begin(), _properties.end(), SortByFirstOfPair()); state_changed(); } @@ -167,7 +207,20 @@ set_on(const Property &property) { template void MultiTransition:: set_off(const Property &property) { - _properties[property] = TD_off; + Properties::iterator pi; + for (pi = _properties.begin(); pi != _properties.end(); ++pi) { + if ((*pi).first == property) { + (*pi).second = TD_off; + state_changed(); + return; + } + } + + // It wasn't already on the list; append it. + _properties.push_back(Element(property, TD_off)); + + // And now we need to re-sort the list. + sort(_properties.begin(), _properties.end(), SortByFirstOfPair()); state_changed(); } @@ -181,9 +234,10 @@ template bool MultiTransition:: is_identity(const Property &property) const { Properties::const_iterator pi; - pi = _properties.find(property); - if (pi != _properties.end()) { - return (*pi).second == TD_identity; + for (pi = _properties.begin(); pi != _properties.end(); ++pi) { + if ((*pi).first == property) { + return (*pi).second == TD_identity; + } } // The property is not mentioned. It's implicitly identity only if @@ -201,13 +255,14 @@ template bool MultiTransition:: is_on(const Property &property) const { Properties::const_iterator pi; - pi = _properties.find(property); - if (pi != _properties.end()) { - return (*pi).second == TD_on; + for (pi = _properties.begin(); pi != _properties.end(); ++pi) { + if ((*pi).first == property) { + return (*pi).second == TD_on; + } } - // The property is not mentioned. It's implicitly 'on' only if the - // default_dir flag is TD_on. + // The property is not mentioned. It's implicitly on only if + // the default_dir flag is on. return (_default_dir == TD_on); } @@ -221,13 +276,14 @@ template bool MultiTransition:: is_off(const Property &property) const { Properties::const_iterator pi; - pi = _properties.find(property); - if (pi != _properties.end()) { - return (*pi).second == TD_off; + for (pi = _properties.begin(); pi != _properties.end(); ++pi) { + if ((*pi).first == property) { + return (*pi).second == TD_off; + } } - // The property is not mentioned. It's implicitly 'off' only if the - // default_dir flag is TD_off. + // The property is not mentioned. It's implicitly off only if + // the default_dir flag is off. return (_default_dir == TD_off); } @@ -291,7 +347,7 @@ compose(const NodeTransition *other) const { dmap_compose(_properties.begin(), _properties.end(), ot->_properties.begin(), ot->_properties.end(), - inserter(result->_properties, result->_properties.begin())); + back_inserter(result->_properties)); return result; } @@ -315,7 +371,8 @@ invert() const { result->_default_dir = TD_identity; dmap_invert(_properties.begin(), _properties.end(), - inserter(result->_properties, result->_properties.begin())); + back_inserter(result->_properties), + (Element *)NULL); return result; } diff --git a/panda/src/graph/multiTransition.h b/panda/src/graph/multiTransition.h index a16eab26d6..83bd178f9e 100644 --- a/panda/src/graph/multiTransition.h +++ b/panda/src/graph/multiTransition.h @@ -19,13 +19,15 @@ #ifndef MULTITRANSITION_H #define MULTITRANSITION_H -#include +#include "pandabase.h" #include "nodeTransition.h" #include "transitionDirection.h" #include "multiTransitionHelpers.h" -#include +#include "indent.h" + +#include //////////////////////////////////////////////////////////////////// // Class : MultiTransition @@ -52,7 +54,18 @@ template class MultiTransition : public NodeTransition { private: - typedef pmap Properties; + typedef pair Element; + + // This has to be a vector and not a map, so we can safely access + // the iterators outside of PANDA.DLL. + typedef pvector Properties; + + // We use this as an STL function object for sorting the vector in + // order by its property. + class SortByFirstOfPair { + public: + INLINE_GRAPH bool operator ()(const Element &a, const Element &b) const; + }; protected: MultiTransition(); @@ -106,8 +119,7 @@ protected: public: // These functions and typedefs allow one to peruse all of the - // Properties in the transition. Beware! It is not safe to use - // this interface outside of PANDA.DLL. + // Properties in the transition. typedef Properties::const_iterator iterator; typedef Properties::const_iterator const_iterator; typedef Properties::value_type value_type; diff --git a/panda/src/graph/multiTransitionHelpers.I b/panda/src/graph/multiTransitionHelpers.I index b6fe15b9fa..f2d032cdd0 100644 --- a/panda/src/graph/multiTransitionHelpers.I +++ b/panda/src/graph/multiTransitionHelpers.I @@ -131,26 +131,24 @@ dmap_invert_compose(InputIterator1 first1, InputIterator1 last1, // input. Guarantees that the new list will have // exactly the same length as the input list. //////////////////////////////////////////////////////////////////// -template +template OutputIterator dmap_invert(InputIterator first, InputIterator last, - OutputIterator result) { - typedef TYPENAME InputIterator::value_type OutputType; - + OutputIterator result, ValueType *) { while (first != last) { switch ((*first).second) { case TD_identity: - (*result) = OutputType((*first).first, TD_identity); + (*result) = ValueType((*first).first, TD_identity); ++result; break; case TD_on: - (*result) = OutputType((*first).first, TD_off); + (*result) = ValueType((*first).first, TD_off); ++result; break; case TD_off: - (*result) = OutputType((*first).first, TD_on); + (*result) = ValueType((*first).first, TD_on); ++result; break; } diff --git a/panda/src/graph/multiTransitionHelpers.h b/panda/src/graph/multiTransitionHelpers.h index 2d85ab405f..9333293ca2 100644 --- a/panda/src/graph/multiTransitionHelpers.h +++ b/panda/src/graph/multiTransitionHelpers.h @@ -56,10 +56,10 @@ dmap_invert_compose(InputIterator1 first1, InputIterator1 last1, // input. Guarantees that the new list will have // exactly the same length as the input list. //////////////////////////////////////////////////////////////////// -template +template OutputIterator dmap_invert(InputIterator first, InputIterator last, - OutputIterator result); + OutputIterator result, ValueType *); //////////////////////////////////////////////////////////////////// diff --git a/panda/src/light/lightTransition.h b/panda/src/light/lightTransition.h index c95777d1a3..e63b7c50c3 100644 --- a/panda/src/light/lightTransition.h +++ b/panda/src/light/lightTransition.h @@ -55,6 +55,15 @@ public: virtual NodeTransition *make_identity() const; virtual NodeTransition *make_initial() const; +#ifdef CPPPARSER + // Interrogate seems to have difficulty figuring out that we do + // implement this pure virtual function properly in MultiTransition. + // For now, we'll pretend for interrogate's sake that it's also + // implemented here, just so interrogate doesn't believe the class + // is abstract. + virtual NodeAttribute *apply(const NodeAttribute *attrib) const; +#endif + virtual void issue(GraphicsStateGuardianBase *gsgbase); protected: