BOOL AddMQ2Type(MQ2Type &Type) { if (FindMQ2DataType(Type.GetName())) return false; unsigned long N = MQ2DataTypes.GetUnused(); MQ2DataTypes[N] = &Type; MQ2DataTypeMap[Type.GetName()] = N + 1; return true; }
BOOL RemoveMQ2Type(MQ2Type &Type) { unsigned long N = MQ2DataTypeMap[Type.GetName()]; if (!N) return 0; N--; if (MQ2Type *pType = MQ2DataTypes[N]) { MQ2DataTypes[N] = 0; return false; } MQ2DataTypeMap[Type.GetName()] = 0; return true; }
BOOL MQ2Internal::AddMQ2Type(MQ2Type &Type) { lockit lk(ghVariableLock); // returns pair with iterator pointing to the constructed // element, and a bool indicating if it was actually inserted. // this will not replace existing elements. auto result = MQ2DataTypeMap.emplace(Type.GetName(), &Type); return result.second; }
BOOL MQ2Internal::RemoveMQ2Type(MQ2Type &Type) { lockit lk(ghVariableLock); // use iterator to erase. allows us to check for existence // and erase it without any waste PCHAR thetypename = Type.GetName(); if (!thetypename) return false; auto iter = MQ2DataTypeMap.find(thetypename); if (iter == MQ2DataTypeMap.end()) return false; // The type existed. Erase it. MQ2DataTypeMap.erase(iter); return true; }