112855Sgabeblack@google.com#include <systemc>
212855Sgabeblack@google.comusing namespace sc_core;
312855Sgabeblack@google.comusing namespace sc_dt;
412855Sgabeblack@google.comusing std::cout;
512855Sgabeblack@google.comusing std::endl;
612855Sgabeblack@google.com
712855Sgabeblack@google.com// 9) sc_object registered and named
812855Sgabeblack@google.com
912855Sgabeblack@google.comstruct i_f: virtual sc_interface
1012855Sgabeblack@google.com{
1112855Sgabeblack@google.com};
1212855Sgabeblack@google.com
1312855Sgabeblack@google.comstruct Chan: i_f, sc_object
1412855Sgabeblack@google.com{
1512855Sgabeblack@google.com  Chan() {}
1612855Sgabeblack@google.com  Chan(const char* _n): sc_object(_n) {}
1712855Sgabeblack@google.com};
1812855Sgabeblack@google.com
1912855Sgabeblack@google.comSC_MODULE(M)
2012855Sgabeblack@google.com{
2112855Sgabeblack@google.com  SC_CTOR(M)
2212855Sgabeblack@google.com  {
2312855Sgabeblack@google.com    SC_THREAD(T);
2412855Sgabeblack@google.com  }
2512855Sgabeblack@google.com  void T()
2612855Sgabeblack@google.com  {
2712855Sgabeblack@google.com  }
2812855Sgabeblack@google.com};
2912855Sgabeblack@google.com
3012855Sgabeblack@google.comstruct Top: sc_module
3112855Sgabeblack@google.com{
3212855Sgabeblack@google.com  M *m;
3312855Sgabeblack@google.com  Top(sc_module_name)
3412855Sgabeblack@google.com  {
3512855Sgabeblack@google.com    m = new M("m");
3612855Sgabeblack@google.com  }
3712855Sgabeblack@google.com};
3812855Sgabeblack@google.com
3912855Sgabeblack@google.comvoid check_form_of_suffix(std::string s)
4012855Sgabeblack@google.com{
4112855Sgabeblack@google.com  std::string charset = "0123456789";
4212855Sgabeblack@google.com  while (!s.empty())
4312855Sgabeblack@google.com  {
4412855Sgabeblack@google.com    sc_assert(s[0] == '_');
4512855Sgabeblack@google.com    s = s.substr(1);
4612855Sgabeblack@google.com    sc_assert(!s.empty());
4712855Sgabeblack@google.com    do
4812855Sgabeblack@google.com    {
4912855Sgabeblack@google.com      sc_assert(charset.find(s[0]) < charset.size());
5012855Sgabeblack@google.com      s = s.substr(1);
5112855Sgabeblack@google.com    } while (!s.empty() && (s[0] != '_'));
5212855Sgabeblack@google.com  }
5312855Sgabeblack@google.com}
5412855Sgabeblack@google.com
5512855Sgabeblack@google.comint sc_main(int argc, char* argv[])
5612855Sgabeblack@google.com{
5712855Sgabeblack@google.com  cout << "Should be silent..." << endl;
5812855Sgabeblack@google.com  sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING);
5912855Sgabeblack@google.com
6012855Sgabeblack@google.com  Chan ch1(""); // object
6112855Sgabeblack@google.com  std::string s1 = std::string(ch1.name());
6212855Sgabeblack@google.com  sc_assert(s1.substr(0,6) == "object");
6312855Sgabeblack@google.com  check_form_of_suffix(s1.substr(6));
6412855Sgabeblack@google.com
6512855Sgabeblack@google.com  Chan ch2;  // object_0
6612855Sgabeblack@google.com  const std::string s2 = std::string(ch2.name());
6712855Sgabeblack@google.com  sc_assert(s2.substr(0,6) == "object");
6812855Sgabeblack@google.com  check_form_of_suffix(s2.substr(6));
6912855Sgabeblack@google.com  sc_assert(s2 != s1);
7012855Sgabeblack@google.com
7112855Sgabeblack@google.com  Chan ch3(s2.c_str()); // object_0_0 or object_1
7212855Sgabeblack@google.com  std::string s3 = std::string(ch3.name());
7312855Sgabeblack@google.com  sc_assert(s3.substr(0,6) == "object");
7412855Sgabeblack@google.com  check_form_of_suffix(s3.substr(6));
7512855Sgabeblack@google.com  sc_assert(s3 != s1);
7612855Sgabeblack@google.com  sc_assert(s3 != s2);
7712855Sgabeblack@google.com
7812855Sgabeblack@google.com  Chan ch4("object_2");
7912855Sgabeblack@google.com  std::string s4 = std::string(ch4.name());
8012855Sgabeblack@google.com  sc_assert(s4.substr(0,6) == "object");
8112855Sgabeblack@google.com  check_form_of_suffix(s4.substr(6));
8212855Sgabeblack@google.com  sc_assert(s4 != s1);
8312855Sgabeblack@google.com  sc_assert(s4 != s2);
8412855Sgabeblack@google.com  sc_assert(s4 != s3);
8512855Sgabeblack@google.com
8612855Sgabeblack@google.com  Chan ch5;
8712855Sgabeblack@google.com  std::string s5 = std::string(ch5.name());
8812855Sgabeblack@google.com  sc_assert(s5.substr(0,6) == "object");
8912855Sgabeblack@google.com  check_form_of_suffix(s5.substr(6));
9012855Sgabeblack@google.com  sc_assert(s5 != s1);
9112855Sgabeblack@google.com  sc_assert(s5 != s2);
9212855Sgabeblack@google.com  sc_assert(s5 != s3);
9312855Sgabeblack@google.com  sc_assert(s5 != s4);
9412855Sgabeblack@google.com
9512855Sgabeblack@google.com  Chan ch6("");
9612855Sgabeblack@google.com  std::string s6 = std::string(ch6.name());
9712855Sgabeblack@google.com  sc_assert(s6.substr(0,6) == "object");
9812855Sgabeblack@google.com  check_form_of_suffix(s6.substr(6));
9912855Sgabeblack@google.com  sc_assert(s6 != s1);
10012855Sgabeblack@google.com  sc_assert(s6 != s2);
10112855Sgabeblack@google.com  sc_assert(s6 != s3);
10212855Sgabeblack@google.com  sc_assert(s6 != s4);
10312855Sgabeblack@google.com  sc_assert(s6 != s5);
10412855Sgabeblack@google.com
10512855Sgabeblack@google.com  sc_signal<int> sig7("signal_0");
10612855Sgabeblack@google.com  std::string s7 = std::string(sig7.name());
10712855Sgabeblack@google.com  sc_assert(s7 == "signal_0");
10812855Sgabeblack@google.com  sc_assert(s7 != s1);
10912855Sgabeblack@google.com  sc_assert(s7 != s2);
11012855Sgabeblack@google.com  sc_assert(s7 != s3);
11112855Sgabeblack@google.com  sc_assert(s7 != s4);
11212855Sgabeblack@google.com  sc_assert(s7 != s5);
11312855Sgabeblack@google.com  sc_assert(s7 != s6);
11412855Sgabeblack@google.com
11512855Sgabeblack@google.com  sc_signal<int> sig8;
11612855Sgabeblack@google.com  std::string s8 = std::string(sig8.name());
11712855Sgabeblack@google.com  sc_assert(s8.substr(0,6) == "signal");
11812855Sgabeblack@google.com  sc_assert(s8.size() > 6);
11912855Sgabeblack@google.com  check_form_of_suffix(s8.substr(6));
12012855Sgabeblack@google.com  sc_assert(s8 != s1);
12112855Sgabeblack@google.com  sc_assert(s8 != s2);
12212855Sgabeblack@google.com  sc_assert(s8 != s3);
12312855Sgabeblack@google.com  sc_assert(s8 != s4);
12412855Sgabeblack@google.com  sc_assert(s8 != s5);
12512855Sgabeblack@google.com  sc_assert(s8 != s6);
12612855Sgabeblack@google.com  sc_assert(s8 != s7);
12712855Sgabeblack@google.com
12812855Sgabeblack@google.com  std::vector<sc_object*> children = sc_get_top_level_objects();
12912855Sgabeblack@google.com  sc_assert (children.size() == 8);
13012855Sgabeblack@google.com
13112855Sgabeblack@google.com  Top top("top");
13212855Sgabeblack@google.com  sc_start();
13312855Sgabeblack@google.com
13412855Sgabeblack@google.com  cout << endl << "Success" << endl;
13512855Sgabeblack@google.com  return 0;
13612855Sgabeblack@google.com}
137