当前位置: 首页>>代码示例>>C++>>正文


C++ SongList::push_back方法代码示例

本文整理汇总了C++中SongList::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ SongList::push_back方法的具体用法?C++ SongList::push_back怎么用?C++ SongList::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SongList的用法示例。


在下文中一共展示了SongList::push_back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: instream

/**
* @brief builds a vector of all the diffrent kinds of songs given
* @param songDataFile - the name of the song data file
* @return a vector of the songs
*/
std::vector<RankableSong*> Parser::buildSongDataBase(const std::string &songDataFile)
{
	std::ifstream instream(songDataFile.c_str());

	std::string line = "";

	int lastSong = 0;
	SongList songList;

	while (instream.good() && !lastSong)
	{
		if (line.compare(SEPARATOR) != 0)
		{
			getline(instream, line);
			// Expect a line of "="
			if (END_OF_SONGS.compare(line) == 0)
			{
				lastSong = 1;
				break;
			}

		}

		getline(instream, line);
		// Expect a line of "title: ..."
		size_t pos = TITLE.size() + 2;
		std::string title = line.substr(pos);

		getline(instream, line);
		// Expect a line of "tags: {...}"
		std::string tags = _getWordList(line);

		std::string lyrics = "";
		std::string lyricsBy = "";
		std::string instruments = "";
		std::string performedBy = "";
		std::string bpmStr = "0";

		getline(instream, line);
		// Expect either lyrics or instruments.
		if (line.substr(0, LYRICS.size()).compare(LYRICS) == 0)
		{
			// Then we have a lyric song
			// Lets get the lyrics:
			lyrics = _getWordList(line);

			// Lets get the lyricsBy:
			getline(instream, line);
			pos = LYRICS_BY.size() + 2;
			lyricsBy = line.substr(pos);

			// insert to dataBase
			songList.push_back(new RankableLyricSong(title, tags, lyrics, lyricsBy));
		}
		else
		{
			// Then we have an instrumental song
			// Lets get the instruments:
			instruments = _getWordList(line);

			// Lets get the performedBy:
			getline(instream, line);
			pos = PERFORMED_BY.size() + 2;
			performedBy = line.substr(pos);

			// Lets see if we have bpm:
			if (!instream.good())
			{
				break;
			}
			getline(instream, line);
			if (END_OF_SONGS.compare(line) == 0)
			{
				lastSong = 1;
			}


			if (line.substr(0, BPM.size()).compare(BPM) == 0)
			{
				pos = BPM.size() + 2;
				bpmStr = line.substr(pos);
			}
			else
			{
				assert((line.compare(SEPARATOR) == 0) || (line.compare(END_OF_SONGS) == 0));
			}

			songList.push_back(new RankableInstrumentalSong(title, tags, instruments, performedBy, bpmStr));
		}
	}

	instream.close();

	return songList;

//.........这里部分代码省略.........
开发者ID:ednussi,项目名称:CPP-67317,代码行数:101,代码来源:Parser.cpp


注:本文中的SongList::push_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。