Gnash  0.8.11dev
GnashAlgorithm.h
Go to the documentation of this file.
1 // GnashAlgorithm.h: useful templates and functors for generic algorithms
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 
21 #ifndef GNASH_ALGORITHM_H
22 #define GNASH_ALGORITHM_H
23 
24 #include <algorithm>
25 #include <functional>
26 
27 namespace gnash {
28 
30 template<typename T>
32 {
33  typedef T* result_type;
34  result_type operator()(T& t) {
35  return &t;
36  }
37 };
38 
40 //
44 template<typename Container, typename Predicate>
45 void EraseIf(Container& c, Predicate p)
46 {
47  typedef typename Container::iterator iterator;
48 
49  for (iterator i = c.begin(), e = c.end(); i != e; ) {
50  iterator stored = i++;
51  if (p(*stored)) c.erase(stored);
52  }
53 }
54 
56 template<typename T, size_t N>
57 size_t
59 {
60  return N;
61 }
62 
64 //
71 template<typename T, typename U>
72 void
74 {
75  typedef typename std::iterator_traits<T>::value_type value_type;
76 
77  std::for_each(begin, end, std::bind(op,
79 }
80 
81 } // namespace gnash
82 
83 #endif
84 
void EraseIf(Container &c, Predicate p)
Erase elements from an associative container based on a predicate.
Definition: GnashAlgorithm.h:45
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
pixel_iterator< T > begin(GnashImage &im)
Definition: ImageIterators.h:191
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: GnashKey.h:126
Definition: GnashKey.h:149
T * result_type
Definition: GnashAlgorithm.h:33
Definition: GnashKey.h:166
size_t arraySize(T(&)[N])
Get the size of an array without passing a pointer by mistake.
Definition: GnashAlgorithm.h:58
Return a pointer to a type.
Definition: GnashAlgorithm.h:31
Definition: GnashKey.h:133
Definition: GnashKey.h:132
std::int32_t second
Definition: Date_as.cpp:93
Definition: GnashKey.h:162
Definition: GnashKey.h:155
Definition: GnashKey.h:151
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
Definition: GnashKey.h:95
void foreachSecond(T begin, T end, U op)
Call a functor on the second element of each element in a range.
Definition: GnashAlgorithm.h:73
result_type operator()(T &t)
Definition: GnashAlgorithm.h:34