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 -- 23 24 Original Author: Ucar Aziz, Synopsys, Inc., 2002-02-15 25 Martin Janssen, Synopsys, Inc., 2002-02-15 26 27 *****************************************************************************/ 28 29/***************************************************************************** 30 31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 32 changes you are making here. 33 34 Name, Affiliation, Date: 35 Description of Modification: 36 37 *****************************************************************************/ 38 39// test of sc_attribute 40 41#include "systemc.h" 42 43int 44sc_main( int, char*[] ) 45{ 46 sc_clock clk; 47 sc_attr_cltn att_cltn; 48 sc_attr_cltn att_cln(att_cltn); 49 sc_attribute<std::string> a1( "a1", "clock" ); 50 sc_attribute<std::string> a2( a1 ); 51 sc_attribute<int> a3( "a3", 24 ); 52 sc_attribute<std::string> a4( "a4", "casio" ); 53 sc_attribute<int> a5("a5"); 54 55 cout << a2.name() << endl; 56 cout << a2.value << endl; 57 58 clk.add_attribute( a2 ); 59 60 sc_attr_base* p = clk.get_attribute("a1"); 61 cout << p->name() << endl; 62 sc_attribute<std::string>* pi = dynamic_cast<sc_attribute<std::string>*>( p ); 63 if( pi != 0 ) { 64 cout << pi->value << endl; 65 } 66 67 cout << endl; 68 cout << "added attributes to the attribute collection class" << endl; 69 70 if(att_cltn.push_back(&a1) == true) { 71 cout << a1.name() << " "; 72 cout << a1.value << endl; 73 } 74 75 if(att_cltn.push_back(&a3) == true) { 76 cout << a3.name() << " "; 77 cout << a3.value << endl; 78 } 79 80 if(att_cltn.push_back(&a4) == true) { 81 cout << a4.name() << " "; 82 cout << a4.value << endl << endl; 83 } 84 85 cout << "size of the class\n"; 86 cout << att_cltn.size()<< endl<< endl; 87 88 cout << "looking whether the name is in collection class\n"; 89 sc_attr_base *pr = att_cltn.operator []("a3"); 90 if(pr != 0) 91 cout << pr->name() << " exists" << endl; 92 else 93 cout << "a3 does not exist\n"; 94 95 sc_attr_base *pm = att_cltn.operator []("a5"); 96 if(pm != 0) 97 cout << pm->name() << " exists" << endl; 98 else 99 cout << "a5 does not exist\n" << endl; 100 101 cout << "removing names \n"; 102 sc_attr_base *pk = att_cltn.remove("a1"); 103 if(pk != 0) 104 cout << "a1 is removed \n"; 105 else 106 cout << "a1 does not exist\n"; 107 sc_attr_base *pn = att_cltn.remove("a5"); 108 if(pn != 0) 109 cout << "a5 is removed \n"; 110 else 111 cout << "a5 does not exist\n"; 112 113 return 0; 114} 115