📄 iapconnectdemosettings.cpp
字号:
/*
* ============================================================================
* Name : CIAPConnectDemoSettings from IAPConnectDemoSettings.cpp
* Part of : Internet Access Points Example v2.0
* Created : 01.09.2006 by Forum Nokia
* Version : 2.0
* Copyright: Forum Nokia
* ============================================================================
*/
// INCLUDE FILES
#include "IAPConnectDemoSettings.h" // header
#include "e32math.h" //logarithm
// CONSTANTS
const TUint KNumberMaxLength = 10;
// ========================= MEMBER FUNCTIONS ================================
// Constructor
CIAPConnectDemoSettings::CIAPConnectDemoSettings()
{
}
// Destructor.
CIAPConnectDemoSettings::~CIAPConnectDemoSettings()
{
TInt i = 0;
while (i < iSettings.Count())
{
delete iSettings[i].iValue;
iSettings[i].iValue = NULL;
i++;
}
iSettings.Reset();
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::AddSettingL()
// Greate new descriptor and copy value
// ---------------------------------------------------------------------------
//
void CIAPConnectDemoSettings::AddSettingL( const TInt& aKey,
const TDesC& aValue )
{
HBufC* value = HBufC::NewLC(aValue.Length());
TPtr ptr2(value->Des());
ptr2.Copy(aValue);
//Add value to list
AddPairL( aKey, value );
CleanupStack::Pop(value);
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::AddSettingL()
// Greate new descriptor and copy value
// Because all values are saved in descriptor, numbers must convert
// ---------------------------------------------------------------------------
//
void CIAPConnectDemoSettings::AddSettingL( const TInt& aKey,
const TInt& aValue )
{
HBufC* value = HBufC::NewLC( KNumberMaxLength );
TPtr ptr2(value->Des());
ptr2.AppendNum( aValue );
AddPairL( aKey, value);
CleanupStack::Pop(value);
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::AddPairL()
// Greate new SettingsPair class if key doesn't exist otherwise only change
// value
// ---------------------------------------------------------------------------
//
void CIAPConnectDemoSettings::AddPairL( const TInt& aKey, HBufC* aValue)
{
TUint index = 0;
if ( KeyIndex( aKey, index ) != KErrNone)
{
//aKey isn't found from list
//Transfer value's ownership
TDemoSettingsPair pair;
pair.iKey = aKey;
pair.iValue = aValue;
iSettings.AppendL( pair );
}
else
{
// Delete the old value and replace it with a new one
delete iSettings[ index ].iValue;
iSettings[ index ].iValue = NULL;
iSettings[ index ].iValue = aValue;
}
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::GetSetting()
// Return key's value in reference parameter if key exist
// ---------------------------------------------------------------------------
//
TInt CIAPConnectDemoSettings::GetSetting( const TInt& aKey,
TDesC& aValue ) const
{
TUint index = 0;
if ( KeyIndex( aKey, index ) != KErrNone)
{
return KErrNotFound;
}
aValue = iSettings[ index ].iValue -> Des();
return KErrNone;
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::GetSetting()
// Return key's value in reference parameter if key exist
// ---------------------------------------------------------------------------
//
TInt CIAPConnectDemoSettings::GetSetting( const TInt& aKey,
HBufC*& aValue) const
{
TUint index = 0;
if ( KeyIndex( aKey, index ) != KErrNone)
{
return KErrNotFound;
}
aValue = iSettings[ index ].iValue;
return KErrNone;
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::GetSetting()
// Return key's value in reference parameter if key exist
// Before return, descriptor must change to integer
// ---------------------------------------------------------------------------
//
TInt CIAPConnectDemoSettings::GetSetting( const TInt& aKey,
TInt& aValue ) const
{
TUint index = 0;
if ( KeyIndex( aKey, index ) != KErrNone)
{
return KErrNotFound;
}
TLex converter ( iSettings[ index ].iValue -> Des() );
TInt error = converter.Val( aValue );
if ( error != KErrNone )
{
return error;
}
return KErrNone;
}
// ---------------------------------------------------------------------------
// CIAPConnectDemoSettings::KeyIndex()
// Search key's index in list. Return errorcode, if key is not found
// ---------------------------------------------------------------------------
//
TInt CIAPConnectDemoSettings::KeyIndex( const TInt& aKey,
TUint& index) const
{
while ( index < static_cast<TUint>( iSettings.Count()) &&
iSettings[ index ].iKey != aKey)
{
++index;
}
if (index == static_cast<TUint> (iSettings.Count()))
{
return KErrNotFound;
}
else
{
return KErrNone;
}
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -