1 | /*
|
---|
2 | * ActOnAlltest.hpp
|
---|
3 | *
|
---|
4 | * Created on: 04.10.2009
|
---|
5 | * Author: FrederikHeber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef ACTONALLTEST_HPP_
|
---|
9 | #define ACTONALLTEST_HPP_
|
---|
10 |
|
---|
11 | using namespace std;
|
---|
12 |
|
---|
13 | #include <list>
|
---|
14 | #include "../vector.hpp"
|
---|
15 |
|
---|
16 | #define ListOfVectors list<Vector *>
|
---|
17 |
|
---|
18 | class VectorList
|
---|
19 | {
|
---|
20 | public:
|
---|
21 | VectorList();
|
---|
22 | VectorList(VectorList &ref);
|
---|
23 | ~VectorList();
|
---|
24 |
|
---|
25 | void AddVector(Vector *v);
|
---|
26 | void EmptyList();
|
---|
27 |
|
---|
28 | template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T), T t );
|
---|
29 | template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T&), T &t );
|
---|
30 | template <typename klasse, typename res, typename T, typename U> void ActOnAll( res (klasse::*f)(T, U), T t, U u );
|
---|
31 | template <typename klasse, typename res, typename T, typename U, typename V> void ActOnAll( res (klasse::*f)(T, U, V), T t, U u, V v);
|
---|
32 |
|
---|
33 | bool operator == (VectorList &rhs);
|
---|
34 | VectorList& operator = (VectorList &ref);
|
---|
35 |
|
---|
36 | //private:
|
---|
37 | ListOfVectors Vectors;
|
---|
38 | };
|
---|
39 |
|
---|
40 |
|
---|
41 | VectorList::VectorList() { };
|
---|
42 | VectorList::VectorList(VectorList &ref)
|
---|
43 | {
|
---|
44 | ref.EmptyList();
|
---|
45 | for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++) {
|
---|
46 | ref.Vectors.push_back(new Vector (**Runner));
|
---|
47 | }
|
---|
48 | };
|
---|
49 |
|
---|
50 | VectorList & VectorList::operator = (VectorList &ref)
|
---|
51 | {
|
---|
52 | EmptyList();
|
---|
53 | for (ListOfVectors::iterator Runner = ref.Vectors.begin(); Runner != ref.Vectors.end(); Runner++) {
|
---|
54 | Vectors.push_back(new Vector (**Runner));
|
---|
55 | }
|
---|
56 | return *this;
|
---|
57 | };
|
---|
58 |
|
---|
59 | bool VectorList::operator == (VectorList &rhs)
|
---|
60 | {
|
---|
61 | bool status = true;
|
---|
62 | ListOfVectors::iterator lRunner = Vectors.begin();
|
---|
63 | ListOfVectors::iterator rRunner = rhs.Vectors.begin();
|
---|
64 | for (;(lRunner != Vectors.end()) && (rRunner != rhs.Vectors.end()); lRunner++, rRunner++) {
|
---|
65 | //Log() << Verbose(0) << **lRunner << " == " << **rRunner << endl;
|
---|
66 | status = status && (**lRunner == **rRunner);
|
---|
67 | }
|
---|
68 | return status;
|
---|
69 | };
|
---|
70 |
|
---|
71 | VectorList::~VectorList() { };
|
---|
72 |
|
---|
73 | template <typename klasse, typename res, typename T> void VectorList::ActOnAll( res (klasse::*f)(T), T t )
|
---|
74 | {
|
---|
75 | for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++)
|
---|
76 | ((*Runner)->*f)(t);
|
---|
77 | };
|
---|
78 |
|
---|
79 | template <typename klasse, typename res, typename T> void VectorList::ActOnAll( res (klasse::*f)(T&), T &t )
|
---|
80 | {
|
---|
81 | for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++)
|
---|
82 | ((*Runner)->*f)(t);
|
---|
83 | };
|
---|
84 |
|
---|
85 | template <typename klasse, typename res, typename T, typename U> void VectorList::ActOnAll( res (klasse::*f)(T, U), T t, U u )
|
---|
86 | {
|
---|
87 | for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++)
|
---|
88 | ((*Runner)->*f)(t, u);
|
---|
89 | };
|
---|
90 |
|
---|
91 | template <typename klasse, typename res, typename T, typename U, typename V> void VectorList::ActOnAll( res (klasse::*f)(T, U, V), T t, U u, V v)
|
---|
92 | {
|
---|
93 | for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++)
|
---|
94 | ((*Runner)->*f)(t, u, v);
|
---|
95 | };
|
---|
96 |
|
---|
97 | void VectorList::AddVector(Vector *v)
|
---|
98 | {
|
---|
99 | Vectors.push_back(v);
|
---|
100 | };
|
---|
101 |
|
---|
102 | void VectorList::EmptyList()
|
---|
103 | {
|
---|
104 | for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++) {
|
---|
105 | delete(*Runner);
|
---|
106 | }
|
---|
107 | Vectors.clear();
|
---|
108 | }
|
---|
109 |
|
---|
110 | #endif /* ACTONALLTEST_HPP_ */
|
---|