From 5bcd9203c338b5b9e0f3b12487a228a1d4dd504f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 5 Feb 2003 14:55:46 -0500 Subject: [PATCH] ENH: Better error checking for cache iterator. --- Source/cmCacheManager.cxx | 41 +++++++++++++++++++++++++++++++++++++-- Source/cmCacheManager.h | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 8609db30a..92a04cf0c 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -605,7 +605,7 @@ void cmCacheManager::AddCacheEntry(const char* key, bool v, } } -bool cmCacheManager::CacheIterator::IsAtEnd() +bool cmCacheManager::CacheIterator::IsAtEnd() const { return m_Position == m_Container.m_Cache.end(); } @@ -623,17 +623,30 @@ bool cmCacheManager::CacheIterator::Find(const char* key) void cmCacheManager::CacheIterator::Next() { - ++m_Position; + if (!this->IsAtEnd()) + { + ++m_Position; + } } void cmCacheManager::CacheIterator::SetValue(const char* value) { + if (this->IsAtEnd()) + { + return; + } CacheEntry* entry = &this->GetEntry(); entry->m_Value = value; } const char* cmCacheManager::CacheIterator::GetProperty(const char* property) const { + // make sure it is not at the end + if (this->IsAtEnd()) + { + return 0; + } + if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") ) { cmSystemTools::Error("Property \"", property, @@ -652,6 +665,12 @@ const char* cmCacheManager::CacheIterator::GetProperty(const char* property) con void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v) { + // make sure it is not at the end + if (this->IsAtEnd()) + { + return; + } + if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") ) { cmSystemTools::Error("Property \"", p, @@ -664,6 +683,12 @@ void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v) bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* property) const { + // make sure it is not at the end + if (this->IsAtEnd()) + { + return false; + } + if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") ) { cmSystemTools::Error("Property \"", property, @@ -683,6 +708,12 @@ bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* property) cons void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v) { + // make sure it is not at the end + if (this->IsAtEnd()) + { + return; + } + if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") ) { cmSystemTools::Error("Property \"", p, @@ -695,6 +726,12 @@ void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v) bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const { + // make sure it is not at the end + if (this->IsAtEnd()) + { + return false; + } + if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") ) { cmSystemTools::Error("Property \"", property, diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index d79db9999..6ead9227d 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -47,7 +47,7 @@ public: public: void Begin(); bool Find(const char*); - bool IsAtEnd(); + bool IsAtEnd() const; void Next(); const char *GetName() const { return m_Position->first.c_str(); }