int CombineOps(OpRcPtrVec & opVec) { int count = 0; int firstindex = 0; // this must be a signed int OpRcPtrVec tmpops; while(firstindex < static_cast<int>(opVec.size()-1)) { ConstOpRcPtr first = opVec[firstindex]; ConstOpRcPtr second = opVec[firstindex+1]; if(first->canCombineWith(second)) { tmpops.clear(); first->combineWith(tmpops, second); // tmpops may have any number of ops in it. (0, 1, 2, ...) // (size 0 would occur potentially iff the combination // results in a no-op) // // No matter the number, we need to swap them in for the // original ops // Erase the initial two ops we've combined opVec.erase(opVec.begin() + firstindex, opVec.begin() + firstindex + 2); // Insert the new ops (which may be empty) at // this location std::copy(tmpops.begin(), tmpops.end(), std::inserter(opVec, opVec.begin() + firstindex)); // Decrement firstindex by 1, // to backstep and reconsider the A, A' case. // See RemoveInverseOps for the full discussion of // why this is appropriate firstindex = std::max(0, firstindex-1); // We've done something so increment the count! ++count; } else { ++firstindex; } } return count; }
void BuildLookOps(OpRcPtrVec & ops, ConstColorSpaceRcPtr & currentColorSpace, bool skipColorSpaceConversions, const Config& config, const ConstContextRcPtr & context, const LookParseResult & looks) { const LookParseResult::Options & options = looks.getOptions(); if(options.empty()) { // Do nothing } else if(options.size() == 1) { // As an optimization, if we only have a single look option, // just push back onto the final location RunLookTokens(ops, currentColorSpace, skipColorSpaceConversions, config, context, options[0]); } else { // If we have multiple look options, try each one in order, // and if we can create the ops without a missing file exception, // push back it's results and return bool success = false; std::ostringstream os; OpRcPtrVec tmpOps; ConstColorSpaceRcPtr cs; for(unsigned int i=0; i<options.size(); ++i) { cs = currentColorSpace; tmpOps.clear(); try { RunLookTokens(tmpOps, cs, skipColorSpaceConversions, config, context, options[i]); success = true; break; } catch(ExceptionMissingFile & e) { if(i != 0) os << " ... "; os << "("; LookParseResult::serialize(os, options[i]); os << ") " << e.what(); } } if(success) { currentColorSpace = cs; std::copy(tmpOps.begin(), tmpOps.end(), std::back_inserter(ops)); } else { throw ExceptionMissingFile(os.str().c_str()); } } }