Util--  1.1
cached_fn.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * $Id: cached_fn.hh 957 2005-03-07 16:01:20Z sjoyeux $
3  */
4 #ifndef UTILMM_FUNCTIONAL_CACHED_FN_HEADER
5 # define UTILMM_FUNCTIONAL_CACHED_FN_HEADER
6 
7 #include "utilmm/config/config.h"
9 
10 namespace utilmm {
11 
58  template< typename Arg, typename Ret, class Hash=hash<Arg>,
59  class Equal=std::equal_to<Arg> >
60  class cached_fn
61  :public std::unary_function<Arg, Ret> {
62  private:
64  typedef typename arg_traits<Arg>::type arg_type;
65 
66  cache_type the_cache;
67 
68  protected:
78  virtual Ret call(Arg const &arg) =0;
79 
80  public:
85  cached_fn() {}
87  virtual ~cached_fn() {}
88 
103  Ret const &operator()(arg_type arg);
104 
111  void empty_cache() {
112  the_cache.clear();
113  }
114 
119  size_t cache_size() const {
120  return the_cache.size();
121  }
122  }; // struct utilmm::cached_fn<>
123 
124 } // namespace utilmm
125 
126 # define IN_UTILMM_FUNCTIONAL_CACHED_FN_HEADER
127 #include "utilmm/functional/bits/cached_fn.tcc"
128 # undef IN_UTILMM_FUNCTIONAL_CACHED_FN_HEADER
129 #endif // UTILMM_FUNCTIONAL_CACHED_FN_HEADER
130 
Declaration of utilmm::hash_map.
void clear()
Remove all elements.
Definition: hash_map.hh:197
cached_fn()
Default constructor.
Definition: cached_fn.hh:85
size_t cache_size() const
Cache size.
Definition: cached_fn.hh:119
A functor with cache.
Definition: cached_fn.hh:60
size_t size() const
element count
Definition: hash_map.hh:81
virtual ~cached_fn()
Destructor.
Definition: cached_fn.hh:87
void empty_cache()
clear the cache
Definition: cached_fn.hh:111
Ret const & operator()(arg_type arg)
Call operator.
virtual Ret call(Arg const &arg)=0
the real function.
computed_type type
argument type
Definition: arg_traits.hh:38

Generated on Tue Oct 9 2018 10:12:45 for Util-- by doxygen 1.8.6
SourceForge.net Project Page