コード例 #1
0
bool PchTasksMerger::mergePchTasks(PchTask &firstTask, PchTask &secondTask)
{
    if (firstTask.language != secondTask.language || firstTask.isMerged || secondTask.isMerged)
        return false;

    CompilerMacros macros = mergeMacros(firstTask.compilerMacros, secondTask.compilerMacros);

    secondTask.isMerged = !hasDuplicates(macros);


    if (secondTask.isMerged && firstTask.language == secondTask.language) {
        firstTask.projectPartIds = merge(std::move(firstTask.projectPartIds),
                                         std::move(secondTask.projectPartIds));
        firstTask.includes = merge(std::move(firstTask.includes), std::move(secondTask.includes));
        firstTask.allIncludes = merge(std::move(firstTask.allIncludes),
                                      std::move(secondTask.allIncludes));
        firstTask.compilerMacros = std::move(macros);
        firstTask.systemIncludeSearchPaths = mergeIncludeSearchPaths(
            std::move(firstTask.systemIncludeSearchPaths),
            std::move(secondTask.systemIncludeSearchPaths));

        firstTask.languageVersion = std::max(firstTask.languageVersion, secondTask.languageVersion);
        firstTask.languageExtension = firstTask.languageExtension | secondTask.languageExtension;
    }

    return secondTask.isMerged;
}
コード例 #2
0
void RKVarEditModel::checkDuplicatesNow () {
	RK_TRACE (EDITOR);

	duplicate_check_triggered = false;

	QStringList dupes;
	for (int i = var_col_offset; i < objects.size (); ++i) {
		QString name = objects[i]->getShortName ();
		for (int j = i+1; j < objects.size (); ++j) {
			if (objects[j]->getShortName () == name) {
				if (objects[i]->getFullName () == objects[j]->getFullName ()) {
					dupes.append (objects[i]->getFullName ());
					j = objects.size ();		// break
				}
			}
		}
	}

	if (!dupes.isEmpty ()) emit (hasDuplicates (dupes));
}
コード例 #3
0
bool AbcWriteJob::eval(double iFrame)
{
    if (iFrame == mFirstFrame)
    {
        // check if the shortnames of any two nodes are the same
        // if so, exit here
        hasDuplicates(mArgs.dagPaths, mArgs.stripNamespace);

        std::string appWriter = "Maya ";
        appWriter += MGlobal::mayaVersion().asChar();
        appWriter += " AbcExport v";
        appWriter += ABCEXPORT_VERSION;

        std::string userInfo = "Exported from: ";
        userInfo += MFileIO::currentFile().asChar();

        // these symbols can't be in the meta data
        if (userInfo.find('=') != std::string::npos ||
            userInfo.find(';') != std::string::npos)
        {
            userInfo = "";
        }

#ifdef ALEMBIC_WITH_HDF5
        if (mAsOgawa)
        {
            mRoot = CreateArchiveWithInfo(Alembic::AbcCoreOgawa::WriteArchive(),
                mFileName, appWriter, userInfo,
                Alembic::Abc::ErrorHandler::kThrowPolicy);
        }
        else
        {
            mRoot = CreateArchiveWithInfo(Alembic::AbcCoreHDF5::WriteArchive(),
                mFileName, appWriter, userInfo,
                Alembic::Abc::ErrorHandler::kThrowPolicy);
        }
#else
        // just write it out as Ogawa
        mRoot = CreateArchiveWithInfo(Alembic::AbcCoreOgawa::WriteArchive(),
            mFileName, appWriter, userInfo,
            Alembic::Abc::ErrorHandler::kThrowPolicy);
#endif

        mShapeTimeIndex = mRoot.addTimeSampling(*mShapeTime);
        mTransTimeIndex = mRoot.addTimeSampling(*mTransTime);

        mBoxProp =  Alembic::AbcGeom::CreateOArchiveBounds(mRoot,
            mTransTimeIndex);

        if (!mRoot.valid())
        {
            std::string theError = "Unable to create abc file";
            throw std::runtime_error(theError);
        }

        mArgs.setFirstAnimShape = (iFrame == *mShapeFrames.begin());

        util::ShapeSet::const_iterator end = mArgs.dagPaths.end();
        GetMembersMap gmMap;
        for (util::ShapeSet::const_iterator it = mArgs.dagPaths.begin();
            it != end; ++it)
        {
            mCurDag = *it;
            setup(iFrame * util::spf(), MayaTransformWriterPtr(), gmMap);
        }
        perFrameCallback(iFrame);
    }
    else
    {
        std::set<double>::iterator checkFrame = mShapeFrames.find(iFrame);
        bool foundShapeFrame = false;
        if (checkFrame != mShapeFrames.end())
        {
            assert(mRoot != NULL);
            foundShapeFrame = true;
            mShapeSamples ++;
            double curTime = iFrame * util::spf();

            std::vector< MayaCameraWriterPtr >::iterator camIt, camEnd;
            camEnd = mCameraList.end();
            for (camIt = mCameraList.begin(); camIt != camEnd; camIt++)
            {
                (*camIt)->write();
            }

            std::vector< MayaMeshWriterPtr >::iterator meshIt, meshEnd;
            meshEnd = mMeshList.end();
            for (meshIt = mMeshList.begin(); meshIt != meshEnd; meshIt++)
            {
                (*meshIt)->write();
                if ((*meshIt)->isSubD())
                {
                    mStats.mSubDAnimCVs += (*meshIt)->getNumCVs();
                }
                else
                {
                    mStats.mPolyAnimCVs += (*meshIt)->getNumCVs();
                }
            }

            std::vector< MayaNurbsCurveWriterPtr >::iterator curveIt, curveEnd;
            curveEnd = mCurveList.end();
            for (curveIt = mCurveList.begin(); curveIt != curveEnd; curveIt++)
            {
                (*curveIt)->write();
                mStats.mCurveAnimCVs += (*curveIt)->getNumCVs();
            }

            std::vector< MayaNurbsSurfaceWriterPtr >::iterator nurbsIt,nurbsEnd;
            nurbsEnd = mNurbsList.end();
            for (nurbsIt = mNurbsList.begin(); nurbsIt != nurbsEnd; nurbsIt++)
            {
                (*nurbsIt)->write();
                mStats.mNurbsAnimCVs += (*nurbsIt)->getNumCVs();
            }

            std::vector< MayaLocatorWriterPtr >::iterator locIt, locEnd;
            locEnd = mLocatorList.end();
            for (locIt = mLocatorList.begin(); locIt != locEnd; locIt++)
            {
                (*locIt)->write();
            }

            std::vector< MayaPointPrimitiveWriterPtr >::iterator ptIt, ptEnd;
            ptEnd = mPointList.end();
            for (ptIt = mPointList.begin(); ptIt != ptEnd; ptIt++)
            {
                (*ptIt)->write(curTime);
                mStats.mPointAnimCVs += (*ptIt)->getNumCVs();
            }

            std::vector< AttributesWriterPtr >::iterator sattrCur =
                mShapeAttrList.begin();

            std::vector< AttributesWriterPtr >::iterator sattrEnd =
                mShapeAttrList.end();

            for(; sattrCur != sattrEnd; sattrCur++)
            {
                (*sattrCur)->write();
            }
        }

        checkFrame = mTransFrames.find(iFrame);
        bool foundTransFrame = false;
        if (checkFrame != mTransFrames.end())
        {
            assert(mRoot.valid());
            foundTransFrame = true;
            mTransSamples ++;
            std::vector< MayaTransformWriterPtr >::iterator tcur =
                mTransList.begin();

            std::vector< MayaTransformWriterPtr >::iterator tend =
                mTransList.end();

            for (; tcur != tend; tcur++)
            {
                (*tcur)->write();
            }

            std::vector< AttributesWriterPtr >::iterator tattrCur =
                mTransAttrList.begin();

            std::vector< AttributesWriterPtr >::iterator tattrEnd =
                mTransAttrList.end();

            for(; tattrCur != tattrEnd; tattrCur++)
            {
                (*tattrCur)->write();
            }
        }

        if (foundTransFrame || foundShapeFrame)
            perFrameCallback(iFrame);
    }

    if (iFrame == mLastFrame)
    {
        postCallback(iFrame);
        return true;
    }

    return false;
}
コード例 #4
0
int MacroExtender::macroExtend() {
	bool canWrite = false;
	int numLine;
	int macroBound = 0;
	int macroLastStart = 0,macroLastEnd = 0;
	bool textSegment = false;
	bool dataSegment = false;
	bool isMacroBody = false;
	smatch auxMatch;
	string curLine;
	vector<string> currentCode;
	vector<string> macroParams;
	vector<string> macroLines;
	fileIn.append(".pre");
	fileOut.append(".mcr");
	ifstream inputFile(fileIn,ios::in);
		
	if (!inputFile) {
		cerr	<< "Fatal Error: Could not open file " << fileIn << endl; 
		return -1;
	}
	cout << "Opened " << fileIn << " for macro-extending..." << endl;
	ofstream outputFile(fileOut,ios::out);
	if (!outputFile) {
		cerr	<< "Fatal Error: Could not create file " << fileOut << endl; 
		return -1;
	}

	while (getline(inputFile,curLine)) {
		// prepareLine(curLine);
		if (curLine.find("SECTION ")!=string::npos && regex_search(curLine,auxMatch,regex("\\bSECTION "))) {
			if (regex_search(curLine,auxMatch,regex("\\bTEXT$"))) {
				textSegment = true;
			}
			else {
				textSegment = false;
			}
			if (regex_search(curLine,auxMatch,regex("\\bDATA$"))) {
				dataSegment = true;
			}
			else {
				dataSegment = false;
			}
		}
		else if (curLine.find(" MACRO ")!=string::npos || regex_search(curLine,auxMatch,regex(" MACRO$")) || regex_search(curLine,auxMatch,regex("\\bMACRO "))) {
			macroBound++;
			macroLastStart = numLine;
			if (textSegment || dataSegment) {
				addError(numLine,string("Semantical Error: MACRO definitions must go before all"));
			}
		}
		else if (regex_search(curLine,auxMatch,regex("\\bMACRO "))) {
			macroBound++;
			macroLastStart = numLine;
			if (textSegment || dataSegment) {
				addError(numLine,string("Semantical Error: MACRO definitions must go before all"));
			}
		}
		else if (regex_search(curLine,auxMatch,regex("\\bENDMACRO$"))) {
			macroBound--;
			macroLastEnd = numLine;
			if (textSegment || dataSegment) {
				addError(numLine,string("Semantical Error: ENDMACRO must go before all"));
			}
		}
		currentCode.push_back(curLine);
		currentCode.shrink_to_fit();
		numLine++;
	}
	//cout << "Macro Bound: " << macroBound << endl;
	if (macroBound>0) {
		addError(macroLastStart,string("Semantical Error: Caught at least one MACRO without a corresponding ENDMACRO"));
	}
	else if (macroBound<0) {
		addError(macroLastEnd,string("Semantical Error: Caught at least one ENDMACRO without a corresponding MACRO"));
	}

	vector<string>::iterator codeIterator;
	for (numLine=1,codeIterator=currentCode.begin();codeIterator!=currentCode.end();codeIterator++,numLine++) {
		curLine = *codeIterator;
		canWrite = true;
		//cout << "@" << hasMacro(curLine) << endl; 
		if (curLine.find("SECTION ")!=string::npos && regex_search(curLine,auxMatch,regex("\\bSECTION "))) {
			if (regex_search(curLine,auxMatch,regex("\\bTEXT$"))) {
				textSegment = true;
			}
			else {
				textSegment = false;
			}
			outputFile << curLine << "\n";
		}
		else if (curLine.find(" MACRO ")!=string::npos || regex_search(curLine,auxMatch,regex(" MACRO$")) || regex_search(curLine,auxMatch,regex("\\bMACRO "))) {
			macroParams.clear();
			macroLines.clear();
			if (regex_search(curLine,auxMatch,regex("\\bMACRO ")) && curLine.find("MACRO ")==0) {
				addError(numLine,string("Syntactical Error: MACRO must have a definition label"));
			}
			else if (!regex_search(curLine,auxMatch,regex(labelReg))) {
				addError(numLine,string("Syntactical Error: MACRO must have a definition label"));
			}
			else if (macroBound<=0 || (macroBound>0 && numLine!=macroLastStart)) {
				int macroDefLine = numLine;
				int numParameters; 
				string macroLabel = curLine.substr(0,curLine.find_last_of(':'));
				if (directiveTable.isDirective(macroLabel) || opcodeTable.isInstruction(macroLabel)) {
					addError(numLine,string("Semantical Error: Invalid use of keyword"));
				}
				if (macroLabel.find(':')!=string::npos) {
					addError(numLine,string("Syntactical Error: Too many definitions for MACRO constructor"));
				}
				if (curLine.find(" MACRO ") == string::npos) {
					numParameters = 0;
				}
				else {
					string auxParameters = curLine.substr(curLine.find(" MACRO ")+7);
					splitTokenize(auxParameters,macroParams,",");
					if (hasDuplicates(macroParams)) {
						addError(numLine,"Semantical Errors: Duplicate parameter detected");
					}
					for (const string &macroRef : macroParams) {
						if (!regex_match(macroRef,regex("\\&[\\w]"))) {
							addError(numLine,"Syntactical Error: Invalid parameter(s) for MACRO statement");
							break;
						}
					}
					numParameters = macroParams.size();
					if (numParameters > MACRO_MAX_PARAMS) {
						string pError = "Semantical Error: Too many parameters for MACRO definition (max at ";
						pError.append(to_string(MACRO_MAX_PARAMS));
						pError.append(" )");
						pError.shrink_to_fit();
						addError(numLine,pError);
					}
					//cout << macroParams << endl;
				}
				if (MNT.find(macroLabel) != MNT.end()) {
					addError(numLine,"Semantical Error: Macro redefinition detected");
				}
				MNT.emplace(macroLabel,make_pair(macroDefLine,numParameters));
				isMacroBody = true;
				codeIterator++;
				while (isMacroBody && codeIterator != currentCode.end()) {
					curLine = *codeIterator;
					if (curLine.find(" EXTERN") != string::npos && regex_search(curLine,auxMatch,regex(" EXTERN$"))) {
						addError(numLine,"Semantical Error: EXTERN directive inside a macro body is forbidden");
					}
					if (curLine.find(" BEGIN") != string::npos && regex_search(curLine,auxMatch,regex(" BEGIN$"))) {
						addError(numLine,"Semantical Error: BEGIN directive inside a macro body is forbidden");
					}
					if (regex_search(curLine,auxMatch,regex("^\\bEND[\\b]?$"))) {
						addError(numLine,"Semantical Error: END directive inside a macro body is forbidden");
					}
					if (curLine.find("PUBLIC ") != string::npos && regex_search(curLine,auxMatch,regex("^PUBLIC "))) {
						addError(numLine,"Semantical Error: PUBLIC directive inside a macro body is forbidden");
					}
					if (curLine.find(':') != string::npos) {
						addError(numLine,"Semantical Error: MACRO does not support labels inside");
						continue;
					}
					if (regex_search(curLine,auxMatch,regex("\\bENDMACRO$"))) {
						isMacroBody = false;
						break;
					}
					if (curLine.find("SECTION ")!=string::npos && regex_search(curLine,auxMatch,regex("^SECTION "))) {
						addError(numLine,"Semantical Error: SECTION directive inside a macro body is forbidden");
					}
					else {
						for (unsigned i=0;i<macroParams.size();i++) {
							string paramRegex = macroParams[i];
							string paramSub = string("#") + to_string(i+1);
							curLine = regex_replace(curLine,regex(paramRegex),paramSub);
						}
						if(regex_search(curLine,auxMatch,regex("\\&[\\w]"))) {
							addError(numLine,"Semantical Error: MACRO has less parameters than it uses");
						}
						macroLines.push_back(curLine);
					}
					codeIterator++;
					numLine++;
				}
				numLine++;
				MDT.emplace(macroLabel,macroLines);
			}
		}
		//else if (regex_search(curLine,auxMatch,regex("\\bENDMACRO\\b"))) {
		//	canWrite = false;
		//}
		else if (hasMacro(curLine)!=";") {
			string macroFound = hasMacro(curLine);
			//cout << "Found Macro \"" << macroFound << "\"at line " << numLine << endl;
			map<string,std::pair<int,int> >::iterator MNTCell = MNT.find(macroFound);
			map<string,vector<string> >::iterator MDTCell = MDT.find(macroFound);
			std::pair<int,int> MNTDefs = MNTCell->second;
			vector<string> auxiliarLines = MDTCell->second;
			vector<string> paramsToSub;
			try	{
				string finalLine = curLine.substr(curLine.find(macroFound)+macroFound.length()+1);
				if (curLine.find(':') != string::npos) {
					string curLabel = curLine.substr(0,curLine.find(':')+1);
					outputFile << curLabel << " ";
				}
				splitTokenize(finalLine,paramsToSub,",");
				if (paramsToSub.size() != static_cast<unsigned>(MNTDefs.second)) {
					addError(numLine,"Syntactical Error: Wrong number of parameters for current MACRO");
				}
				else {
					for (const string &subLines : auxiliarLines) {
						string auxSubLine = subLines;
						for (int j=0;j<MNTDefs.second;j++) {
							string MDTParamRegex = string("#") + to_string(j+1);
							auxSubLine = regex_replace(auxSubLine,regex(MDTParamRegex),paramsToSub[j]);
						}
						outputFile << auxSubLine << "\n";	
					}
				}
			}
			catch (std::out_of_range &e) {
				//cout << "Macro without params: " << e.what() << endl;
				if (curLine.find(':') != string::npos) {
					string curLabel = curLine.substr(0,curLine.find(':')+1);
					outputFile << curLabel << " ";
				}
				for (const string &subLines : auxiliarLines) {
					outputFile << subLines << "\n";	
				}
			}
		}
		else {
			if (!canWrite) {
				canWrite = true;
			}
			else {
				if (curLine.size()) {
					outputFile << curLine << "\n";
				}
			}
		}
	}
	//cout << "MNT: " << endl;
	//cout << MNT << endl;
	//cout << "MDT: " << endl;
	//cout << MDT << endl;
	if (this->errorList.size()) {
		printErrors();
		outputFile.close();
		remove(fileOut.c_str());
	}
	return this->errorList.size();
}
コード例 #5
0
ファイル: SortedArray.c プロジェクト: jammy83/ds
int main()
{
    printf("Working on testcase 1: Validating isSorted() function\n");
    //Testcase 1: test isSorted() function
    int arr[] = {0, 2, 4, 6, 8, 10};
    assert(isSorted(arr, sizeof(arr)/sizeof(arr[0]), 1));
    int arr_1[] = {0, 2, 4, 6, 7, 8, 7, 10};
    assert(isSorted(arr_1, sizeof(arr_1)/sizeof(arr_1[0]), 1) == 0);
    printf("Working on testcase 1: Validating isSorted() function: Completed successfully\n");
    
    //Testcase 2: test hasDuplicates() function
    printf("Working on testcase 2: Validating hasDuplicates() function\n");
    int arr_2[] = {2, 5, 11, 14, 15, 18, 19, 20};
    assert(hasDuplicates(arr_2, sizeof(arr_2)/sizeof(arr_2[0]), 1) == 0);
    assert(hasDuplicates(arr_1, sizeof(arr_1)/sizeof(arr_1[0]), 1) == -1);
    int arr_3[] = {21, 17, 13, 10, 9, 8 , 5, 5, 4, 3, 2, 0};
    assert(hasDuplicates(arr_3, sizeof(arr_3)/sizeof(arr_3[0]), 0) == 1);
    printf("Working on testcase 2: Validating hasDuplicates() function: Completed successfully\n");
    
    //Testcase 3: test isValid() function
    printf("Working on testcase 3: Validating isValid() function\n");
    assert(isValid(5, 6));
    assert(isValid(-1, 6) == 0);
    assert(isValid(0, 4));
    assert(isValid(10, 6) == 0);
    printf("Working on testcase 3: Validating isValid() function: Completed successfully\n");
    
    //Testcase 4: test Search() function with all different searchType and searchResult combinations
    printf("Working on testcase 4: Validating Search() function\n");
    int arr_a[] = {2, 5, 11, 14, 15, 18, 19, 20, 22, 25, 27, 28, 100};
    
    int keys_a[NumSearchTypeEntries][NumSearchResultEntries];
    int indices_a[NumSearchTypeEntries][NumSearchResultEntries];
    keys_a[LessThan][FoundLess] = 101;
    indices_a[LessThan][FoundLess] = 12;
    keys_a[LessThan][NotFound] = -1;
    indices_a[LessThan][NotFound] = -1;
    
    keys_a[LessThanEquals][FoundLess] = 99;
    indices_a[LessThanEquals][FoundLess] = 11;
    keys_a[LessThanEquals][FoundExact] = 100;
    indices_a[LessThanEquals][FoundExact] = 12;
    keys_a[LessThanEquals][NotFound] = 1;
    indices_a[LessThanEquals][NotFound] = -1;
    
    keys_a[Equals][FoundExact] = 25;
    indices_a[Equals][FoundExact] = 9;
    keys_a[Equals][NotFound] = 0;
    indices_a[Equals][NotFound] = -1;
    
    keys_a[GreaterThan][FoundGreater] = 19;
    indices_a[GreaterThan][FoundGreater] = 7;
    keys_a[GreaterThan][NotFound] = 100;
    indices_a[GreaterThan][NotFound] = -1;
    
    keys_a[GreaterThanEquals][FoundGreater] = 23;
    indices_a[GreaterThanEquals][FoundGreater] = 9;
    keys_a[GreaterThanEquals][FoundExact] = 100;
    indices_a[GreaterThanEquals][FoundExact] = 12;
    keys_a[GreaterThanEquals][NotFound] = 101;
    indices_a[GreaterThanEquals][NotFound] = -1;
    
    testSearch(arr_a, sizeof(arr_a)/sizeof(arr_a[0]), 1 /*ascending*/, keys_a, indices_a);
    printf("Working on testcase 4: Validating Search() function: Completed successfully\n");
    
    printf("Working on testcase 5: Validating Search() function\n");
    int arr_d[] = {33, 29, 28, 26, 21, 17, 13, 10, 9, 8 , 5, 4, 3, 2, 0};
    
    int keys_d[NumSearchTypeEntries][NumSearchResultEntries];
    int indices_d[NumSearchTypeEntries][NumSearchResultEntries];
    keys_d[LessThan][FoundLess] = 34;
    indices_d[LessThan][FoundLess] = 0;
    keys_d[LessThan][NotFound] = -2;
    indices_d[LessThan][NotFound] = -1;
    
    keys_d[LessThanEquals][FoundLess] = 30;
    indices_d[LessThanEquals][FoundLess] = 1;
    keys_d[LessThanEquals][FoundExact] = 21;
    indices_d[LessThanEquals][FoundExact] = 4;
    keys_d[LessThanEquals][NotFound] = -3;
    indices_d[LessThanEquals][NotFound] = -1;
    
    keys_d[Equals][FoundExact] = 10;
    indices_d[Equals][FoundExact] = 7;
    keys_d[Equals][NotFound] = 1;
    indices_d[Equals][NotFound] = -1;
    
    keys_d[GreaterThan][FoundGreater] = 19;
    indices_d[GreaterThan][FoundGreater] = 4;
    keys_d[GreaterThan][NotFound] = 50;
    indices_d[GreaterThan][NotFound] = -1;
    
    keys_d[GreaterThanEquals][FoundGreater] = 23;
    indices_d[GreaterThanEquals][FoundGreater] = 3;
    keys_d[GreaterThanEquals][FoundExact] = 13;
    indices_d[GreaterThanEquals][FoundExact] = 6;
    keys_d[GreaterThanEquals][NotFound] = 34;
    indices_d[GreaterThanEquals][NotFound] = -1;
    
    testSearch(arr_d, sizeof(arr_d)/sizeof(arr_d[0]), 0 /*descending*/, keys_d, indices_d);
    
    printf("Working on testcase 5: Validating Search() function: Completed successfully\n");
    
    return 0;
}
コード例 #6
0
ファイル: SortedArray.c プロジェクト: jammy83/ds
/* @brief This function performs a simple linear search on the given sorted array
 * based on the key and SearchType provided and returns the SearchResult
 * along with the index
 * @param items[in]      - Pointer to a sorted array
 * @param n_items[in]    - Size of the array
 * @param ascending[in]  - if the elements of the array are sorted in ascending order or not
 * @param key[in]        - the value to be searched for in the array
 * @param type[in]       - search type
 * @param index[out]     - index of the result once a match is found
 *                         returns -1 if no match is found, i.e @return == NotFound
 * @return SearchResult  - the value of the SearchResult based on the search
 */
SearchResult
Search(const int* const items,
       const int n_items,
       const int ascending,
       const int key,
       const SearchType type,
       int* const index)
{
    assert(items != NULL);
    assert(n_items > 0);
    assert(isSorted(items, n_items, ascending));
    assert(hasDuplicates(items, n_items, ascending) == 0);
    
    //find the bounds of the array
    const int low = (ascending) ? 0 : n_items - 1;
    const int high = (ascending) ? n_items - 1 : 0;
    
    //Check if the result is likely to be in the array based on
    //the key and the type
    int inRange = 1;
    (*index) = -1; //clear the index
    
    switch (type) {
        case LessThan:
            if (key <= items[low]) {
                inRange = 0;
            }
            break;
        case LessThanEquals:
            if (key < items[low]) {
                inRange = 0;
            }
            break;
        case Equals:
            if (key < items[low] || key > items[high]) {
                inRange = 0;
            }
            break;
        case GreaterThanEquals:
            if (key > items[high]) {
                inRange = 0;
            }
            break;
        case GreaterThan:
            if (key >= items[high]) {
                inRange = 0;
            }
            break;
    }
    
    if (inRange == 0) {
        return NotFound;
    }
    
    int i, cnt;
    for (i = low, cnt = 0; cnt < n_items; ++cnt) {
        switch (type) {
            case LessThan:
                if (items[i] >= key) {
                    (*index) = (ascending) ? i - 1 : i + 1;
                    //validate index since its calculated
                    assert(isValid((*index), n_items));
                    return FoundLess;
                }
                break;
            case LessThanEquals:
                if (items[i] >= key) {
                    if (items[i] == key) {
                        (*index) = i;
                        return FoundExact;
                    } else {
                        (*index) = (ascending) ? i - 1 : i + 1;
                        //validate index since its calculated
                        assert(isValid((*index), n_items));
                        return FoundLess;
                    }
                }
                break;
            case Equals:
                if (items[i] == key) {
                    (*index) = i;
                    return FoundExact;
                }
                break;
            case GreaterThanEquals:
                if (items[i] >= key) {
                    (*index) = i;
                    if (items[(*index)] == key) {
                        return FoundExact;
                    } else {
                        return FoundGreater;
                    }
                }
                break;
            case GreaterThan:
                if (items[i] > key) {
                    (*index) = i;
                    return FoundGreater;
                }
                break;
        }
        i = (ascending) ? i + 1 : i - 1;
    }
    
    if ((type == LessThan || type == LessThanEquals) &&
        key > items[high]) {
        (*index) = high;
        return FoundLess;
    } else {
        (*index) = -1;
    }
    return NotFound;
}
コード例 #7
0
ファイル: AbcWriteJob.cpp プロジェクト: BigRoy/Maya-devkit
bool AbcWriteJob::eval(double iFrame)
{
	if (iFrame == mFirstFrame)
	{
		// check if the shortnames of any two nodes are the same
		// if so, exit here
		hasDuplicates(mArgs.dagPaths, mArgs.stripNamespace);

		std::string appWriter = "Maya ";
		appWriter += MGlobal::mayaVersion().asChar();
		appWriter += " AbcBullet v";
		appWriter += ABCBULLET_VERSION;

		std::string userInfo = "Exported from: ";
		userInfo += MFileIO::currentFile().asChar();

		// these symbols can't be in the meta data
		if (userInfo.find('=') != std::string::npos ||
			userInfo.find(';') != std::string::npos)
		{
			userInfo = "";
		}

		mRoot = CreateArchiveWithInfo(Alembic::AbcCoreHDF5::WriteArchive(),
			mFileName, appWriter, userInfo,
			Alembic::Abc::ErrorHandler::kThrowPolicy);
		mTransTimeIndex = mRoot.addTimeSampling(*mTransTime);

		mBoxProp =  Alembic::AbcGeom::CreateOArchiveBounds(mRoot,
			mTransTimeIndex);

		if (!mRoot.valid())
		{
			std::string theError = "Unable to create abc file";
			throw std::runtime_error(theError);
		}

		util::ShapeSet::const_iterator end = mArgs.dagPaths.end();
		util::GetMembersMap gmMap;
		for (util::ShapeSet::const_iterator it = mArgs.dagPaths.begin();
			it != end; ++it)
		{
			mCurDag = *it;
			setup(iFrame * util::spf(), MayaTransformWriterPtr(), gmMap);
		}
		perFrameCallback(iFrame);
	}
	else
	{
		std::set<double>::iterator checkFrame = mTransFrames.find(iFrame);
		bool foundTransFrame = false;
		if (checkFrame != mTransFrames.end())
		{
			assert(mRoot.valid());
			foundTransFrame = true;
			mTransSamples ++;

			// write out transforms
			{
				std::vector< MayaTransformWriterPtr >::iterator tcur =
					mTransList.begin();

				std::vector< MayaTransformWriterPtr >::iterator tend =
					mTransList.end();

				for (; tcur != tend; tcur++)
				{
					(*tcur)->write();
				}

				std::vector< AttributesWriterPtr >::iterator tattrCur =
					mTransAttrList.begin();

				std::vector< AttributesWriterPtr >::iterator tattrEnd =
					mTransAttrList.end();

				for(; tattrCur != tattrEnd; tattrCur++)
				{
					(*tattrCur)->write();
				}
			}

			// write out transform collections
			{
				std::vector< MayaTransformCollectionWriterPtr >::iterator tcur =
					mTransColList.begin();

				std::vector< MayaTransformCollectionWriterPtr >::iterator tend =
					mTransColList.end();

				for (; tcur != tend; tcur++)
				{
					(*tcur)->write(iFrame);
				}

				std::vector< AttributesWriterPtr >::iterator tattrCur =
					mTransColAttrList.begin();

				std::vector< AttributesWriterPtr >::iterator tattrEnd =
					mTransColAttrList.end();

				for(; tattrCur != tattrEnd; tattrCur++)
				{
					(*tattrCur)->write();
				}
			}
		}
		if (foundTransFrame)
			perFrameCallback(iFrame);
	}

	if (iFrame == mLastFrame)
	{
		postCallback(iFrame);
		return true;
	}

	return false;
}