Merge mozilla-central to autoland. a=merge CLOSED TREE
[gecko.git] / storage / Variant.cpp
blob61cb5b0676240b32e6aba5672362e40a99509617
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "Variant.h"
9 #include "nsCOMPtr.h"
11 extern "C" {
13 using namespace mozilla::storage;
15 /**
16 * Return the data type of the given variant. This method used to be exposed
17 * to XPCOM, but since bug 1507540 it's marked [notxpcom] in the interface
18 * definition, so we need this C function to access it from Rust.
20 uint16_t NS_GetDataType(nsIVariant* aVariant) {
21 return aVariant->GetDataType();
24 // Convenience functions to create Storage variants from Rust.
25 void NS_NewStorageNullVariant(nsIVariant** aVariant) {
26 nsCOMPtr<nsIVariant> variant = new NullVariant();
27 variant.forget(aVariant);
30 void NS_NewStorageBooleanVariant(bool aValue, nsIVariant** aVariant) {
31 nsCOMPtr<nsIVariant> variant = new BooleanVariant(aValue);
32 variant.forget(aVariant);
35 void NS_NewStorageIntegerVariant(int64_t aValue, nsIVariant** aVariant) {
36 nsCOMPtr<nsIVariant> variant = new IntegerVariant(aValue);
37 variant.forget(aVariant);
40 void NS_NewStorageFloatVariant(double aValue, nsIVariant** aVariant) {
41 nsCOMPtr<nsIVariant> variant = new FloatVariant(aValue);
42 variant.forget(aVariant);
45 void NS_NewStorageTextVariant(const nsAString& aValue, nsIVariant** aVariant) {
46 nsCOMPtr<nsIVariant> variant = new TextVariant(aValue);
47 variant.forget(aVariant);
50 void NS_NewStorageUTF8TextVariant(const nsACString& aValue,
51 nsIVariant** aVariant) {
52 nsCOMPtr<nsIVariant> variant = new UTF8TextVariant(aValue);
53 variant.forget(aVariant);
56 } // extern "C"