-TypeDescription &TypeDescription::CreateOrGet(const std::string &name) {
- for (vector<TypeDescription>::iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) {
- if (i->name == name) {
- return *i;
- }
+TypeDescription &TypeDescription::Create(int id, const std::string &name) {
+ if (typeDescriptions.count(id)) {
+ std::stringstream msg;
+ msg << "duplicate type ID " << id
+ << " (have " << Get(id).TypeName() << ", got " << name << ")";
+ throw std::invalid_argument(msg.str());
+ }
+ if (typeName2ID.count(name)) {
+ std::stringstream msg;
+ msg << "duplicate type name " << name
+ << " (have " << GetTypeId(name) << ", got " << id << ")";
+ throw std::invalid_argument(msg.str());