| 2575 | } |
| 2576 | |
| 2577 | void Config::addColorSpace(const ConstColorSpaceRcPtr & original) |
| 2578 | { |
| 2579 | const std::string name(original->getName()); |
| 2580 | if (name.empty()) |
| 2581 | { |
| 2582 | throw Exception("Color space must have a non-empty name."); |
| 2583 | } |
| 2584 | |
| 2585 | // Check this is not an existing role or named transform. |
| 2586 | if (hasRole(name.c_str())) |
| 2587 | { |
| 2588 | std::ostringstream os; |
| 2589 | os << "Cannot add '" << name << "' color space, there is already a role with this " |
| 2590 | "name."; |
| 2591 | throw Exception(os.str().c_str()); |
| 2592 | } |
| 2593 | auto nt = getNamedTransform(name.c_str()); |
| 2594 | if (nt) |
| 2595 | { |
| 2596 | std::ostringstream os; |
| 2597 | os << "Cannot add '" << name << "' color space, there is already a named transform using " |
| 2598 | "this name as a name or as an alias: '" << nt->getName() << "'."; |
| 2599 | throw Exception(os.str().c_str()); |
| 2600 | } |
| 2601 | |
| 2602 | if (getMajorVersion() >= 2 && ContainsContextVariableToken(name)) |
| 2603 | { |
| 2604 | std::ostringstream oss; |
| 2605 | oss << "A color space name '" << name |
| 2606 | << "' cannot contain a context variable reserved token i.e. % or $."; |
| 2607 | |
| 2608 | throw Exception(oss.str().c_str()); |
| 2609 | } |
| 2610 | |
| 2611 | const size_t numAliases = original->getNumAliases(); |
| 2612 | for (size_t aidx = 0; aidx < numAliases; ++aidx) |
| 2613 | { |
| 2614 | const char * alias = original->getAlias(aidx); |
| 2615 | |
| 2616 | if (hasRole(alias)) |
| 2617 | { |
| 2618 | std::ostringstream os; |
| 2619 | os << "Cannot add '" << name << "' color space, it has an alias '" << alias |
| 2620 | << "' and there is already a role with this name."; |
| 2621 | throw Exception(os.str().c_str()); |
| 2622 | } |
| 2623 | auto nt = getNamedTransform(alias); |
| 2624 | if (nt) |
| 2625 | { |
| 2626 | std::ostringstream os; |
| 2627 | os << "Cannot add '" << name << "' color space, it has an alias '" << alias |
| 2628 | << "' and there is already a named transform using this name as a name or as " |
| 2629 | "an alias: '" << nt->getName() << "'."; |
| 2630 | throw Exception(os.str().c_str()); |
| 2631 | } |
| 2632 | if (ContainsContextVariableToken(alias)) |
| 2633 | { |
| 2634 | std::ostringstream os; |