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  test06.cpp -- Test sc_vector::get_elements
23
24  Original Author: Philipp A. Hartmann, OFFIS, 2010-11-04
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#include "systemc"
39
40using sc_core::sc_object;
41using sc_core::sc_vector;
42using sc_core::sc_mutex;
43using sc_core::sc_in;
44
45void print_vector( const char * header,
46                   const std::vector<sc_object*> & vec )
47{
48  std::cout << "\n-->-- " << header << " -->--\n";
49
50  std::cout << " - size: " << vec.size() << "\n";
51
52  for (size_t i=0; i<vec.size(); ++i )
53    std::cout << " - "
54              << vec[i]->name() << " - "
55              << vec[i]->kind() << "\n";
56
57  std::cout << "--<-- " << header << " --<--"
58            << std::endl;
59}
60
61#define PRINT_VECTOR( Vector ) \
62  print_vector( #Vector, Vector )
63
64SC_MODULE( sub_module )
65{
66  sc_in<bool> in;
67  SC_CTOR(sub_module) {}
68};
69
70
71SC_MODULE( module )
72{
73  // vector of sub-modules
74  sc_vector< sub_module > sub_vec;
75
76  // vector of ports
77  sc_vector< sc_in<bool> > in_vec;
78
79  SC_CTOR(module)
80    : sub_vec( "sub_modules" )
81    , in_vec( "in_vec" )
82  {}
83
84  void init( unsigned n_sub )
85  {
86    sub_vec.init(n_sub);
87    in_vec.init(n_sub);
88    // in_vec.init(n_sub); // second call fails
89
90    // bind ports of sub-modules -- no dereference
91    sc_assemble_vector(  sub_vec, &sub_module::in ).bind( in_vec );
92  }
93
94};
95
96int sc_main(int, char* [])
97{
98  module m("dut");
99  m.init(4); // calls from external context
100
101  PRINT_VECTOR( m.get_child_objects() );
102
103  PRINT_VECTOR( m.sub_vec.get_child_objects() );
104
105  PRINT_VECTOR( m.sub_vec.get_elements() );
106
107  PRINT_VECTOR( sc_assemble_vector( m.sub_vec, &sub_module::in ).get_elements() );
108
109  std::cout << "\nProgram completed" << std::endl;
110  return 0;
111}
112