/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * This class is used by the storage module whenever an nsIVariant needs to be * returned. We provide traits for the basic sqlite types to make use easier. * The following types map to the indicated sqlite type: * int64_t -> INTEGER (use IntegerVariant) * double -> FLOAT (use FloatVariant) * nsString -> TEXT (use TextVariant) * nsCString -> TEXT (use UTF8TextVariant) * uint8_t[] -> BLOB (use BlobVariant) * nullptr -> NULL (use NullVariant) * int64_t[] -> ARRAY (use ArrayOfIntegersVariant) * double[] -> ARRAY (use ArrayOfDoublesVariant) * nsCString[] -> ARRAY (use ArrayOfUTF8StringsVariant) * * The kvstore component also reuses this class as a common implementation * of a simple threadsafe variant for the storage of primitive values only. * The BooleanVariant type has been introduced for kvstore use cases and should * be enhanced to provide full boolean variant support for mozStorage. * * Bug 1494102 tracks that work.
*/
namespace mozilla::storage {
//////////////////////////////////////////////////////////////////////////////// //// Base Class
class Variant_base : public nsIVariant, public nsIInterfaceRequestor { public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIVARIANT
NS_DECLARE_STATIC_IID_ACCESSOR(VARIANT_BASE_IID)
// This is used to recognize nsIVariant instances derived from Variant_base // from other implementations like XPCVariant that may not be thread-safe. if (aIID.Equals(VARIANT_BASE_IID) || aIID.Equals(NS_GET_IID(nsIVariant))) {
nsCOMPtr<nsIVariant> result(static_cast<nsIVariant*>(this));
result.forget(aResult); return NS_OK;
}
template <> struct variant_storage_traits<nsCString[], false> { using ConstructorType = std::pair<constvoid*, int>; using StorageType = FallibleTArray<nsCString>; staticinlinevoid storage_conversion(ConstructorType aArrayAndLength,
StorageType* _outData) {
_outData->Clear(); if (!_outData->SetCapacity(aArrayAndLength.second, fallible)) {
MOZ_ASSERT_UNREACHABLE("Cannot allocate."); return;
} // We can avoid copying the strings as we're asking SQLite to do it on bind // by using SQLITE_TRANSIENT. const nsCString* str = static_cast<const nsCString*>(aArrayAndLength.first); for (int32_t i = 0; i < aArrayAndLength.second; ++i, str++) {
MOZ_ALWAYS_TRUE(_outData->AppendElement(*str, fallible));
}
}
//////////////////////////////////////////////////////////////////////////////// //// Handy typedefs! Use these for the right mapping.
// Currently, BooleanVariant is only useful for kvstore. // Bug 1494102 tracks implementing full boolean variant support for mozStorage. using BooleanVariant = Variant<bool>;
using IntegerVariant = Variant<int64_t>; using FloatVariant = Variant<double>; using TextVariant = Variant<nsString>; using UTF8TextVariant = Variant<nsCString>; using BlobVariant = Variant<uint8_t[], false>; using AdoptedBlobVariant = Variant<uint8_t[], true>; using ArrayOfIntegersVariant = Variant<int64_t[], false>; using AdoptedArrayOfIntegersVariant = Variant<int64_t[], true>; using ArrayOfDoublesVariant = Variant<double[], false>; using AdoptedArrayOfDoublesVariant = Variant<double[], true>; using ArrayOfUTF8StringsVariant = Variant<nsCString[], false>;
} // namespace mozilla::storage
#include"Variant_inl.h"
#endif// mozilla_storage_Variant_h__
¤ Dauer der Verarbeitung: 0.34 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.