/*! \file histo.h * \brief count elements of same value (prototypes) * * ---------------------------------------------------------------------------- * * $Id: histo.h,v 1.1 2005-04-28 11:38:05 tforb Exp $ * \author Thomas Forbriger * \date 28/04/2005 * * count elements of same value (prototypes) * * Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach) * * REVISIONS and CHANGES * - 28/04/2005 V1.0 Thomas Forbriger * * ============================================================================ */ // include guard #ifndef AFF_HISTO_H_VERSION #define AFF_HISTO_H_VERSION \ "AFF_HISTO_H V1.0 " #define AFF_HISTO_H_CVSID \ "$Id: histo.h,v 1.1 2005-04-28 11:38:05 tforb Exp $" #include #include namespace aff { namespace func { namespace util { /*! utility class to count elements of the same value * * This class should be used together with the * aff::func::util::collect() function template. * * \param C any container class like aff::Array */ template class Extracthisto { typedef typename C::Tcoc Tcont; typedef typename C::Tvalue Tvalue; public: typedef typename std::map Tmap; typedef Tmap Tretval; //! initialize member data Extracthisto(const Tcont& c) { } //! collect another value void operator() (const Tvalue& v) { ++Mmap[v]; } //! return result of operation Tretval result() const { return(Mmap); } private: Tmap Mmap; }; // class Extracthisto } // namespace util /*----------------------------------------------------------------------*/ /*! Function template to count elements of the same value * * \param C any container class like aff::Array * (this value is deduced by the compiler) * \param c any container of numerical values * \return a map the associates every value with the number of elements * that have this value * * \sa aff::func::util::collect, aff::func::util::Extracthisto */ template typename aff::func::util::Extracthisto::Tmap histo(const C& c) { return(aff::func::util::collect(c)); } // histo() } // namespace func } // namespace aff #endif // AFF_HISTO_H_VERSION (includeguard) /* ----- END OF histo.h ----- */