1998-10-19 17:48:55 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1998-10-19 17:48:55 +00:00
|
|
|
|
|
|
|
#ifndef nsID_h__
|
|
|
|
#define nsID_h__
|
|
|
|
|
1999-09-06 21:22:36 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-08-09 00:20:25 +00:00
|
|
|
#include "nscore.h"
|
1998-10-19 17:48:55 +00:00
|
|
|
|
2008-01-12 04:30:42 +00:00
|
|
|
#define NSID_LENGTH 39
|
|
|
|
|
1998-10-19 17:48:55 +00:00
|
|
|
/**
|
|
|
|
* A "unique identifier". This is modeled after OSF DCE UUIDs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct nsID {
|
|
|
|
/**
|
2006-08-28 20:17:01 +00:00
|
|
|
* @name Identifier values
|
1998-10-19 17:48:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
//@{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t m0;
|
|
|
|
uint16_t m1;
|
|
|
|
uint16_t m2;
|
|
|
|
uint8_t m3[8];
|
1998-10-19 17:48:55 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
* Equivalency method. Compares this nsID with another.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @return <b>true</b> if they are the same, <b>false</b> if not.
|
1998-10-19 17:48:55 +00:00
|
|
|
*/
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool Equals(const nsID& other) const {
|
2011-10-16 19:28:36 +00:00
|
|
|
// Unfortunately memcmp isn't faster than this.
|
2008-01-15 16:46:15 +00:00
|
|
|
return
|
2012-08-22 15:56:38 +00:00
|
|
|
((((uint32_t*) &m0)[0] == ((uint32_t*) &other.m0)[0]) &&
|
|
|
|
(((uint32_t*) &m0)[1] == ((uint32_t*) &other.m0)[1]) &&
|
|
|
|
(((uint32_t*) &m0)[2] == ((uint32_t*) &other.m0)[2]) &&
|
|
|
|
(((uint32_t*) &m0)[3] == ((uint32_t*) &other.m0)[3]));
|
1998-10-19 17:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
|
|
|
* string into an nsID
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_COM_GLUE bool Parse(const char *aIDStr);
|
1998-10-19 17:48:55 +00:00
|
|
|
|
2008-02-07 19:49:18 +00:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
1998-10-19 17:48:55 +00:00
|
|
|
/**
|
|
|
|
* nsID string encoder. Returns an allocated string in
|
|
|
|
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
|
2008-01-12 04:30:42 +00:00
|
|
|
* YOU SHOULD ONLY USE THIS IF YOU CANNOT USE ToProvidedString() BELOW.
|
1998-10-19 17:48:55 +00:00
|
|
|
*/
|
2005-08-09 13:39:12 +00:00
|
|
|
NS_COM_GLUE char* ToString() const;
|
2008-01-12 04:30:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* nsID string encoder. Builds a string in
|
|
|
|
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
|
|
|
|
* buffer provided by the caller (for instance, on the stack).
|
|
|
|
*/
|
|
|
|
NS_COM_GLUE void ToProvidedString(char (&dest)[NSID_LENGTH]) const;
|
2008-02-07 19:49:18 +00:00
|
|
|
|
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
1998-10-19 17:48:55 +00:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
/*
|
|
|
|
* Class IDs
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef nsID nsCID;
|
|
|
|
|
|
|
|
// Define an CID
|
|
|
|
#define NS_DEFINE_CID(_name, _cidspec) \
|
|
|
|
const nsCID _name = _cidspec
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#define NS_DEFINE_NAMED_CID(_name) \
|
|
|
|
static nsCID k##_name = _name
|
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
#define REFNSCID const nsCID&
|
|
|
|
|
2005-08-09 00:20:25 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NS_DEFINE_IID(_name, _iidspec) \
|
|
|
|
const nsIID _name = _iidspec
|
|
|
|
|
|
|
|
/**
|
2006-11-14 21:21:37 +00:00
|
|
|
* 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 09:47:11 +00:00
|
|
|
* merged on windows). Dummy should always be instantiated as "void".
|
2005-08-09 00:20:25 +00:00
|
|
|
*/
|
|
|
|
|
2005-11-11 14:36:26 +00:00
|
|
|
#define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
|
2014-05-11 09:47:11 +00:00
|
|
|
template<typename T, typename U> \
|
|
|
|
struct COMTypeInfo;
|
2005-08-09 00:20:25 +00:00
|
|
|
|
2006-11-14 21:21:37 +00:00
|
|
|
#define NS_DEFINE_STATIC_IID_ACCESSOR(the_interface, the_iid) \
|
2014-05-11 09:47:11 +00:00
|
|
|
template <typename T> \
|
|
|
|
struct the_interface::COMTypeInfo<the_interface, T> { \
|
|
|
|
static const nsIID kIID NS_HIDDEN; \
|
|
|
|
}; \
|
|
|
|
template <typename T> \
|
|
|
|
const nsIID the_interface::COMTypeInfo<the_interface, T>::kIID NS_HIDDEN = the_iid;
|
2005-11-11 14:36:26 +00:00
|
|
|
|
2005-08-09 00:20:25 +00: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 09:47:11 +00:00
|
|
|
#define NS_GET_IID(T) (T::COMTypeInfo<T, void>::kIID)
|
|
|
|
#define NS_GET_TEMPLATE_IID(T) (T::template COMTypeInfo<T, void>::kIID)
|
1998-10-19 17:48:55 +00:00
|
|
|
|
2005-11-11 14:36:26 +00:00
|
|
|
#endif
|