2014-06-30 19:39:45 +04: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 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
|
|
|
#include "nscore.h"
|
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.
|
|
|
|
*/
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
struct nsID
|
|
|
|
{
|
1998-10-19 21:48:55 +04:00
|
|
|
/**
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
//@{
|
2015-07-31 23:50:08 +03:00
|
|
|
/**
|
|
|
|
* Ensures everything is zeroed out.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
inline bool Equals(const nsID& aOther) 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
|
2014-06-27 05:35:39 +04: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]);
|
1998-10-19 21:48:55 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
inline bool operator==(const nsID& aOther) const
|
|
|
|
{
|
|
|
|
return Equals(aOther);
|
|
|
|
}
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/**
|
|
|
|
* nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
|
|
|
* string into an nsID
|
|
|
|
*/
|
2014-08-28 02:47:27 +04:00
|
|
|
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
|
|
|
/**
|
2014-06-27 05:35:39 +04:00
|
|
|
* nsID string encoder. Returns an allocated string in
|
1998-10-19 21:48:55 +04:00
|
|
|
* {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
|
|
|
*/
|
2014-08-28 02:47:27 +04:00
|
|
|
char* ToString() const;
|
2008-01-12 07:30:42 +03:00
|
|
|
|
|
|
|
/**
|
2014-06-27 05:35:39 +04:00
|
|
|
* nsID string encoder. Builds a string in
|
2008-01-12 07:30:42 +03:00
|
|
|
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format, into a char[NSID_LENGTH]
|
|
|
|
* buffer provided by the caller (for instance, on the stack).
|
|
|
|
*/
|
2014-08-28 02:47:27 +04:00
|
|
|
void ToProvidedString(char (&aDest)[NSID_LENGTH]) const;
|
2008-02-07 22:49:18 +03:00
|
|
|
|
|
|
|
#endif // XPCOM_GLUE_AVOID_NSPR
|
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
//@}
|
|
|
|
};
|
|
|
|
|
2015-10-08 20:11:04 +03:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
|
|
|
/**
|
|
|
|
* A stack helper class to convert a nsID to a string. Useful
|
|
|
|
* for printing nsIDs. For example:
|
|
|
|
* nsID aID = ...;
|
|
|
|
* printf("%s", nsIDToCString(aID).get());
|
|
|
|
*/
|
|
|
|
class nsIDToCString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit nsIDToCString(const nsID& aID)
|
|
|
|
{
|
|
|
|
aID.ToProvidedString(mStringBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *get() const
|
|
|
|
{
|
|
|
|
return mStringBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
char mStringBytes[NSID_LENGTH];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
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) \
|
2016-03-11 06:32:39 +03:00
|
|
|
static const nsCID k##_name = _name
|
2010-06-10 22:11:11 +04:00
|
|
|
|
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
|
|
|
|
*/
|
2014-06-27 05:35:39 +04:00
|
|
|
|
2005-08-09 04:20:25 +04:00
|
|
|
#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
|
2014-05-11 13:47:11 +04:00
|
|
|
* merged on windows). Dummy should always be instantiated as "void".
|
2005-08-09 04:20:25 +04:00
|
|
|
*/
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
#define NS_DECLARE_STATIC_IID_ACCESSOR(the_iid) \
|
2014-05-11 13:47:11 +04:00
|
|
|
template<typename T, typename U> \
|
|
|
|
struct COMTypeInfo;
|
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) \
|
2014-06-27 05:35:39 +04:00
|
|
|
template<typename T> \
|
2014-05-11 13:47:11 +04:00
|
|
|
struct the_interface::COMTypeInfo<the_interface, T> { \
|
|
|
|
static const nsIID kIID NS_HIDDEN; \
|
|
|
|
}; \
|
2014-06-27 05:35:39 +04:00
|
|
|
template<typename T> \
|
2014-05-11 13:47:11 +04:00
|
|
|
const nsIID the_interface::COMTypeInfo<the_interface, T>::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;}
|
|
|
|
|
2014-05-11 13:47:11 +04: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 21:48:55 +04:00
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
#endif
|