test04.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  test04.cpp -- Test sc_vector -- build a two dimensional mesh
23
24  Original Author: Philipp A. Hartmann, OFFIS, 2010-03-01
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#include "sysc/utils/sc_vector.h"
40
41
42SC_MODULE( mesh_node )
43{
44  // constructor with additional parameters
45  mesh_node( sc_core::sc_module_name, int x, int y );
46};
47
48typedef sc_vector< mesh_node > row_type;
49typedef sc_vector< row_type  > mesh_type;
50
51SC_MODULE(mesh)
52{
53  mesh_type nodes;
54
55  mesh( sc_module_name, int n, int m );
56
57  struct node_creator
58  {
59    node_creator( int row ) : x(row) {}
60
61    mesh_node* operator()(const char * name, size_t idx )
62    {
63      return new mesh_node( name, x, idx );
64    }
65    int x;
66  };
67
68  struct row_creator
69  {
70    row_creator( int n_cols ) : cols_( n_cols ) {}
71
72    row_type* operator()( const char* name, size_t idx )
73    {
74      return new row_type( name, cols_, node_creator(idx) );
75    }
76    int cols_;
77  };
78
79  const unsigned rows;
80  const unsigned cols;
81
82};
83
84mesh_node::mesh_node( sc_module_name, int x, int y )
85{
86  std::cout << name() << " created @ "
87            << x << "x" << y << std::endl;
88}
89
90mesh::mesh( sc_module_name, int n, int m )
91  : nodes("nodes")
92  , rows( n )
93  , cols( m )
94{
95  nodes.init( n, row_creator(m) );
96}
97
98int sc_main(int argc, char* argv[])
99{
100  mesh dut("dut", 4, 5);
101
102  for (size_t j=0; j<dut.cols; ++j )
103    for (size_t i=0; i<dut.rows; ++i )
104      cout << dut.nodes[i][j].name() << " - "
105           << dut.nodes[i][j].kind()
106           << endl;
107
108  cout << "Program completed" << endl;
109  return 0;
110}
111