Esempio n. 1
0
    int lengthLongestPath(string input) {
        stack<int> stru;
        stru.push(-1);

        int maxLen = 0, lastLayer = -1;
        while (input.empty() == false) {
            int tabN = readTabs(input);
            string dir = readDir(input);

            if (tabN > lastLayer + 1) return -1;
            while (tabN <= lastLayer) {
                if (stru.empty() == true) return -1;
                stru.pop();
                lastLayer--;
            }
            stru.push(stru.top() + 1 + dir.size());
            if (isFile(dir) == true) maxLen = max(maxLen, stru.top());
            lastLayer = tabN;
        }
        return maxLen;
    }
Esempio n. 2
0
TabSong* ConvertGtp::load(string fileName)
{
	stream.open(fileName.c_str() , ios::binary);
	if(stream.fail())
		return NULL;

	int size = stream.tellg();

	try {
		song = new TabSong();

		readSignature();
		song->t.clear();
		readSongAttributes();
	 	readTrackDefaults();

		//char st[50];
		//stream.read(st, 50);

	 	numBars = readDelphiInteger();           // Number of bars
		if (numBars <= 0 || (strongChecks && numBars > 16384))  
			throw string("Insane number of bars: %1");
		//osg::notify(osg::INFO) << "Bars: " << numBars << "\n";

	 	numTracks = readDelphiInteger();         // Number of tracks
		if (numTracks <= 0 || (strongChecks && numTracks > 32))  
			throw string("Insane number of tracks: %1");
		//osg::notify(osg::INFO) << "Tracks: " << numTracks << "\n";

	 	readBarProperties();
	 	readTrackProperties();
	 	readTabs();

		currentStage = string("Exit code");
		if (stream.eof()) {
			int ex = readDelphiInteger();            // Exit code: 00 00 00 00
			if (ex != 0)
				;//osg::notify(osg::INFO) << "File not ended with 00 00 00 00\n";
			if (!stream.eof())
				;//osg::notify(osg::INFO) << "File not ended - there's more data!\n";
		}
	} 
	catch (string msg) 
	{
		//osg::notify(osg::WARN) << "Error loading Tab: " << msg;
		stream.close();
		stream.clear();
		return NULL;
	}
	catch ( exception e )
	{
		//osg::notify(osg::WARN) << "Error loading Tab: " << e.what();
		stream.close();
		stream.clear();
		return NULL;
	}

	stream.close();

	return song;
}