Ejemplo n.º 1
0
const bool	OTSettings::Set_bool(const OTString & strSection, const OTString & strKey, const bool	  & bValue,   bool & out_bNewOrUpdate, 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); }
	const OTString strValue(bValue ? "true" : "false");

	return Set_str(strSection,strKey,strValue,out_bNewOrUpdate,strComment);
}
Ejemplo n.º 2
0
bool Settings::CheckSet_str(const String& strSection, const String& strKey,
                              const String& strDefault, std::string& out_strResult,
                              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;
    }

    const char* const szDefault =
        (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get()
                                                         : nullptr;

    String strTempResult;
    bool bKeyExist;
    if (!Check_str(strSection, strKey, strTempResult, bKeyExist)) return false;

    if (bKeyExist) {
        // Already have a key, lets use it's value.
        out_bIsNew = false;
        out_strResult = strTempResult.Get();
        return true;
    }
    else {
        bool bNewKeyCheck;
        if (!Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
            return false;

        if (nullptr == szDefault) // The Default is to have no key.
        {
            // Success
            out_bIsNew = false;
            out_strResult = "";
            return true;
        }

        if (bNewKeyCheck) {
            // Success
            out_bIsNew = true;
            out_strResult = strDefault.Get();
            return true;
        }
    }

    // If we get here, error!
    OT_FAIL;
}
Ejemplo n.º 3
0
const bool	OTSettings::CheckSet_str (const OTString & strSection, const OTString & strKey, const OTString & strDefault, OTString & out_strResult, 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); }

	const char * const szDefault = (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get() : NULL;

	OTString strTempResult;
	bool bKeyExist, bNewKeyCheck;
	if (! Check_str(strSection,strKey,strTempResult,bKeyExist)) return false;

	if (bKeyExist)
	{
		// Already have a key, lets use it's value.
		out_bIsNew = false;
		out_strResult = strTempResult;
		return true;
	}
	else
	{
		if (! Set_str(strSection,strKey,strDefault,bNewKeyCheck,strComment)) return false;

		if (NULL == szDefault) // The Default is to have no key.
		{
			// Success
			out_bIsNew = false;
			out_strResult = "";
			return true;
		}
		
		if (bNewKeyCheck)
		{
			// Success
			out_bIsNew = true;
			out_strResult = strDefault;
			return true;
		}
	}

	// If we get here, error!
	OT_ASSERT(false);
	return false;
}
Ejemplo n.º 4
0
bool Settings::Set_bool(const String& strSection, const String& strKey,
                          const bool& bValue, bool& out_bNewOrUpdate,
                          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;
    }
    const String strValue(bValue ? "true" : "false");

    return Set_str(strSection, strKey, strValue, out_bNewOrUpdate, strComment);
}