C++ (Cpp) wxScopedCharBuffer Example

Introduction

The c++ (cpp) wxscopedcharbuffer example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: C++ (Cpp)

Class/type: wxScopedCharBuffer

Example#1
File: dobjcmn.cppProject: Toonerz/project64

size_t wxHTMLDataObject::GetDataSize() const
{
    const wxScopedCharBuffer buffer(GetHTML().utf8_str());

    size_t size = buffer.length();

#ifdef __WXMSW__
    // On Windows we need to add some stuff to the string to satisfy
    // its clipboard format requirements.
    size += 400;
#endif

    return size;
}

Example#2
File: password_manager.cppProject: frodegill/wxMailto

wxmailto_status PasswordManager::SaveCredential(wxUInt& id, const wxString& encrypted_location_hex, const wxString& encrypted_username_hex, const wxString& encrypted_password_hex)
{
	wxmailto_status status;
	wxBool update = true;
	if (0 == id)
	{
		PersistentProperty* p = new PersistentProperty();
		if (!p)
			return LOGERROR(ID_OUT_OF_MEMORY);

		if (ID_OK != (status=p->Initialize(NEXT_CREDENTIAL_ID, &wxGetApp().GetGlobalLockers()->m_next_credential_id_lock)) ||
		    ID_OK != (status=p->GetNextAvailableId(id)))
		{
			delete p;
			return status;
		}

		delete p;
		update = false;
	}

	PocoGlue* poco_glue = wxGetApp().GetAppModuleManager()->GetPocoGlue();
	if (!poco_glue)
		return LOGERROR(ID_EXIT_REQUESTED);

	Poco::Data::Session* session;
	if (ID_OK!=(status=poco_glue->CreateSession(session)) ||
	    ID_OK!=(status=poco_glue->StartTransaction(session)))
	{
		return status;
	}

	const wxScopedCharBuffer encrypted_location_buffer = encrypted_location_hex.ToUTF8();
	const wxScopedCharBuffer encrypted_username_buffer = encrypted_username_hex.ToUTF8();
	const wxScopedCharBuffer encrypted_password_buffer = encrypted_password_hex.ToUTF8();
	
	Poco::Data::BLOB encrypted_location_blob(reinterpret_cast<const wxUint8*>(encrypted_location_buffer.data()), encrypted_location_buffer.length());
	Poco::Data::BLOB encrypted_username_blob(reinterpret_cast<const wxUint8*>(encrypted_username_buffer.data()), encrypted_username_buffer.length());
	Poco::Data::BLOB encrypted_password_blob(reinterpret_cast<const wxUint8*>(encrypted_password_buffer.data()), encrypted_password_buffer.length());
	if (update)
	{
		*session << "UPDATE credentials SET location=?,username=?,password=? WHERE id=?",
				Poco::Data::Keywords::use(encrypted_location_blob),
				Poco::Data::Keywords::use(encrypted_username_blob),
				Poco::Data::Keywords::use(encrypted_password_blob),
				Poco::Data::Keywords::use(id),
				Poco::Data::Keywords::now;
	}
	else
	{
		*session << "INSERT INTO credentials (id,location,username,password) VALUES (?,?,?,?)",
				Poco::Data::Keywords::use(id),
				Poco::Data::Keywords::use(encrypted_location_blob),
				Poco::Data::Keywords::use(encrypted_username_blob),
				Poco::Data::Keywords::use(encrypted_password_blob),
				Poco::Data::Keywords::now;
	}

	poco_glue->CommitTransaction(session);
	poco_glue->ReleaseSession(session);

	return ID_OK;
}