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;
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 
gnash::image::begin
pixel_iterator< T > begin(GnashImage &im)
Definition: ImageIterators.h:191
gnash::CreatePointer::operator()
result_type operator()(T &t)
Definition: GnashAlgorithm.h:34
gnash::key::U
@ U
Definition: GnashKey.h:133
gnash::key::T
@ T
Definition: GnashKey.h:132
gnash::arraySize
size_t arraySize(T(&)[N])
Get the size of an array without passing a pointer by mistake.
Definition: GnashAlgorithm.h:58
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
second
std::int32_t second
Definition: Date_as.cpp:93
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::CreatePointer::result_type
T * result_type
Definition: GnashAlgorithm.h:33
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::EraseIf
void EraseIf(Container &c, Predicate p)
Erase elements from an associative container based on a predicate.
Definition: GnashAlgorithm.h:45
gnash::image::end
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::foreachSecond
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
gnash::key::N
@ N
Definition: GnashKey.h:126
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::CreatePointer
Return a pointer to a type.
Definition: GnashAlgorithm.h:32