Exemple #1
0
bool INIFile::ParseFile(ifstream& f)
{
  if ( !f.is_open() )
    return false;

  char* pPos1 = NULL, *pPos2 = NULL;
  int nLine = 0;
  char buffer[1024];
  string strSection, strKey, strVal;
  CSection* pSection = NULL;

  while ( f.getline(buffer, sizeof(buffer)) )
  {
		nLine++;

		// is this the beginning of a section?
		if ( buffer[0] == c_INISectionNameStart )
		{
			// yes, so get the end of the section name
			pPos1 = strchr( buffer, c_INISectionNameEnd );
			*pPos1 = '\0';
			pSection = new CSection;
			m_lstSections.push_back(pSection);
      strSection = &buffer[1];
      std::transform(strSection.begin(), strSection.end(), strSection.begin(), (int(*)(int))tolower);
			pSection->SetName( strSection );
			continue;
		}
		// check that it is not a comment
		if ( buffer[0] != c_INIComment )
		{
			if ( (pPos2 = strchr( buffer, '=' )) )
			{
				*pPos2 = '\0';
				strKey = buffer;
        // make the key lower case
        std::transform(strKey.begin(), strKey.end(), strKey.begin(), (int(*)(int))tolower);
        // trim the key
				strKey.erase( strKey.find_last_not_of(" \r\n")+1);
				strVal = pPos2+1;
        // trim the value
				strKey.erase( strKey.find_last_not_of(" \r\n")+1);
				if ( pSection )
				{
					pSection->AddKey( strKey, strVal);
				}
				else
				{
          return false;
				}
			}
		}
  }

  return true;
}
	xst_cwstring& CCfgFile::GetValue(xst_cwstring& strKey, xst_cwstring& strSection, xst_cwstring& strDefault)
	{
		CSection* pSec = _GetSection( strSection );
		if( pSec == xst_null )
		{
			return strDefault;
		}

		return pSec->GetValue( strKey, strDefault );
	}
/**
	Writes a 'section' node containing the metadata of one single section.
	@param section: section object with the metadata of a section
*/
void CitationsXMLGenerator::addSection(const CSection &section)
{
    addOpenningTag(aXMLFile, "section");
    addSectionType(section.getSectionType());
    addSectionTitle(section.getTitle());
    if(section.getPSubSection()!=NULL) {
        addSection(*section.getPSubSection());
    }
    addClosingTag(aXMLFile, "section");
}
Exemple #4
0
INIFile::CSection* INIFile::AddSection(string name)
{
	if ( !name.empty() )
		return NULL;

	CSection*		pSection = new CSection;

	pSection->SetName(name);
	m_lstSections.push_back(pSection);
	return pSection;
}
Exemple #5
0
string INIFile::GetValueString(const string section, const string key)
{
  CSection* pSection = GetSection(section);
  string val;

  if ( pSection )
  {
    val = pSection->GetValue(key);
  }

  return val;
}
CParameter *CParameterSet::GetParameter(const char *SectionName, const char *ParameterName)
{
	CSection *CurSection;
	CParameter *CurParameter;

	CurSection = mFirstSection->Find(SectionName);
	if (CurSection != NULL)
		CurParameter = CurSection->FindParameter(ParameterName);
	else
		CurParameter = NULL;
	return CurParameter;
}
	i32 CCfgFile::_LoadUnicode(cch16* pFileData, cul32& ulDataSize)
	{
		//TCData< ch16 > Data;
		//Set ulDataSize / sizeof( ch16 ) because it must be size of the wide char buffer
		//ulDataSize is the size (in bytes) of all file data except BOM
		//Data.Create( (const xst_unknown)pFileData, ulDataSize, ulDataSize / sizeof( ch16 ), true );

		//Tokenize file
		XST::StringUtil::TokensW vTokens;
		XST::StringUtil::SplitExcept( pFileData, &vTokens, L"\"", L"\"", L"\t\r\n= " );
		//Get default section
		CSection* pCurrSection = xst_null; //_GetOrCreateSection( "" );

		for(u32 i = 0; i < vTokens.size(); ++i)
		{
			xst_wstring& strCurrToken = vTokens[ i ];

			//Skip comments
			if( strCurrToken[0] == L'#' || (  strCurrToken.length() > 1 && strCurrToken[0] == L'/' && strCurrToken[1] == L'/' ) ) continue;
			//If section name
			if( strCurrToken[0] == L'[' && strCurrToken[ strCurrToken.length() - 1 ] == L']' )
			{
				//Create new section or add to the existing
				pCurrSection = _GetOrCreateSection( strCurrToken.substr( 1, strCurrToken.length() - 2 ) );
			}
			else
			{
				//If key = value exists
				if( i + 1 < vTokens.size() )
				{

					if( pCurrSection == xst_null )
					{
						pCurrSection = _GetOrCreateSection( L"" );
					}

					xst_wstring& strNextToken = vTokens[ i + 1 ];
					ch16 c = strNextToken[ strNextToken.length() - 1 ];
					if( strNextToken[0] == L'"' && strNextToken[ strNextToken.length() - 1 ] == L'"' )
					{
						strNextToken = strNextToken.substr( 1, strNextToken.length() - 2 );
					}
					pCurrSection->AddValue( strCurrToken, strNextToken );

					++i;
				}
			}

		}

		m_bLoaded = true;
		return RESULT::OK;
	}
Exemple #8
0
short INIFile::GetValueShort(const string section, const string key)
{
  CSection* pSection = GetSection(section);
  short sRet = 0;
  string val;

  if ( pSection )
  {
    val = pSection->GetValue(key);
    sRet = (short)atoi(val.c_str());
  }

  return sRet;
}
	i32 CCfgFile::_LoadAscii(cch8* pFileData, cul32& ulDataSize)
	{
		//Tokenize file
		XST::StringUtil::TokensA vTokens;
		XST::StringUtil::SplitExcept( pFileData, &vTokens, "\"", "\"", "\t\r\n= " );
		//Get default section
		CSection* pCurrSection = xst_null; //_GetOrCreateSection( "" );

		for(u32 i = 0; i < vTokens.size(); ++i)
		{
			xst_astring& strCurrToken = vTokens[ i ];

			//Skip comments
			if( strCurrToken[0] == '#' || (  strCurrToken.length() > 1 && strCurrToken[0] == '/' && strCurrToken[1] == '/' ) ) continue;
			//If section name
			if( strCurrToken[0] == '[' && strCurrToken[ strCurrToken.length() - 1 ] == ']' )
			{
				//Create new section or add to the existing
				pCurrSection = _GetOrCreateSection( strCurrToken.substr( 1, strCurrToken.length() - 2 ) );
			}
			else
			{
				//If key = value exists
				if( i + 1 < vTokens.size() )
				{

					if( pCurrSection == xst_null )
					{
						pCurrSection = _GetOrCreateSection( "" );
					}

					xst_astring& strNextToken = vTokens[ i + 1 ];
					ch16 c = strNextToken[ strNextToken.length() - 1 ];
					if( strNextToken[0] == '"' && strNextToken[ strNextToken.length() - 1 ] == '"' )
					{
						strNextToken = strNextToken.substr( 1, strNextToken.length() - 2 );
					}
					pCurrSection->AddValue( strCurrToken, strNextToken );

					++i;
				}
			}

		}

		m_bLoaded = true;
		return RESULT::OK;
	}
Exemple #10
0
// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
void CSection::AddNext(CSection& next)
{
	if(next.IsOnMaintrack())
	{
		if(m_nextMain!=NULL)
			throw ASEException("Track has two next main track",m_trackMesh->GetName().c_str());
		else
			m_nextMain = &next;
	}
	else
	{
		if(m_nextAlt!=NULL)
			throw ASEException("Track has two next alt track",m_trackMesh->GetName().c_str());
		else
			m_nextAlt = &next;
	}
	if(IsOnMaintrack())
	{
		if(next.m_prevMain!=NULL)
			throw ASEException("Track has two previous main track",next.m_trackMesh->GetName().c_str());

		next.m_prevMain = this;
	}
	else
	{
		if(next.m_prevAlt!=NULL)
			throw ASEException("Track has two previous alt track",next.m_trackMesh->GetName().c_str());
		next.m_prevAlt = this;
	}
}
void CParameterSet::AddParameter(char *SectionName, char *ParameterName, CParameterValue &Value)
{
	CSection *CurSection;

	if (mFirstSection == NULL)
		mFirstSection = new CSection(SectionName);

	CurSection = mFirstSection->Find(SectionName);

	if (CurSection == NULL)
	{
		CurSection = new CSection(SectionName);
		mFirstSection->AddAtEnd(CurSection);
	}

	CurSection->AddParameter(ParameterName, Value);
}
Exemple #12
0
int main(int argc, char* argv[])
{	
	SECTION_INFO_T sec;
	CSection* section = new CSection();
	PAT* pat = new PAT();

	// open media test, media is file
	section->openMedia("file://SGP.ts");

	// create task to read continously
	std::thread tr = std::thread([&]() {

		while(1)
		{
			if(section->readMedia(&sec) == RESULT_NOTOK)
				break;

			// PAT parsing PAT PID is zero
			if(sec.pid == 0)
			{
				pat->parsingPATSection((UINT8*)sec.section);
			}
		}
	});

	tr.join();

	// print PAT info
	pat->printPATList();
	pat->savePatToJson();

	delete section;
	delete pat;

	return 0;	
}