Skip to content

Commit

Permalink
1. Updating the mapped list with const where required.
Browse files Browse the repository at this point in the history
2. Updating the multi level list with const where required.
3. Depracating deep copy in the multi level list
4. Stricter warnings in the app
  • Loading branch information
samirmenon committed Jul 22, 2013
1 parent d046dca commit f24b71a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
4 changes: 2 additions & 2 deletions applications-linux/sutil_test/CMakeLists.txt
Expand Up @@ -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
Expand Down
57 changes: 49 additions & 8 deletions src/sutil/CMappedList.hpp
Expand Up @@ -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 */
Expand Down Expand Up @@ -638,7 +638,7 @@ namespace sutil
}

template <typename Idx, typename T>
const Idx* CMappedList<Idx,T>::getIndexAt(const std::size_t arg_idx)
const Idx* CMappedList<Idx,T>::getIndexAt(const std::size_t arg_idx) const
{
if(NULL==front_)
{ return NULL; }
Expand Down Expand Up @@ -666,12 +666,53 @@ namespace sutil
}

template <typename Idx, typename T>
const T* CMappedList<Idx,T>::at_const(const std::size_t arg_idx)
{ return (const T*) at(arg_idx); }
const T* CMappedList<Idx,T>::at_const(const std::size_t arg_idx) const
{
if(NULL==front_)
{ return NULL; }
else
{
if(arg_idx > size_)
{ return NULL; }
const SMLNode<Idx,T> * t = front_;

for(std::size_t i=0; i<arg_idx; ++i)
{
#ifdef DEBUG
assert(i<=size_);
#endif

if(NULL==t)
{ return NULL; }
t = t->next_;
}
if(NULL==t)
{ return NULL; }

return (const T*) t->data_;
}
}

template <typename Idx, typename T>
const T* CMappedList<Idx,T>::at_const(const Idx & arg_idx)
{ return (const T*) at(arg_idx); }
const T* CMappedList<Idx,T>::at_const(const Idx & arg_idx) const
{
if(NULL==front_)
{ return NULL; }
else
{
if(map_.find(arg_idx) == map_.end())
{
return NULL;
}

const SMLNode<Idx,T> * t = map_.at(arg_idx);

if(NULL==t)
{ return NULL; }
else
{ return (const T*) t->data_; }
}
}


template <typename Idx, typename T>
Expand Down
35 changes: 29 additions & 6 deletions src/sutil/CMappedMultiLevelList.hpp
Expand Up @@ -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<Idx,T>* arg_br);

/** Assignment operator : Performs a deep-copy (std container requirement).
* Beware; This can be quite slow. */
virtual CMappedMultiLevelList<Idx,T>& operator = (const CMappedMultiLevelList<Idx,T>& arg_rhs)
{
deepCopy(&arg_rhs);
return *this;
}

/** Erases an element from the list.
* Referenced by the element's memory location */
Expand Down Expand Up @@ -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<list>
*
* NOTE TODO : Should not keep this public. Resolve this later.
*/
std::vector<std::vector<T*> > mlvec_;

Expand All @@ -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<Idx,T>::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<Idx,T>* arg_br);

}; //End of template class

/***************************************************************
Expand Down Expand Up @@ -181,7 +204,7 @@ namespace sutil

template <typename Idx, typename T>
bool CMappedMultiLevelList<Idx,T>::
deepCopy(CMappedMultiLevelList<Idx,T>* arg_br)
deepCopy(const CMappedMultiLevelList<Idx,T>* arg_br)
{//Deep copy.
this->~CMappedMultiLevelList(); //Delete everything in the mapped list

Expand Down Expand Up @@ -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<T*,std::size_t>(tmp,pri));

//Now add the entry to the vector
Expand Down

0 comments on commit f24b71a

Please sign in to comment.