static void _streamFill(void) { // do we have any free packets? if (XMEDIAPACKET_STATUS_PENDING != s_pState->m_Stream.m_PacketStatus[s_pState->m_Stream.m_CurrentPacket]) { // get some data int size = _streamFromFile(); if (size > 0) { _streamToVoice(size); // next packet... ++s_pState->m_Stream.m_CurrentPacket; s_pState->m_Stream.m_CurrentPacket %= QAL_MAX_STREAM_PACKETS; } if (!s_pState->m_Stream.m_Playing) { // Non-looping stream finished playback s_pState->m_Stream.m_pVoice->Discontinuity(); } } }
const int CXCFileStream::ReadCsvData(LPCTSTR lpszFilename, vector<list<string> > &vlStr) { /// 1、判断是否是CSV文件 if (! IsCsvFile(lpszFilename)) return XC_ERR_INVALID_FILE_NAME; /// 2、打开CSV文件 ifstream _streamFromFile(lpszFilename); /// 判断打开文件是否成功 if (NULL == _streamFromFile) return (-errno); /// 存储读取的文件内容 string _strIn(""); /// 3、读取一行 while (getline(_streamFromFile, _strIn)) { /// 每行的源字符串 LPCTSTR _pcSrc = _strIn.c_str(); /// 存储一行‘,'分隔解析后的各个元素 list<string> _ltStr; /// Parse values in this line while (*_pcSrc != '\0') { /// string to hold this value string _strElem(""); /// 针对每个字符分析 if (*_pcSrc == '"') { /// Bump past opening quote _pcSrc++; /// Parse quoted value while (*_pcSrc != '\0') { /// Test for quote character if (*_pcSrc == '"') { /// Found one quote _pcSrc++; // If pair of quotes, keep one // Else interpret as end of value if (*_pcSrc != '"') { _pcSrc++; break; } } /// Add this character to value _strElem.push_back(*_pcSrc++); } } else { // Parse unquoted value while (*_pcSrc != '\0' && *_pcSrc != ',') _strElem.push_back(*_pcSrc++); // Advance to next character (if not already end of string) if (*_pcSrc != '\0') _pcSrc++; } /// Add this string to container _ltStr.push_back(_strElem); } /// 分析后的一行文件内容所得的元素列表添加到容器中 vlStr.push_back(_ltStr); /// 归零,防止下次分析旧的数据。 _strIn.assign(""); } return XC_ERR_NONE; }