MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / addNamedTransform

Method addNamedTransform

src/OpenColorIO/Config.cpp:3169–3298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3167}
3168
3169void 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).

Callers 14

_add_itemMethod · 0.80
_remove_itemMethod · 0.80
_new_itemMethod · 0.80
_set_valueMethod · 0.80
loadFunction · 0.80
mergeNamedTransformMethod · 0.80
addNamedTransformsMethod · 0.80
test_named_transformMethod · 0.80
test_canonical_nameMethod · 0.80
OCIO_ADD_TESTFunction · 0.80
OCIO_ADD_TESTFunction · 0.80

Calls 14

CompareFunction · 0.85
resetCacheIDsMethod · 0.80
getImplFunction · 0.50
getNameMethod · 0.45
emptyMethod · 0.45
getTransformMethod · 0.45
sizeMethod · 0.45
getNumAliasesMethod · 0.45
getAliasMethod · 0.45

Tested by 7

test_named_transformMethod · 0.64
test_canonical_nameMethod · 0.64
OCIO_ADD_TESTFunction · 0.64
OCIO_ADD_TESTFunction · 0.64
OCIO_ADD_TESTFunction · 0.64
OCIO_ADD_TESTFunction · 0.64