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