From 4d4ff39ff98442089c6ef0d5dd9a6d9207d8750d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 31 Oct 2001 20:04:32 +0000 Subject: [PATCH] Added a bool paramter to osg::StateSet::compare(const StateSet& rhs,bool compareAttributeContents=false) const; to allow it to use different comparison schemes, now it can use checking for pointer equality (the default) or attribute contexts. This has been added to assist optimization of databases within the flt loader, but also could be useful for other operations too. --- include/osg/StateSet | 2 +- src/osg/StateSet.cpp | 59 +++++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/include/osg/StateSet b/include/osg/StateSet index 3ab52fcd9..33995ffe0 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -35,7 +35,7 @@ class SG_EXPORT StateSet : public Object virtual const char* className() const { return "StateSet"; } /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ - int compare(const StateSet& rhs) const; + int compare(const StateSet& rhs,bool compareAttributeContents=false) const; bool operator < (const StateSet& rhs) const { return compare(rhs)<0; } bool operator == (const StateSet& rhs) const { return compare(rhs)==0; } diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 231f21c2a..08f2303af 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -40,29 +40,54 @@ StateSet::~StateSet() // delete the memory manually. } -int StateSet::compare(const StateSet& rhs) const +int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const { - // now check to see how the attributes compare. - AttributeList::const_iterator lhs_attr_itr = _attributeList.begin(); - AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin(); - while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.end()) + if (compareAttributeContents) { - if (lhs_attr_itr->firstfirst) return -1; - else if (rhs_attr_itr->firstfirst) return 1; - if (lhs_attr_itr->second.firstsecond.first) return -1; - else if (rhs_attr_itr->second.firstsecond.first) return 1; - if (lhs_attr_itr->second.secondsecond.second) return -1; - else if (rhs_attr_itr->second.secondsecond.second) return 1; - ++lhs_attr_itr; - ++rhs_attr_itr; + // now check to see how the attributes compare. + AttributeList::const_iterator lhs_attr_itr = _attributeList.begin(); + AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin(); + while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.end()) + { + if (lhs_attr_itr->firstfirst) return -1; + else if (rhs_attr_itr->firstfirst) return 1; + if (*(lhs_attr_itr->second.first)<*(rhs_attr_itr->second.first)) return -1; + else if (*(rhs_attr_itr->second.first)<*(lhs_attr_itr->second.first)) return 1; + if (lhs_attr_itr->second.secondsecond.second) return -1; + else if (rhs_attr_itr->second.secondsecond.second) return 1; + ++lhs_attr_itr; + ++rhs_attr_itr; + } + if (lhs_attr_itr==_attributeList.end()) + { + if (rhs_attr_itr!=rhs._attributeList.end()) return -1; + } + else if (rhs_attr_itr == rhs._attributeList.end()) return 1; } - if (lhs_attr_itr==_attributeList.end()) + else // just compare pointers. { - if (rhs_attr_itr!=rhs._attributeList.end()) return -1; + // now check to see how the attributes compare. + AttributeList::const_iterator lhs_attr_itr = _attributeList.begin(); + AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin(); + while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.end()) + { + if (lhs_attr_itr->firstfirst) return -1; + else if (rhs_attr_itr->firstfirst) return 1; + if (lhs_attr_itr->second.firstsecond.first) return -1; + else if (rhs_attr_itr->second.firstsecond.first) return 1; + if (lhs_attr_itr->second.secondsecond.second) return -1; + else if (rhs_attr_itr->second.secondsecond.second) return 1; + ++lhs_attr_itr; + ++rhs_attr_itr; + } + if (lhs_attr_itr==_attributeList.end()) + { + if (rhs_attr_itr!=rhs._attributeList.end()) return -1; + } + else if (rhs_attr_itr == rhs._attributeList.end()) return 1; } - else if (rhs_attr_itr == rhs._attributeList.end()) return 1; - + // we've got here so attributes must be equal... // check to see how the modes compare.