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 test02.cpp -- Test sc_vector 23 24 Original Author: Philipp A. Hartmann, OFFIS, 2010-01-10 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//#define USE_BOOST 39 40#ifndef USE_BOOST 41# define SC_INCLUDE_DYNAMIC_PROCESSES 42#endif 43 44#include "systemc.h" 45 46using sc_core::sc_vector; 47 48#ifdef USE_BOOST 49#include <boost/bind.hpp> 50#include <boost/bind/placeholders.hpp> 51#endif 52 53// ---- some classes 54// 55struct base : sc_object 56{ 57 base( const char* n ) : sc_object(n) {} 58}; 59 60struct derived_0 : base 61{ 62 derived_0(const char* name) : base(name) {} 63 const char* kind() const { return "derived_0"; } 64}; 65 66struct derived_1 : public base 67{ 68 derived_1(const char* name) : base(name) {} 69 const char* kind() const { return "derived_1"; } 70}; 71 72// plain function pointer 73base* fill_array( const char* n, size_t i ) 74{ 75 if( i%2 ) return new derived_1( n ); 76 return new derived_0( n ); 77} 78 79SC_MODULE(DUT) 80{ 81 sc_vector< base > arr; 82 sc_vector< sc_in<bool> > inps; 83 sc_vector< sc_signal<bool> > sigs; 84 85 SC_CTOR(DUT); 86 87 // member function as creator (use with sc_bind()) 88 sc_signal<bool>* init_sig_bind( const char* n, unsigned i ) 89 { 90 sc_signal<bool>* sig = new sc_signal<bool>(n); 91 inps[i]( *sig ); 92 return sig; 93 } 94}; 95 96 97DUT::DUT( sc_module_name ) 98 : arr("array") 99 , inps("inps", 5) 100 , sigs("sigs") 101{ 102 arr.init( 3, fill_array ); 103 104 sigs.init( inps.size() 105#if defined( SC_INCLUDE_DYNAMIC_PROCESSES ) 106 , sc_bind( &DUT::init_sig_bind, this, sc_unnamed::_1, sc_unnamed::_2 ) 107#elif defined( USE_BOOST ) 108 , boost::bind( &DUT::init_sig_bind, this, _1, _2 ) 109#endif 110 ); 111} 112 113int sc_main(int , char* []) 114{ 115 DUT dut("dut"); 116 117 std::vector<sc_object*> children = dut.get_child_objects(); 118 119 for (size_t i=0; i<children.size(); ++i ) 120 cout << children[i]->name() << " - " 121 << children[i]->kind() 122 << endl; 123 124 cout << "Program completed" << endl; 125 return 0; 126} 127