const bool	OTSettings::CheckSet_long(const OTString & strSection, const OTString & strKey, const long	   & lDefault,	 long	  & out_lResult,   bool & out_bIsNew, const OTString & strComment)
{
	if (! strSection.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); }
	if (! strKey.Exists())				{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); }

	long lTempResult;
	bool bKeyExist, bNewKeyCheck;
	if (! Check_long(strSection,strKey,lTempResult,bKeyExist)) return false;

	if (bKeyExist)
	{
		// Already have a key, lets use it's value.
		out_bIsNew = false;
		out_lResult = lTempResult;
		return true;
	}
	else
	{
		if (! Set_long(strSection,strKey,lDefault,bNewKeyCheck,strComment)) return false;
		if (bNewKeyCheck)
		{
			// Success
			out_bIsNew = true;
			out_lResult = lDefault;
			return true;
		}
	}

	// If we get here, error!
	OT_ASSERT(false);
	return false;
}
示例#2
0
bool Settings::CheckSet_long(const String& strSection, const String& strKey,
                               const int64_t& lDefault, int64_t& out_lResult,
                               bool& out_bIsNew, const String& strComment)
{
    if (!strSection.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strSection"
              << " is Empty!\n";
        OT_FAIL;
    }
    if (!strKey.Exists()) {
        otErr << __FUNCTION__ << ": Error: "
              << "strKey"
              << " is Empty!\n";
        OT_FAIL;
    }

    int64_t lTempResult;
    bool bKeyExist;
    if (!Check_long(strSection, strKey, lTempResult, bKeyExist)) return false;

    if (bKeyExist) {
        // Already have a key, lets use it's value.
        out_bIsNew = false;
        out_lResult = lTempResult;
        return true;
    }
    else {
        bool bNewKeyCheck;
        if (!Set_long(strSection, strKey, lDefault, bNewKeyCheck, strComment))
            return false;
        if (bNewKeyCheck) {
            // Success
            out_bIsNew = true;
            out_lResult = lDefault;
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}