| 125 | } |
| 126 | |
| 127 | void test_creator(void) |
| 128 | { |
| 129 | SpecificFactory<base> fc; |
| 130 | |
| 131 | /* creator test */ |
| 132 | |
| 133 | fc.RegisterCreator("A", std::function<decltype(create_a)>(create_a)); |
| 134 | fc.RegisterCreator("B", std::function<base*()>([]() { return new B(); })); |
| 135 | fc.RegisterCreator("C", create_a); |
| 136 | |
| 137 | base* p = fc.Create("A"); |
| 138 | |
| 139 | p->f(); |
| 140 | |
| 141 | p = fc.Create("B"); |
| 142 | |
| 143 | p->f(); |
| 144 | |
| 145 | p = fc.Create("C"); |
| 146 | |
| 147 | p->f(); |
| 148 | |
| 149 | /* creator with argument */ |
| 150 | |
| 151 | fc.RegisterCreator("D", create_b); |
| 152 | fc.RegisterCreator("E", std::function<base*(const std::string&)>(create_b)); |
| 153 | |
| 154 | const std::string& hello = "hello"; |
| 155 | |
| 156 | p = fc.Create<const std::string&>("D", hello); |
| 157 | p->f(); |
| 158 | |
| 159 | p = fc.Create<const std::string&>("E", "world"); |
| 160 | p->f(); |
| 161 | |
| 162 | fc.RegisterCreator("E", create_b2); |
| 163 | p = fc.Create("E", 1000); |
| 164 | |
| 165 | p->g(); |
| 166 | |
| 167 | std::cout << "retrieval creator type info: \n"; |
| 168 | |
| 169 | std::vector<std::string> info = fc.CreatorInfo("E"); |
| 170 | |
| 171 | for(auto str : info) |
| 172 | { |
| 173 | std::cout << str << std::endl; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | struct G |
| 178 | { |
no test coverage detected