/* * IndexedValue_impl.hpp * * Created on: 29.07.2012 * Author: heber */ #ifndef INDEXEDVALUE_IMPL_HPP_ #define INDEXEDVALUE_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Assert.hpp" #include "IndexedValue.hpp" #include "CodePatterns/Log.hpp" #include #include "Fragmentation/Summation/ZeroInstance.hpp" template const typename IndexedValue::index_t IndexedValue::DropIndex(-1); template IndexedValue::IndexedValue( const IndexedValue::indices_t &_indices, const IndexedValue::values_t &_values) { ASSERT(_indices.size() == _values.size(), "IndexedVectors::IndexedVectors() - vector of indices and values don't match in size."); typename indices_t::const_iterator indexiter = _indices.begin(); typename values_t::const_iterator vectoriter = _values.begin(); for (; vectoriter != _values.end(); ++indexiter, ++vectoriter) { if (*indexiter != DropIndex) { // skip all force values associated to -1 #ifndef NDEBUG std::pair inserter = #endif values.insert( std::make_pair( *indexiter, *vectoriter) ); ASSERT( inserter.second, "IndexedValue<>::IndexedValue() - index " +toString(inserter.first->first)+" already present with vector " +toString(inserter.first->second)+"."); } } } template IndexedValue& IndexedValue::operator=(const IndexedValue &other) { // check for self-assignment if (this != &other) { values.clear(); values = other.values; } return *this; } template void IndexedValue::superposeOtherIndexedVectors(const IndexedValue &other, const double prefactor) { for (typename indexedvalues_t::const_iterator otheriter = other.values.begin(); otheriter != other.values.end(); ++otheriter) { typename indexedvalues_t::iterator iter = values.find(otheriter->first); if (iter == values.end()) { // index does not exist std::pair inserter = values.insert( std::make_pair( otheriter->first, ZeroInstance()) ); ASSERT( inserter.second, "IndexedValue<>::superposeOtherIndexedVectors() - index is present though unfound before?"); iter = inserter.first; } iter->second.superposeOtherIndexedVectors(otheriter->second, prefactor); } } template bool IndexedValue::operator==(const IndexedValue& other) const { bool status = (values == other.values); return status; } template std::ostream & operator<<(std::ostream &ost, const IndexedValue &other) { for (typename IndexedValue::indexedvalues_t::const_iterator iter = other.values.begin(); iter != other.values.end(); ++iter) ost << "(" << iter->first << "," << iter->second << ") "; return ost; } #endif /* INDEXEDVALUE_IMPL_HPP_ */