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)
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 
24 #include "lib/time/timevalue.hpp"
25 #include "lib/util-foreach.hpp"
26 #include "lib/itertools.hpp"
27 
28 #include <iostream>
29 #include <vector>
30 #include <deque>
31 #include <list>
32 #include <map>
33 #include <set>
34 
35 
36 namespace lib {
37 namespace meta {
38 namespace test {
39 
42  typedef lib::time::TimeVar Time;
43 
44  using std::cout;
45  using std::endl;
46 
47 
48  namespace { // a custom test container....
49 
50 
51  struct TestSource
52  {
53  vector<int> data_;
54 
55  TestSource(uint num);
56 
57  typedef vector<int>::iterator sourceIter;
59 
60  iterator begin() ;
61  iterator end() ;
62  // note: a bare type definition is sufficient here....
63  };
64 
65 
66 
67  }//(End) test containers
68 
69 #define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl;
70 
71 
72 
73  /*******************************************************************************/
82  class IterableClassification_test : public Test
83  {
84 
85  void
86  run (Arg)
87  {
88  // define a bunch of STL containers
89  typedef std::vector<long> LongVector;
90  typedef std::multiset<Time> TimeSet;
91  typedef std::map<int,char> CharMap;
92  typedef std::list<bool> BoolList;
93  typedef std::deque<ushort> ShortDeque;
94  typedef TestSource CustomCont;
95 
96  // some types in compliance to the "Lumiera Forward Iterator" concept
97  typedef TestSource::iterator ForwardRangeIter;
98  typedef TransformIter<ForwardRangeIter, long> TransformedForwardIter;
99  typedef FilterIter<TransformedForwardIter> FilteredForwardIter;
100  typedef ScopeQuery<Effect>::iterator CustomForwardIter;
101 
102 
103  // detect STL iteration
104  SHOW_CHECK( can_STL_ForEach<LongVector> );
105  SHOW_CHECK( can_STL_ForEach<TimeSet> );
106  SHOW_CHECK( can_STL_ForEach<CharMap> );
107  SHOW_CHECK( can_STL_ForEach<BoolList> );
108  SHOW_CHECK( can_STL_ForEach<ShortDeque> );
109  SHOW_CHECK( can_STL_ForEach<CustomCont> );
110 
111  SHOW_CHECK( can_STL_ForEach<ForwardRangeIter> );
115 
116  // detect Lumiera Forward Iterator
117  SHOW_CHECK( can_IterForEach<LongVector> );
118  SHOW_CHECK( can_IterForEach<TimeSet> );
119  SHOW_CHECK( can_IterForEach<CharMap> );
120  SHOW_CHECK( can_IterForEach<BoolList> );
121  SHOW_CHECK( can_IterForEach<ShortDeque> );
122  SHOW_CHECK( can_IterForEach<CustomCont> );
123 
124  SHOW_CHECK( can_IterForEach<ForwardRangeIter> );
128  }
129  };
130 
131 
133  LAUNCHER (IterableClassification_test, "unit common");
134 
135 
136 
137 }}} // namespace lib::meta::test
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
Iterator tool filtering pulled data according to a predicate.
Definition: itertools.hpp:337
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:555
Definition: run.hpp:40
Implementation namespace for support and library code.
Simplistic test class runner.
Trait template to detect a type usable immediately as "Lumiera Forward Iterator" in a specialised for...
Definition: trait.hpp:510
Iterator tool treating pulled data by a custom transformation (function)
Definition: itertools.hpp:754
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.