📄 vminifileloader.cpp
字号:
INPUT: oSection - the section for the lookup
oKey - the key (within the section) to lookup
OUTPUT:
RETURNS: string if found, emptry string if not
*/
std::string VMIniFileLoader::GetSectionValueAsString( std::string oSection, std::string oKey ){ SECTION_MAP_ITER oSectionsIter = m_oEntries.find( oSection ); if ( oSectionsIter == m_oEntries.end() ) { return( std::string( "" ) ); } else { STRING_MAP* poSection = (*oSectionsIter).second; STRING_MAP_ITER oIter = poSection->find( oKey );
if ( oIter == poSection->end() ) { return( std::string( "" ) ); } else { return( (*oIter).second ); } }}/* End of function "VMIniFileLoader::GetSectionValueAsString"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetSectionValueAsInteger
DESCRIPTION: returns the value stored under the section/key key pair
INPUT: oSection - the section for the lookup
oKey - the key (within the section) to lookup
OUTPUT:
RETURNS: int value of string if found, zero if not
*/
int VMIniFileLoader::GetSectionValueAsInteger( std::string oSection, std::string oKey ){ std::string oValue; oValue = GetSectionValueAsString( oSection, oKey ); return( atoi( oValue.c_str() ) );}/* End of function "VMIniFileLoader::GetSectionValueAsInteger"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetSectionValueAsBool
DESCRIPTION: returns the value stored under the section/key key pair
INPUT: oSection - the section for the lookup
oKey - the key (within the section) to lookup
OUTPUT:
RETURNS: bool value of string if found, false if not
*/
bool VMIniFileLoader::GetSectionValueAsBool( std::string oSection, std::string oKey ){ std::string oValue; oValue = GetSectionValueAsString( oSection, oKey ); return( oValue == "true" );}/* End of function "VMIniFileLoader::GetSectionValueAsBool"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetValueAsString
DESCRIPTION: returns the value found under the combined section/key pair
if the value is not found, will store the default value if
bStoreDefault is true
INPUT: oSection - the section to use
oKey - the key to look up within the section
oDefaultValue - the default value
bStoreDefault - flag to drive storage of the default
OUTPUT:
RETURNS: data value stored under the combined key
*/
std::string VMIniFileLoader::GetValueAsString( std::string oSection, std::string oKey, std::string oDefaultValue, bool bStoreDefault ){ SECTION_MAP_ITER oSectionsIter = m_oEntries.find( oSection );
if ( oSectionsIter == m_oEntries.end() ) { if ( bStoreDefault ) { STRING_MAP* poNewMap = new STRING_MAP; poNewMap->insert( STRING_MAP::value_type( oKey, oDefaultValue ) ); m_oEntries.insert( SECTION_MAP::value_type( oSection, poNewMap ) ); } return( oDefaultValue ); } else { STRING_MAP* poSection = (*oSectionsIter).second; STRING_MAP_ITER oIter = poSection->find( oKey );
if ( oIter == poSection->end() ) { poSection->insert( STRING_MAP::value_type( oKey, oDefaultValue ) ); return( oDefaultValue ); } else { return( (*oIter).second ); } }}/* End of function "VMIniFileLoader::GetValueAsString"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetValueAsInteger
DESCRIPTION: returns the value found under the combined section/key pair
if the value is not found, will store the default value if
bStoreDefault is true
INPUT: oSection - the section to use
oKey - the key to look up within the section
iDefaultValue - the default value
bStoreDefault - flag to drive storage of the default
OUTPUT:
RETURNS: data value stored under the combined key as an integer
*/
int VMIniFileLoader::GetValueAsInteger( std::string oSection, std::string oKey, int iDefaultValue, bool bStoreDefault ){ char achValue[ 32 ]; sprintf( achValue, "%d", iDefaultValue ); std::string oValue; oValue = GetValueAsString( oSection, oKey, std::string( achValue ), bStoreDefault ); return( atoi( oValue.c_str() ) );}/* End of function "VMIniFileLoader::GetValueAsInteger"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetValueAsBool
DESCRIPTION: returns the value found under the combined section/key pair
if the value is not found, will store the default value if
bStoreDefault is true
INPUT: oSection - the section to use
oKey - the key to look up within the section
oDefaultValue - the default value
bStoreDefault - flag to drive storage of the default
OUTPUT:
RETURNS: data value stored under the combined key as a boolean
*/
bool VMIniFileLoader::GetValueAsBool( std::string oSection, std::string oKey, bool bDefaultValue, bool bStoreDefault ){ char achValue[ 32 ]; sprintf( achValue, "%s", bDefaultValue ? "true" : "false"); std::string oValue; oValue = GetValueAsString( oSection, oKey, std::string( achValue ), bStoreDefault ); return( oValue == "true" );}/* End of function "VMIniFileLoader::GetValueAsBool"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetProfileSectionName
DESCRIPTION: sets the 'current default section' for this
INPUT: oName - the name of the section to use for the current
OUTPUT: none
RETURNS: void
*/
void VMIniFileLoader::SetProfileSectionName( std::string oName ){ char *name = (char *) oName.c_str(); if (name[ 0 ] != '[' ) { m_oProfileSection = "[" + oName + "]"; } else { m_oProfileSection = oName; }}/* End of function "VMIniFileLoader::SetProfileSectionName"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetValue
DESCRIPTION: sets the value of the data stored under the section/key pair
INPUT: oSection - section to store value in
oKey - key to use for the data storage
oValue - the value to store at the given location
OUTPUT:
RETURNS: void
*/
void VMIniFileLoader::SetValue( std::string oSection, std::string oKey, std::string oValue ){ SECTION_MAP_ITER oSectionsIter = m_oEntries.find( oSection );
if ( oSectionsIter == m_oEntries.end() ) { STRING_MAP* poNewMap = new STRING_MAP; poNewMap->insert( STRING_MAP::value_type( oKey, oValue ) ); m_oEntries.insert( SECTION_MAP::value_type( oSection, poNewMap ) ); } else { STRING_MAP* poSection = (*oSectionsIter).second; STRING_MAP_ITER oIter = poSection->find( oKey ); if ( oIter != poSection->end() ) { poSection->erase( oKey ); } poSection->insert( STRING_MAP::value_type( oKey, oValue ) ); }}/* End of function "VMIniFileLoader::SetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetValue
DESCRIPTION: stores the given key value pair in the global section
INPUT: oKey - the key to store under
oValue - the value to store
OUTPUT:
RETURNS: void
*/
void VMIniFileLoader::SetValue( std::string oKey, std::string oValue ){ SetValue( std::string( cchGlobal ), oKey, oValue );}/* End of function "VMIniFileLoader::SetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetValue
DESCRIPTION: sets the value of the data stored under the section/key pair
INPUT: oSection - section to store value in
oKey - key to use for the data storage
iValue - the integer value to store at the given location
OUTPUT:
RETURNS: void
*/
void VMIniFileLoader::SetValue( std::string oSection, std::string oKey, int iValue ){ char achValue[ 32 ]; sprintf( achValue, "%d", iValue ); SetValue( oSection, oKey, std::string( achValue ) );}/* End of function "VMIniFileLoader::SetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetValue
DESCRIPTION: stores the given key value pair in the global section
INPUT: oKey - the key to store under
iValue - the integer value to store
OUTPUT:
RETURNS: void
*/
void VMIniFileLoader::SetValue( std::string oKey, int iValue ){ SetValue( std::string( cchGlobal ), oKey, iValue );}/* End of function "VMIniFileLoader::SetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetValue
DESCRIPTION: sets the value of the data stored under the section/key pair
INPUT: oSection - section to store value in
oKey - key to use for the data storage
bValue - the boolean value to store at the given location
OUTPUT:
RETURNS: void
*/
void VMIniFileLoader::SetValue( std::string oSection, std::string oKey, bool bValue ){ SetValue( oSection, oKey, std::string( bValue ? "true" : "false" ) );}/* End of function "VMIniFileLoader::SetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetValue
DESCRIPTION: stores the given key value pair in the global section
INPUT: oKey - the key to store under
bValue - the boolean value to store
OUTPUT:
RETURNS: void
*/
void VMIniFileLoader::SetValue( std::string oKey, bool bValue ){ SetValue( std::string( cchGlobal ), oKey, bValue );}/* End of function "VMIniFileLoader::SetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetSection
DESCRIPTION: returns the entire contents of the given section to the
caller.
INPUT: oSection - the section to return
OUTPUT: none
RETURNS: pointer to the data set stored under the given section,
NULL if no data in the given section
*/
int VMIniFileLoader::GetSection( std::string oSection, STRING_MAP& roOutput ){ SECTION_MAP_ITER oSectionsIter = m_oEntries.find( oSection );
if ( oSectionsIter == m_oEntries.end() ) { return( 0 ); } return( CloneMap( *( (*oSectionsIter).second ), roOutput ) );
}/* End of function "VMIniFileLoader::GetSection"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::SetSection
DESCRIPTION: allows a section to be constructed outside of this, then
stored here for future use
INPUT: oSection - the name of the section
roSectionValues - section data to store
OUTPUT:
RETURNS: void -
*/
void VMIniFileLoader::SetSection( std::string oSection, STRING_MAP& roSectionValues ){ STRING_MAP* poNewMap = new STRING_MAP; CloneMap( roSectionValues, *poNewMap ); m_oEntries.insert( SECTION_MAP::value_type( oSection, poNewMap ) );}/* End of function "VMIniFileLoader::SetSection"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::CloneMap
DESCRIPTION: performs a deep copy of a data section
INPUT: roSource -
roTarget -
OUTPUT:
RETURNS: the number of values copied
*/
int VMIniFileLoader::CloneMap( STRING_MAP& roSource, STRING_MAP& roTarget ){ int iEntryCount = 0; // keeps track of number of entries copied between maps STRING_MAP_ITER oIter; for ( oIter = roSource.begin(); oIter != roSource.end(); oIter++ ) { roTarget.insert( STRING_MAP::value_type( (*oIter).first, (*oIter).second ) ); iEntryCount++; } return( iEntryCount );} /* End of function "VMIniFileLoader::CloneMap"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMIniFileLoader::GetSectionMap
DESCRIPTION: returns the entire data set to the caller
INPUT: void
OUTPUT: none
RETURNS: SECTION_MAP*
*/
SECTION_MAP* VMIniFileLoader::GetSectionMap( void ){ return( &m_oEntries );}/* End of function "VMIniFileLoader::GetSectionMap"
/*****************************************************************************/
/*****************************************************************************/
/* Check-in history
$WorkFile: $
$Archive: $
*$Log: $
*/
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -