| 3167 | } |
| 3168 | |
| 3169 | void Config::addNamedTransform(const ConstNamedTransformRcPtr & nt) |
| 3170 | { |
| 3171 | if (!nt) |
| 3172 | { |
| 3173 | throw Exception("Named transform is null."); |
| 3174 | } |
| 3175 | const std::string name(nt->getName()); |
| 3176 | if (name.empty()) |
| 3177 | { |
| 3178 | throw Exception("Named transform must have a non-empty name."); |
| 3179 | } |
| 3180 | if (!nt->getTransform(TRANSFORM_DIR_FORWARD) && |
| 3181 | !nt->getTransform(TRANSFORM_DIR_INVERSE)) |
| 3182 | { |
| 3183 | throw Exception("Named transform must define at least one transform."); |
| 3184 | } |
| 3185 | |
| 3186 | if (hasRole(name.c_str())) |
| 3187 | { |
| 3188 | std::ostringstream os; |
| 3189 | os << "Cannot add '" << name << "' named transform, there is already a role with this " |
| 3190 | "name."; |
| 3191 | throw Exception(os.str().c_str()); |
| 3192 | } |
| 3193 | auto cs = getColorSpace(name.c_str()); |
| 3194 | if (cs) |
| 3195 | { |
| 3196 | std::ostringstream os; |
| 3197 | os << "Cannot add '" << name << "' named transform, there is already a color space using " |
| 3198 | "this name as a name or as an alias: '" << cs->getName() << "'."; |
| 3199 | throw Exception(os.str().c_str()); |
| 3200 | } |
| 3201 | |
| 3202 | if (ContainsContextVariableToken(name)) |
| 3203 | { |
| 3204 | std::ostringstream oss; |
| 3205 | oss << "A named transform name '" << name |
| 3206 | << "' cannot contain a context variable reserved token i.e. % or $."; |
| 3207 | |
| 3208 | throw Exception(oss.str().c_str()); |
| 3209 | } |
| 3210 | |
| 3211 | size_t existing = getImpl()->getNamedTransformIndex(name.c_str()); |
| 3212 | |
| 3213 | size_t replaceIdx = (size_t)-1; |
| 3214 | const auto numNT = getImpl()->m_allNamedTransforms.size(); |
| 3215 | if (existing < numNT) |
| 3216 | { |
| 3217 | const std::string existingName{ getImpl()->m_allNamedTransforms[existing]->getName() }; |
| 3218 | if (!StringUtils::Compare(existingName, name)) |
| 3219 | { |
| 3220 | std::ostringstream os; |
| 3221 | os << "Cannot add '" << name << "' named transform, existing named transform, '"; |
| 3222 | os << existingName << "' is using this name as an alias."; |
| 3223 | throw Exception(os.str().c_str()); |
| 3224 | } |
| 3225 | // There is a named transform with the same name that will be replaced (if new named |
| 3226 | // transform can be used). |