Lumiera  0.pre.03
»edit your freedom«
iterable-classification-test.cpp
Go to the documentation of this file.
1 /*
2  IterableClassification(Test) - detecting iterability of a generic type
3 
4  Copyright (C) Lumiera.org
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 
33 #include "lib/time/timevalue.hpp"
34 #include "lib/util-foreach.hpp"
35 #include "lib/itertools.hpp"
36 
37 #include <iostream>
38 #include <vector>
39 #include <deque>
40 #include <list>
41 #include <map>
42 #include <set>
43 
44 
45 namespace lib {
46 namespace meta {
47 namespace test {
48 
51  typedef lib::time::TimeVar Time;
52 
53  using std::cout;
54  using std::endl;
55 
56 
57  namespace { // a custom test container....
58 
59 
60  struct TestSource
61  {
62  vector<int> data_;
63 
64  TestSource(uint num);
65 
66  typedef vector<int>::iterator sourceIter;
68 
69  iterator begin() ;
70  iterator end() ;
71  // note: a bare type definition is sufficient here....
72  };
73 
74 
75 
76  }//(End) test containers
77 
78 #define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl;
79 
80 
81 
82  /*******************************************************************************/
91  class IterableClassification_test : public Test
92  {
93 
94  void
95  run (Arg)
96  {
97  // define a bunch of STL containers
98  typedef std::vector<long> LongVector;
99  typedef std::multiset<Time> TimeSet;
100  typedef std::map<int,char> CharMap;
101  typedef std::list<bool> BoolList;
102  typedef std::deque<ushort> ShortDeque;
103  typedef TestSource CustomCont;
104 
105  // some types in compliance to the "Lumiera Forward Iterator" concept
106  typedef TestSource::iterator ForwardRangeIter;
107  typedef TransformIter<ForwardRangeIter, long> TransformedForwardIter;
108  typedef FilterIter<TransformedForwardIter> FilteredForwardIter;
109  typedef ScopeQuery<Effect>::iterator CustomForwardIter;
110 
111 
112  // detect STL iteration
113  SHOW_CHECK( can_STL_ForEach<LongVector> );
114  SHOW_CHECK( can_STL_ForEach<TimeSet> );
115  SHOW_CHECK( can_STL_ForEach<CharMap> );
116  SHOW_CHECK( can_STL_ForEach<BoolList> );
117  SHOW_CHECK( can_STL_ForEach<ShortDeque> );
118  SHOW_CHECK( can_STL_ForEach<CustomCont> );
119 
120  SHOW_CHECK( can_STL_ForEach<ForwardRangeIter> );
124 
125  // detect Lumiera Forward Iterator
126  SHOW_CHECK( can_IterForEach<LongVector> );
127  SHOW_CHECK( can_IterForEach<TimeSet> );
128  SHOW_CHECK( can_IterForEach<CharMap> );
129  SHOW_CHECK( can_IterForEach<BoolList> );
130  SHOW_CHECK( can_IterForEach<ShortDeque> );
131  SHOW_CHECK( can_IterForEach<CustomCont> );
132 
133  SHOW_CHECK( can_IterForEach<ForwardRangeIter> );
137  }
138  };
139 
140 
142  LAUNCHER (IterableClassification_test, "unit common");
143 
144 
145 
146 }}} // namespace lib::meta::test
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
Iterator tool filtering pulled data according to a predicate.
Definition: itertools.hpp:346
Query a scope to discover it&#39;s contents or location.
Trait template to detect a type usable with the STL for-each loop.
Definition: trait.hpp:550
Definition: run.hpp:49
Implementation namespace for support and library code.
Simple test class runner.
Trait template to detect a type usable immediately as "Lumiera Forward Iterator" in a specialised for...
Definition: trait.hpp:505
Iterator tool treating pulled data by a custom transformation (function)
Definition: itertools.hpp:763
Specific queries to explore contents of a scope within the high-level model.
Helpers for working with iterators based on the pipeline model.
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
a family of time value like entities and their relationships.
Perform operations "for each element" of a collection.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...
Metaprogramming helpers to check for specific properties of a type in question.