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