2014-06-30 08:39:45 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsID_h__
|
|
|
|
#define nsID_h__
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
|
2008-01-11 20:30:42 -08:00
|
|
|
#define NSID_LENGTH 39
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* A "unique identifier". This is modeled after OSF DCE UUIDs.
|
|
|
|
*/
|
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
struct nsID
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* @name Identifier values
|
|
|
|
*/
|
|
|
|
|
|
|
|
//@{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t m0;
|
|
|
|
uint16_t m1;
|
|
|
|
uint16_t m2;
|
|
|
|
uint8_t m3[8];
|
2007-03-22 10:30:00 -07:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
* Equivalency method. Compares this nsID with another.
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return <b>true</b> if they are the same, <b>false</b> if not.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
inline bool Equals(const nsID& aOther) const
|
|
|
|
{
|
2011-10-16 12:28:36 -07:00
|
|
|
// Unfortunately memcmp isn't faster than this.
|
2008-01-15 08:46:15 -08:00
|
|
|
return
|
2014-06-26 18:35:39 -07:00
|
|
|
(((uint32_t*)&m0)[0] == ((uint32_t*)&aOther.m0)[0]) &&
|
|
|
|
(((uint32_t*)&m0)[1] == ((uint32_t*)&aOther.m0)[1]) &&
|
|
|
|
(((uint32_t*)&m0)[2] == ((uint32_t*)&aOther.m0)[2]) &&
|
|
|
|
(((uint32_t*)&m0)[3] == ((uint32_t*)&aOther.m0)[3]);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
|
|
|
* string into an nsID
|
|
|
|
*/
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_COM_GLUE bool Parse(const char* aIDStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-07 11:49:18 -08:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2014-06-26 18:35:39 -07:00
|
|
|
* nsID string encoder. Returns an allocated string in
|
2007-03-22 10:30:00 -07:00
|
|
|
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
|
2008-01-11 20:30:42 -08:00
|
|
|
* YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
NS_COM_GLUE char* ToString() const;
|
2008-01-11 20:30:42 -08:00
|
|
|
|
|
|
|
/**
|
2014-06-26 18:35:39 -07:00
|
|
|
* nsID string encoder. Builds a string in
|
2008-01-11 20:30:42 -08:00
|
|
|
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
|
|
|
|
* buffer provided by the caller (for instance, on the stack).
|
|
|
|
*/
|
2014-06-26 18:35:39 -07:00
|
|
|
NS_COM_GLUE void ToProvidedString(char (&aDest)[NSID_LENGTH]) const;
|
2008-02-07 11:49:18 -08:00
|
|
|
|
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class IDs
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef nsID nsCID;
|
|
|
|
|
|
|
|
// Define an CID
|
|
|
|
#define NS_DEFINE_CID(_name, _cidspec) \
|
|
|
|
const nsCID _name = _cidspec
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#define NS_DEFINE_NAMED_CID(_name) \
|
|
|
|
static nsCID k##_name = _name
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define REFNSCID const nsCID&
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An "interface id" which can be used to uniquely identify a given
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef nsID nsIID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A macro shorthand for <tt>const nsIID&<tt>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define REFNSIID const nsIID&
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define an IID
|
|
|
|
* obsolete - do not use this macro
|
|
|
|
*/
|
2014-06-26 18:35:39 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define NS_DEFINE_IID(_name, _iidspec) \
|
|
|
|
const nsIID _name = _iidspec
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A macro to build the static const IID accessor method. The Dummy
|
|
|
|
* template parameter only exists so that the kIID symbol will be linked
|
|
|
|
* properly (weak symbol on linux, gnu_linkonce on mac, multiple-definitions
|
2014-05-11 02:47:11 -07:00
|
|
|
* merged on windows). Dummy should always be instantiated as "void".
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
|
2014-05-11 02:47:11 -07:00
|
|
|
template<typename T, typename U> \
|
|
|
|
struct COMTypeInfo;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \
|
2014-06-26 18:35:39 -07:00
|
|
|
template<typename T> \
|
2014-05-11 02:47:11 -07:00
|
|
|
struct the_interface::COMTypeInfo<the_interface, T> { \
|
|
|
|
static const nsIID kIID NS_HIDDEN; \
|
|
|
|
}; \
|
2014-06-26 18:35:39 -07:00
|
|
|
template<typename T> \
|
2014-05-11 02:47:11 -07:00
|
|
|
const nsIID the_interface::COMTypeInfo<the_interface, T>::kIID NS_HIDDEN = the_iid;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A macro to build the static const CID accessor method
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
|
|
|
|
static const nsID& GetCID() {static const nsID cid = the_cid; return cid;}
|
|
|
|
|
2014-05-11 02:47:11 -07:00
|
|
|
#define NS_GET_IID(T) (T::COMTypeInfo<T, void>::kIID)
|
|
|
|
#define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<T, void>::kIID)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif
|