diff --git a/applications-linux/sutil_test/CMakeLists.txt b/applications-linux/sutil_test/CMakeLists.txt index 811f488..0a0fb2b 100644 --- a/applications-linux/sutil_test/CMakeLists.txt +++ b/applications-linux/sutil_test/CMakeLists.txt @@ -28,13 +28,13 @@ SET(ALLSRC ${SUTIL_TEST_DIR}/test_main.cpp IF(CMAKE_BUILD_TYPE MATCHES Debug) #Add debug definitions ADD_DEFINITIONS(-DASSERT=assert -DDEBUG=1 -DW_TESTING=1) - SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -ggdb -O0 -pg -std=c++0x -fopenmp") + SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -Woverloaded-virtual -ggdb -O0 -pg -std=c++0x -fopenmp") ENDIF(CMAKE_BUILD_TYPE MATCHES Debug) IF(CMAKE_BUILD_TYPE MATCHES Release) #Add release definitions ADD_DEFINITIONS( -DEIGEN_NO_DEBUG ) - SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -O3 -std=c++0x -fopenmp") + SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -Woverloaded-virtual -O3 -std=c++0x -fopenmp") ENDIF(CMAKE_BUILD_TYPE MATCHES Release) #Make sure the generated makefile is not shortened diff --git a/src/sutil/CMappedList.hpp b/src/sutil/CMappedList.hpp index 504dce6..d0f64c4 100644 --- a/src/sutil/CMappedList.hpp +++ b/src/sutil/CMappedList.hpp @@ -184,19 +184,19 @@ namespace sutil * in the linked list * * NOTE : The index starts at 0 */ - virtual const Idx* getIndexAt(const std::size_t arg_idx); + virtual const Idx* getIndexAt(const std::size_t arg_idx) const; /** Returns the element at the given numerical index * in the linked list (usually useful only for * debugging) * * NOTE : The index starts at 0 */ - virtual const T* at_const(const std::size_t arg_idx); + virtual const T* at_const(const std::size_t arg_idx) const; /** Returns a const pointer to the element referenced by the index * * NOTE : This uses the std::map (and is rather slow) */ - virtual const T* at_const(const Idx & arg_idx); + virtual const T* at_const(const Idx & arg_idx) const; /** Erases an element from the list. * Referenced by the element's memory location */ @@ -638,7 +638,7 @@ namespace sutil } template - const Idx* CMappedList::getIndexAt(const std::size_t arg_idx) + const Idx* CMappedList::getIndexAt(const std::size_t arg_idx) const { if(NULL==front_) { return NULL; } @@ -666,12 +666,53 @@ namespace sutil } template - const T* CMappedList::at_const(const std::size_t arg_idx) - { return (const T*) at(arg_idx); } + const T* CMappedList::at_const(const std::size_t arg_idx) const + { + if(NULL==front_) + { return NULL; } + else + { + if(arg_idx > size_) + { return NULL; } + const SMLNode * t = front_; + + for(std::size_t i=0; inext_; + } + if(NULL==t) + { return NULL; } + + return (const T*) t->data_; + } + } template - const T* CMappedList::at_const(const Idx & arg_idx) - { return (const T*) at(arg_idx); } + const T* CMappedList::at_const(const Idx & arg_idx) const + { + if(NULL==front_) + { return NULL; } + else + { + if(map_.find(arg_idx) == map_.end()) + { + return NULL; + } + + const SMLNode * t = map_.at(arg_idx); + + if(NULL==t) + { return NULL; } + else + { return (const T*) t->data_; } + } + } template diff --git a/src/sutil/CMappedMultiLevelList.hpp b/src/sutil/CMappedMultiLevelList.hpp index 57091ff..9b51610 100644 --- a/src/sutil/CMappedMultiLevelList.hpp +++ b/src/sutil/CMappedMultiLevelList.hpp @@ -64,10 +64,14 @@ namespace sutil * the appropriate slot in the vector-list. Uses the copy-constructor. */ virtual T* create(const Idx& arg_idx, const std::size_t arg_priority); - /** Copy-Constructor : Does a deep copy of the mapped multi level list to - * get a new one. - * NOTE : This uses the passed mapped list's iterator construct. */ - virtual bool deepCopy(CMappedMultiLevelList* arg_br); + + /** Assignment operator : Performs a deep-copy (std container requirement). + * Beware; This can be quite slow. */ + virtual CMappedMultiLevelList& operator = (const CMappedMultiLevelList& arg_rhs) + { + deepCopy(&arg_rhs); + return *this; + } /** Erases an element from the list. * Referenced by the element's memory location */ @@ -100,6 +104,8 @@ namespace sutil /** Create a node on the mapped list and also insert it into the vector * of lists. That way someone can lookup or iterate over the mapped list * and can also exploit the structure of the vec + * + * NOTE TODO : Should not keep this public. Resolve this later. */ std::vector > mlvec_; @@ -112,6 +118,23 @@ namespace sutil /** The priority levels this multi-level map has */ std::size_t pri_levels_; + + protected: + /** These functions exist in the parent class, but are not to be + * called by pointers to this class. The overloaded equivalents + * in this class are the replacements. For more information, read + * the documentation related to -Woverloaded-virtual + * + * NOTE TODO : This needs to be protected here. + * T* CMappedList::create(const Idx & arg_idx, const bool insert_at_start); + */ + + + /** Copy-Constructor : Does a deep copy of the mapped multi level list to + * get a new one. + * NOTE : This uses the passed mapped list's iterator construct. */ + virtual bool deepCopy(const CMappedMultiLevelList* arg_br); + }; //End of template class /*************************************************************** @@ -181,7 +204,7 @@ namespace sutil template bool CMappedMultiLevelList:: - deepCopy(CMappedMultiLevelList* arg_br) + deepCopy(const CMappedMultiLevelList* arg_br) {//Deep copy. this->~CMappedMultiLevelList(); //Delete everything in the mapped list @@ -219,7 +242,7 @@ namespace sutil clear(); return false; } - std::size_t pri = arg_br->map_nodeptr2pri_[tmp]; + std::size_t pri = arg_br->map_nodeptr2pri_.at(tmp); map_nodeptr2pri_.insert(std::pair(tmp,pri)); //Now add the entry to the vector