iter_test.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  iter_test.cpp -- sc_vector iterator comparisons
23
24  Original Author: Philipp A. Hartmann, OFFIS, 2014-08-21
25
26 *****************************************************************************/
27#include <systemc.h>
28
29SC_MODULE(mod)
30{
31    sc_in<bool> p;
32    SC_CTOR(mod){}
33};
34
35int sc_main(int,char*[])
36{
37    typedef sc_vector<mod> module_vec;
38    typedef sc_vector_assembly<mod,sc_in<bool> > module_port_vec;
39
40    module_vec mv("sigs",5);
41    module_vec::const_iterator citr = mv.begin();
42    module_vec::iterator       itr = mv.begin();
43
44    module_port_vec mpv = sc_assemble_vector(mv, &mod::p);
45    module_port_vec::const_iterator cpitr = mpv.cbegin();
46    module_port_vec::iterator       pitr  = mpv.begin();
47
48    sc_assert(itr == citr);
49    sc_assert(citr == itr);
50    sc_assert(!(itr != citr));
51    sc_assert(!(citr != itr));
52
53    sc_assert(itr == cpitr);
54    sc_assert(citr == pitr);
55    sc_assert(cpitr == itr);
56    sc_assert(pitr == citr);
57    sc_assert(!(itr != cpitr));
58    sc_assert(!(citr != pitr));
59    sc_assert(!(cpitr != pitr));
60    sc_assert(!(pitr != itr));
61
62    sc_assert(itr < mv.end());
63    sc_assert(!(itr > mv.cend()));
64    sc_assert(citr < mv.end());
65    sc_assert(!(citr > mv.cend()));
66
67    ++citr;
68    sc_assert(itr != citr);
69    sc_assert(citr != itr);
70    sc_assert(!(itr == citr));
71    sc_assert(!(citr == itr));
72
73    sc_assert(!(itr < itr));
74    sc_assert(!(itr > itr));
75    sc_assert(itr < citr);
76    sc_assert(citr > itr);
77
78    sc_assert(1 == citr - mv.begin());
79    sc_assert(0 == pitr - mv.cbegin());
80    itr += citr - mpv.begin();
81    sc_assert(1 == itr - mpv.cbegin());
82
83    sc_assert(citr == itr);
84    sc_assert(itr <= citr);
85    sc_assert(citr <= itr);
86    sc_assert(cpitr <= itr);
87    sc_assert(!(itr <= cpitr));
88
89    itr++;
90    cpitr = pitr += itr - mv.begin();
91    sc_assert(itr == pitr);
92    sc_assert(itr >= citr);
93    sc_assert(!(citr >= pitr));
94
95    cout << "\nSuccess" << endl;
96    return 0;
97}
98