1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/* ====================================================================
* Copyright (c) 2003-2007, Martin Hauner
* http://subcommander.tigris.org
*
* Subcommander is licensed as described in the file doc/COPYING, which
* you should have received as part of this distribution.
* ====================================================================
*/
// sc
#include "ConfigValue.h"
// qt
#include <QtCore/QString>
ConfigValue::ConfigValue( const sc::String& key, const sc::String& value )
: _key(key), _value(value)
{
}
ConfigValue::ConfigValue( const sc::String& key, unsigned long value )
: _key(key)
{
setOptionValue(value);
}
ConfigValue::ConfigValue( const sc::String& key, long value )
: _key(key)
{
setNumericValue(value);
}
ConfigValue::ConfigValue( const sc::String& key, bool value )
: _key(key)
{
setBoolValue(value);
}
ConfigValue::ConfigValue( const ConfigValue& src )
: _key(src._key), _value(src._value)
{
}
const sc::String& ConfigValue::getKey() const
{
return _key;
}
const sc::String& ConfigValue::getStringValue() const
{
return _value;
}
unsigned long ConfigValue::getOptionValue() const
{
bool b = false;
return QString(_value.getStr()).toULong(&b,16);
}
long ConfigValue::getNumericValue() const
{
return QString(_value.getStr()).toLong();
}
bool ConfigValue::getBoolValue() const
{
if( _value == sc::String("true") )
{
return true;
}
else
{
return false;
}
}
void ConfigValue::setStringValue( const sc::String& v )
{
_value = v;
}
void ConfigValue::setOptionValue( unsigned long v )
{
_value = sc::String(QString("%1").arg(v,0,16).toUtf8());
}
void ConfigValue::setNumericValue( long v )
{
_value = sc::String(QString("%1").arg(v).toUtf8());
}
void ConfigValue::setBoolValue( bool b )
{
if( b )
{
_value = "true";
}
else
{
_value = "false";
}
}
bool ConfigValue::isNull()
{
return _key.getCharCnt() == 0;
}
|