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  test03.cpp -- Test sc_vector
23
24  Original Author: Philipp A. Hartmann, OFFIS, 2010-03-05
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.h"
39
40using sc_core::sc_vector;
41
42SC_MODULE( sub_module )
43{
44  // constructor with additional parameters
45  sub_module( sc_core::sc_module_name, int param );
46  // ...
47};
48
49SC_MODULE( module )
50{
51  sc_core::sc_vector< sub_module > m_sub_vec;          // vector of sub-modules
52
53  module( sc_core::sc_module_name, unsigned n_sub );   // constructor
54
55  struct mod_creator                                   // Creator struct
56  {
57    mod_creator( int p ) : param(p) {}                 // store parameter to forward
58
59    sub_module* operator()( const char* name, size_t ) // actual creator function
60    {
61      return new sub_module( name, param );            // forward param to sub-module
62    }
63    int param;
64  };
65
66};
67
68sub_module::sub_module( sc_core::sc_module_name, int )
69  { /* empty */ }
70
71module::module( sc_core::sc_module_name, unsigned n_sub )
72  : m_sub_vec( "sub_modules" )                       // set name prefix
73{
74  m_sub_vec.init( n_sub, mod_creator(42) );          // init with custom creator
75  // ...
76}
77
78int sc_main(int , char* [])
79{
80  module dut( "dut", 5 );
81
82  typedef sc_core::sc_vector<sub_module> vec_type;
83  vec_type const & children = dut.m_sub_vec;
84
85  for( vec_type::const_iterator it = children.begin();
86       it != children.end(); ++it )
87  {
88    cout << it->name() << " - "
89         << (*it).kind()
90         << endl;
91  }
92
93  for (size_t i=0; i < children.size(); ++i )
94    cout << children[i].basename() << " - "
95         << children[i].get_parent_object()->name()
96         << endl;
97
98  cout << "Program completed" << endl;
99  return 0;
100}
101