Commit 8c0fcb4e authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

proceeding

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1686
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 52ac1c7a
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: valmap.h,v 1.1 2005-03-21 09:35:34 tforb Exp $
* $Id: valmap.h,v 1.2 2005-04-28 12:58:31 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -23,11 +23,65 @@
#define AFF_VALMAP_H_VERSION \
"AFF_VALMAP_H V1.0 "
#define AFF_VALMAP_H_CVSID \
"$Id: valmap.h,v 1.1 2005-03-21 09:35:34 tforb Exp $"
"$Id: valmap.h,v 1.2 2005-04-28 12:58:31 tforb Exp $"
namespace tf {
#include<aff/lib/mapper.h>
#include<map>
}
namespace aff {
namespace func {
namespace util {
/*! Utility class to map values using a std::map
*
* This class should be used together with the
* aff::func::util::mapvalues() function template.
*
* \param T1 source value type
* \param T2 target value type
*/
template<class T1, class T2>
class Mapvalmap {
public:
typedef T1 Tinvalue;
typedef T2 Toutvalue;
typedef std::map<Tinvalue,Toutvalue> Tmap;
//! initialize member data
Mapvalmap(const Tmap& m): Mmap(m) { }
//! map another value
Toutvalue operator() (Tinvalue v) { return(Mmap[v]); }
private:
Tmap Mmap;
}; // class Mapvalmap
} // namespace util
/*----------------------------------------------------------------------*/
/*! Function template to map container contents to values of a different
* type
*
* \param C any container class like aff::Array
* \param T1 type of values in source container
* \param T2 type of values in target container
*
* \param c any container of values to be mapped
* \return container of same shape as c but with mapped values
*
* \sa aff::func::util::mapvaues, aff::func::util::Mapvalmap
*/
template<template <class> class C, class T1, class T2>
C<T2> valmap(const C<T1>& c,
const typename util::Mapvalmap<T1,T2>::Tmap& m)
{
return(aff::func::util::mapvalues<C, util::Mapvalmap<T1,T2> >(c,m));
} // rms()
} // namespace func
} // namespace aff
#endif // AFF_VALMAP_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: mapper.h,v 1.2 2005-04-21 07:14:55 tforb Exp $
* $Id: mapper.h,v 1.3 2005-04-28 12:58:31 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -23,11 +23,55 @@
#define AFF_MAPPER_H_VERSION \
"AFF_MAPPER_H V1.0 "
#define AFF_MAPPER_H_CVSID \
"$Id: mapper.h,v 1.2 2005-04-21 07:14:55 tforb Exp $"
"$Id: mapper.h,v 1.3 2005-04-28 12:58:31 tforb Exp $"
namespace tf {
}
namespace aff {
namespace func {
namespace util {
/*! Function template to map values from one container to another
*
* This is a framework to browse through a container and map
* values to values of a different type. This function template is used
* by container functions like aff::func::valmap().
*
* \param C any container class like aff::Array
* \param F any mapper utility class like
* aff::func::util::Mapvalmap
*
* \param c container to read values to be mapped
* \param exfun fully initialized mapper utility
* \return result container of same shape as c but with mapped values
*
* \sa aff::func::valmap()
*/
template<template<class> class C, class F>
C<typename F::Toutvalue>
mapvalues(const typename C<typename F::Tinvalue>::Tcoc& c,
F exfun)
{
typedef typename C<typename F::Tinvalue>::Tcoc Tin;
typedef C<typename F::Toutvalue> Tout;
Tout retval(c.shape());
aff::Browser<Tin> browser(c);
aff::Iterator<Tout> iterator(retval);
while(browser.valid() && iterator.valid())
{
*iterator = exfun(*browser);
++browser;
++iterator;
}
return(retval);
}; // mapvalues
} // namespace util
} // namespace func
} // namespace aff
#endif // AFF_MAPPER_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: functionstest.cc,v 1.5 2005-04-28 11:38:06 tforb Exp $
* $Id: functionstest.cc,v 1.6 2005-04-28 12:58:31 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -19,7 +19,7 @@
#define FUNCTIONSTEST_VERSION \
"FUNCTIONSTEST V1.0 test function templates"
#define FUNCTIONSTEST_CVSID \
"$Id: functionstest.cc,v 1.5 2005-04-28 11:38:06 tforb Exp $"
"$Id: functionstest.cc,v 1.6 2005-04-28 12:58:31 tforb Exp $"
#include <iostream>
#include <aff/dump.h>
......@@ -31,6 +31,7 @@
#include <aff/functions/max.h>
#include <aff/functions/rms.h>
#include <aff/functions/histo.h>
#include <aff/functions/valmap.h>
using namespace aff;
......@@ -38,6 +39,8 @@ using std::cout;
using std::cerr;
using std::endl;
typedef std::map<double, int> Tvalmap;
int main(int iargc, char* argv[])
{
CODE( typedef aff::Array<double> Tarray );
......@@ -56,6 +59,12 @@ int main(int iargc, char* argv[])
CODE( typedef Tmap::const_iterator Tmapit );
CODE( for (Tmapit i=mymap.begin(); i!=mymap.end(); ++i) \
{ cout << i->first << "\t" << i->second << endl; } );
CODE( Tvalmap avalmap );
CODE( avalmap[-4.]=1 );
CODE( avalmap[1.]=2 );
CODE( avalmap[2.]=3 );
CODE( avalmap[5.]=4 );
CODE( dump_array(aff::func::valmap<aff::Array, double, int>(A, avalmap)) );
}
/* ----- END OF functionstest.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment