mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Sections use vector instead of a map
Uses brute-force search, but only ever for small vectors
This commit is contained in:
parent
c4ba6757d9
commit
6f2343bf64
@ -51,18 +51,14 @@ namespace Catch {
|
|||||||
typename ContainerT::const_iterator it = container.begin();
|
typename ContainerT::const_iterator it = container.begin();
|
||||||
typename ContainerT::const_iterator itEnd = container.end();
|
typename ContainerT::const_iterator itEnd = container.end();
|
||||||
for(; it != itEnd; ++it )
|
for(; it != itEnd; ++it )
|
||||||
{
|
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
template<typename AssociativeContainerT>
|
template<typename AssociativeContainerT>
|
||||||
inline void deleteAllValues( AssociativeContainerT& container ) {
|
inline void deleteAllValues( AssociativeContainerT& container ) {
|
||||||
typename AssociativeContainerT::const_iterator it = container.begin();
|
typename AssociativeContainerT::const_iterator it = container.begin();
|
||||||
typename AssociativeContainerT::const_iterator itEnd = container.end();
|
typename AssociativeContainerT::const_iterator itEnd = container.end();
|
||||||
for(; it != itEnd; ++it )
|
for(; it != itEnd; ++it )
|
||||||
{
|
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ContainerT, typename Function>
|
template<typename ContainerT, typename Function>
|
||||||
|
@ -24,6 +24,8 @@ namespace Catch {
|
|||||||
|
|
||||||
class SectionInfo : ISectionInfo {
|
class SectionInfo : ISectionInfo {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef std::vector<SectionInfo*> SubSections;
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
Root,
|
Root,
|
||||||
@ -46,7 +48,7 @@ namespace Catch {
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
~SectionInfo() {
|
~SectionInfo() {
|
||||||
deleteAllValues( m_subSections );
|
deleteAll( m_subSections );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string getName() const {
|
virtual std::string getName() const {
|
||||||
@ -68,13 +70,11 @@ namespace Catch {
|
|||||||
bool hasUntestedSections() const {
|
bool hasUntestedSections() const {
|
||||||
if( m_state == Unknown )
|
if( m_state == Unknown )
|
||||||
return true;
|
return true;
|
||||||
|
for( SubSections::const_iterator it = m_subSections.begin();
|
||||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
|
it != m_subSections.end();
|
||||||
std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
|
++it)
|
||||||
for(; it != itEnd; ++it ) {
|
if( (*it)->hasUntestedSections() )
|
||||||
if( it->second->hasUntestedSections() )
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,11 +85,13 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SectionInfo* findOrAddSubSection( const std::string& name, bool& changed ) {
|
SectionInfo* findOrAddSubSection( const std::string& name, bool& changed ) {
|
||||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
|
for( SubSections::const_iterator it = m_subSections.begin();
|
||||||
if( it != m_subSections.end() )
|
it != m_subSections.end();
|
||||||
return it->second;
|
++it)
|
||||||
|
if( (*it)->getName() == name )
|
||||||
|
return *it;
|
||||||
SectionInfo* subSection = new SectionInfo( this, name );
|
SectionInfo* subSection = new SectionInfo( this, name );
|
||||||
m_subSections.insert( std::make_pair( name, subSection ) );
|
m_subSections.push_back( subSection );
|
||||||
m_state = Branch;
|
m_state = Branch;
|
||||||
changed = true;
|
changed = true;
|
||||||
return subSection;
|
return subSection;
|
||||||
@ -112,7 +114,7 @@ namespace Catch {
|
|||||||
State m_state;
|
State m_state;
|
||||||
SectionInfo* m_parent;
|
SectionInfo* m_parent;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
std::map<std::string, SectionInfo*> m_subSections;
|
SubSections m_subSections;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user