зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1046841 - Convert remaining files in xpcom/{ds,glue,sample}/ to Gecko style. r=froydnj
This commit is contained in:
Родитель
16471161bb
Коммит
e3a6a8dc06
|
@ -36,131 +36,132 @@ class nsTCharSeparatedTokenizer
|
|||
typedef typename DependentSubstringType::substring_type SubstringType;
|
||||
|
||||
public:
|
||||
// Flags -- only one for now. If we need more, they should be defined to
|
||||
// be 1 << 1, 1 << 2, etc. (They're masks, and aFlags is a bitfield.)
|
||||
enum {
|
||||
SEPARATOR_OPTIONAL = 1
|
||||
};
|
||||
// Flags -- only one for now. If we need more, they should be defined to
|
||||
// be 1 << 1, 1 << 2, etc. (They're masks, and aFlags is a bitfield.)
|
||||
enum
|
||||
{
|
||||
SEPARATOR_OPTIONAL = 1
|
||||
};
|
||||
|
||||
nsTCharSeparatedTokenizer(const SubstringType& aSource,
|
||||
CharType aSeparatorChar,
|
||||
uint32_t aFlags = 0)
|
||||
: mIter(aSource.Data(), aSource.Length()),
|
||||
mEnd(aSource.Data() + aSource.Length(), aSource.Data(),
|
||||
aSource.Length()),
|
||||
mSeparatorChar(aSeparatorChar),
|
||||
mWhitespaceBeforeFirstToken(false),
|
||||
mWhitespaceAfterCurrentToken(false),
|
||||
mSeparatorAfterCurrentToken(false),
|
||||
mSeparatorOptional(aFlags & SEPARATOR_OPTIONAL)
|
||||
{
|
||||
// Skip initial whitespace
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceBeforeFirstToken = true;
|
||||
++mIter;
|
||||
}
|
||||
nsTCharSeparatedTokenizer(const SubstringType& aSource,
|
||||
CharType aSeparatorChar,
|
||||
uint32_t aFlags = 0)
|
||||
: mIter(aSource.Data(), aSource.Length())
|
||||
, mEnd(aSource.Data() + aSource.Length(), aSource.Data(),
|
||||
aSource.Length())
|
||||
, mSeparatorChar(aSeparatorChar)
|
||||
, mWhitespaceBeforeFirstToken(false)
|
||||
, mWhitespaceAfterCurrentToken(false)
|
||||
, mSeparatorAfterCurrentToken(false)
|
||||
, mSeparatorOptional(aFlags & SEPARATOR_OPTIONAL)
|
||||
{
|
||||
// Skip initial whitespace
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceBeforeFirstToken = true;
|
||||
++mIter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any more tokens are available.
|
||||
*/
|
||||
bool hasMoreTokens() const
|
||||
{
|
||||
MOZ_ASSERT(mIter == mEnd || !IsWhitespace(*mIter),
|
||||
"Should be at beginning of token if there is one");
|
||||
|
||||
return mIter < mEnd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is whitespace prior to the first token.
|
||||
*/
|
||||
bool whitespaceBeforeFirstToken() const
|
||||
{
|
||||
return mWhitespaceBeforeFirstToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is a separator after the current token.
|
||||
* Useful if you want to check whether the last token has a separator
|
||||
* after it which may not be valid.
|
||||
*/
|
||||
bool separatorAfterCurrentToken() const
|
||||
{
|
||||
return mSeparatorAfterCurrentToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is any whitespace after the current token.
|
||||
*/
|
||||
bool whitespaceAfterCurrentToken() const
|
||||
{
|
||||
return mWhitespaceAfterCurrentToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next token.
|
||||
*/
|
||||
const DependentSubstringType nextToken()
|
||||
{
|
||||
mozilla::RangedPtr<const CharType> tokenStart = mIter;
|
||||
mozilla::RangedPtr<const CharType> tokenEnd = mIter;
|
||||
|
||||
MOZ_ASSERT(mIter == mEnd || !IsWhitespace(*mIter),
|
||||
"Should be at beginning of token if there is one");
|
||||
|
||||
// Search until we hit separator or end (or whitespace, if a separator
|
||||
// isn't required -- see clause with 'break' below).
|
||||
while (mIter < mEnd && *mIter != mSeparatorChar) {
|
||||
// Skip to end of the current word.
|
||||
while (mIter < mEnd &&
|
||||
!IsWhitespace(*mIter) && *mIter != mSeparatorChar) {
|
||||
++mIter;
|
||||
}
|
||||
tokenEnd = mIter;
|
||||
|
||||
// Skip whitespace after the current word.
|
||||
mWhitespaceAfterCurrentToken = false;
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceAfterCurrentToken = true;
|
||||
++mIter;
|
||||
}
|
||||
if (mSeparatorOptional) {
|
||||
// We've hit (and skipped) whitespace, and that's sufficient to end
|
||||
// our token, regardless of whether we've reached a SeparatorChar.
|
||||
break;
|
||||
} // (else, we'll keep looping until we hit mEnd or SeparatorChar)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any more tokens are available.
|
||||
*/
|
||||
bool hasMoreTokens() const
|
||||
{
|
||||
MOZ_ASSERT(mIter == mEnd || !IsWhitespace(*mIter),
|
||||
"Should be at beginning of token if there is one");
|
||||
mSeparatorAfterCurrentToken = (mIter != mEnd &&
|
||||
*mIter == mSeparatorChar);
|
||||
MOZ_ASSERT(mSeparatorOptional ||
|
||||
(mSeparatorAfterCurrentToken == (mIter < mEnd)),
|
||||
"If we require a separator and haven't hit the end of "
|
||||
"our string, then we shouldn't have left the loop "
|
||||
"unless we hit a separator");
|
||||
|
||||
return mIter < mEnd;
|
||||
// Skip separator (and any whitespace after it), if we're at one.
|
||||
if (mSeparatorAfterCurrentToken) {
|
||||
++mIter;
|
||||
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceAfterCurrentToken = true;
|
||||
++mIter;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is whitespace prior to the first token.
|
||||
*/
|
||||
bool whitespaceBeforeFirstToken() const
|
||||
{
|
||||
return mWhitespaceBeforeFirstToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is a separator after the current token.
|
||||
* Useful if you want to check whether the last token has a separator
|
||||
* after it which may not be valid.
|
||||
*/
|
||||
bool separatorAfterCurrentToken() const
|
||||
{
|
||||
return mSeparatorAfterCurrentToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is any whitespace after the current token.
|
||||
*/
|
||||
bool whitespaceAfterCurrentToken() const
|
||||
{
|
||||
return mWhitespaceAfterCurrentToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next token.
|
||||
*/
|
||||
const DependentSubstringType nextToken()
|
||||
{
|
||||
mozilla::RangedPtr<const CharType> tokenStart = mIter;
|
||||
mozilla::RangedPtr<const CharType> tokenEnd = mIter;
|
||||
|
||||
MOZ_ASSERT(mIter == mEnd || !IsWhitespace(*mIter),
|
||||
"Should be at beginning of token if there is one");
|
||||
|
||||
// Search until we hit separator or end (or whitespace, if a separator
|
||||
// isn't required -- see clause with 'break' below).
|
||||
while (mIter < mEnd && *mIter != mSeparatorChar) {
|
||||
// Skip to end of the current word.
|
||||
while (mIter < mEnd &&
|
||||
!IsWhitespace(*mIter) && *mIter != mSeparatorChar) {
|
||||
++mIter;
|
||||
}
|
||||
tokenEnd = mIter;
|
||||
|
||||
// Skip whitespace after the current word.
|
||||
mWhitespaceAfterCurrentToken = false;
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceAfterCurrentToken = true;
|
||||
++mIter;
|
||||
}
|
||||
if (mSeparatorOptional) {
|
||||
// We've hit (and skipped) whitespace, and that's sufficient to end
|
||||
// our token, regardless of whether we've reached a SeparatorChar.
|
||||
break;
|
||||
} // (else, we'll keep looping until we hit mEnd or SeparatorChar)
|
||||
}
|
||||
|
||||
mSeparatorAfterCurrentToken = (mIter != mEnd &&
|
||||
*mIter == mSeparatorChar);
|
||||
MOZ_ASSERT(mSeparatorOptional ||
|
||||
(mSeparatorAfterCurrentToken == (mIter < mEnd)),
|
||||
"If we require a separator and haven't hit the end of "
|
||||
"our string, then we shouldn't have left the loop "
|
||||
"unless we hit a separator");
|
||||
|
||||
// Skip separator (and any whitespace after it), if we're at one.
|
||||
if (mSeparatorAfterCurrentToken) {
|
||||
++mIter;
|
||||
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceAfterCurrentToken = true;
|
||||
++mIter;
|
||||
}
|
||||
}
|
||||
|
||||
return Substring(tokenStart.get(), tokenEnd.get());
|
||||
}
|
||||
return Substring(tokenStart.get(), tokenEnd.get());
|
||||
}
|
||||
|
||||
private:
|
||||
mozilla::RangedPtr<const CharType> mIter;
|
||||
const mozilla::RangedPtr<const CharType> mEnd;
|
||||
CharType mSeparatorChar;
|
||||
bool mWhitespaceBeforeFirstToken;
|
||||
bool mWhitespaceAfterCurrentToken;
|
||||
bool mSeparatorAfterCurrentToken;
|
||||
bool mSeparatorOptional;
|
||||
mozilla::RangedPtr<const CharType> mIter;
|
||||
const mozilla::RangedPtr<const CharType> mEnd;
|
||||
CharType mSeparatorChar;
|
||||
bool mWhitespaceBeforeFirstToken;
|
||||
bool mWhitespaceAfterCurrentToken;
|
||||
bool mSeparatorAfterCurrentToken;
|
||||
bool mSeparatorOptional;
|
||||
};
|
||||
|
||||
template<bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace>
|
||||
|
|
|
@ -17,67 +17,67 @@ class nsTWhitespaceTokenizer
|
|||
typedef typename DependentSubstringType::substring_type SubstringType;
|
||||
|
||||
public:
|
||||
explicit nsTWhitespaceTokenizer(const SubstringType& aSource)
|
||||
: mIter(aSource.Data(), aSource.Length()),
|
||||
mEnd(aSource.Data() + aSource.Length(), aSource.Data(),
|
||||
aSource.Length()),
|
||||
mWhitespaceBeforeFirstToken(false),
|
||||
mWhitespaceAfterCurrentToken(false)
|
||||
{
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceBeforeFirstToken = true;
|
||||
++mIter;
|
||||
}
|
||||
explicit nsTWhitespaceTokenizer(const SubstringType& aSource)
|
||||
: mIter(aSource.Data(), aSource.Length())
|
||||
, mEnd(aSource.Data() + aSource.Length(), aSource.Data(),
|
||||
aSource.Length())
|
||||
, mWhitespaceBeforeFirstToken(false)
|
||||
, mWhitespaceAfterCurrentToken(false)
|
||||
{
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceBeforeFirstToken = true;
|
||||
++mIter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any more tokens are available.
|
||||
*/
|
||||
bool hasMoreTokens() const
|
||||
{
|
||||
return mIter < mEnd;
|
||||
}
|
||||
/**
|
||||
* Checks if any more tokens are available.
|
||||
*/
|
||||
bool hasMoreTokens() const
|
||||
{
|
||||
return mIter < mEnd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is whitespace prior to the first token.
|
||||
*/
|
||||
bool whitespaceBeforeFirstToken() const
|
||||
{
|
||||
return mWhitespaceBeforeFirstToken;
|
||||
}
|
||||
/*
|
||||
* Returns true if there is whitespace prior to the first token.
|
||||
*/
|
||||
bool whitespaceBeforeFirstToken() const
|
||||
{
|
||||
return mWhitespaceBeforeFirstToken;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if there is any whitespace after the current token.
|
||||
* This is always true unless we're reading the last token.
|
||||
*/
|
||||
bool whitespaceAfterCurrentToken() const
|
||||
{
|
||||
return mWhitespaceAfterCurrentToken;
|
||||
}
|
||||
/*
|
||||
* Returns true if there is any whitespace after the current token.
|
||||
* This is always true unless we're reading the last token.
|
||||
*/
|
||||
bool whitespaceAfterCurrentToken() const
|
||||
{
|
||||
return mWhitespaceAfterCurrentToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next token.
|
||||
*/
|
||||
const DependentSubstringType nextToken()
|
||||
{
|
||||
const mozilla::RangedPtr<const CharType> tokenStart = mIter;
|
||||
while (mIter < mEnd && !IsWhitespace(*mIter)) {
|
||||
++mIter;
|
||||
}
|
||||
const mozilla::RangedPtr<const CharType> tokenEnd = mIter;
|
||||
mWhitespaceAfterCurrentToken = false;
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceAfterCurrentToken = true;
|
||||
++mIter;
|
||||
}
|
||||
return Substring(tokenStart.get(), tokenEnd.get());
|
||||
/**
|
||||
* Returns the next token.
|
||||
*/
|
||||
const DependentSubstringType nextToken()
|
||||
{
|
||||
const mozilla::RangedPtr<const CharType> tokenStart = mIter;
|
||||
while (mIter < mEnd && !IsWhitespace(*mIter)) {
|
||||
++mIter;
|
||||
}
|
||||
const mozilla::RangedPtr<const CharType> tokenEnd = mIter;
|
||||
mWhitespaceAfterCurrentToken = false;
|
||||
while (mIter < mEnd && IsWhitespace(*mIter)) {
|
||||
mWhitespaceAfterCurrentToken = true;
|
||||
++mIter;
|
||||
}
|
||||
return Substring(tokenStart.get(), tokenEnd.get());
|
||||
}
|
||||
|
||||
private:
|
||||
mozilla::RangedPtr<const CharType> mIter;
|
||||
const mozilla::RangedPtr<const CharType> mEnd;
|
||||
bool mWhitespaceBeforeFirstToken;
|
||||
bool mWhitespaceAfterCurrentToken;
|
||||
mozilla::RangedPtr<const CharType> mIter;
|
||||
const mozilla::RangedPtr<const CharType> mEnd;
|
||||
bool mWhitespaceBeforeFirstToken;
|
||||
bool mWhitespaceAfterCurrentToken;
|
||||
};
|
||||
|
||||
template<bool IsWhitespace(char16_t) = NS_IsAsciiWhitespace>
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -24,7 +24,7 @@ extern "C" NS_HIDDEN_(void) XPCOMGlueEnablePreload();
|
|||
* Initialize the XPCOM glue by dynamically linking against the XPCOM
|
||||
* shared library indicated by xpcomFile.
|
||||
*/
|
||||
extern "C" NS_HIDDEN_(nsresult) XPCOMGlueStartup(const char* xpcomFile);
|
||||
extern "C" NS_HIDDEN_(nsresult) XPCOMGlueStartup(const char* aXPCOMFile);
|
||||
|
||||
typedef void (*NSFuncPtr)();
|
||||
|
||||
|
@ -43,7 +43,7 @@ struct nsDynamicFunctionLoad
|
|||
* functions were found.
|
||||
*/
|
||||
extern "C" NS_HIDDEN_(nsresult)
|
||||
XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad* symbols);
|
||||
XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad* aSymbols);
|
||||
|
||||
#endif // XPCOM_GLUE
|
||||
#endif // nsXPCOMGlue_h__
|
||||
|
|
|
@ -21,20 +21,21 @@
|
|||
|
||||
nsSampleImpl::nsSampleImpl() : mValue(nullptr)
|
||||
{
|
||||
mValue = (char*)nsMemory::Clone("initial value", 14);
|
||||
mValue = (char*)nsMemory::Clone("initial value", 14);
|
||||
}
|
||||
|
||||
nsSampleImpl::~nsSampleImpl()
|
||||
{
|
||||
if (mValue)
|
||||
nsMemory::Free(mValue);
|
||||
if (mValue) {
|
||||
nsMemory::Free(mValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NS_IMPL_ISUPPORTS expands to a simple implementation of the nsISupports
|
||||
* interface. This includes a proper implementation of AddRef, Release,
|
||||
* and QueryInterface. If this class supported more interfaces than just
|
||||
* nsISupports,
|
||||
* nsISupports,
|
||||
* you could use NS_IMPL_ADDREF() and NS_IMPL_RELEASE() to take care of the
|
||||
* simple stuff, but you would have to create QueryInterface on your own.
|
||||
* nsSampleFactory.cpp is an example of this approach.
|
||||
|
@ -54,96 +55,101 @@ NS_IMPL_ISUPPORTS_CI(nsSampleImpl, nsISample)
|
|||
NS_IMETHODIMP
|
||||
nsSampleImpl::GetValue(char** aValue)
|
||||
{
|
||||
NS_PRECONDITION(aValue != nullptr, "null ptr");
|
||||
if (! aValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aValue != nullptr, "null ptr");
|
||||
if (!aValue) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (mValue) {
|
||||
/**
|
||||
* GetValue's job is to return data known by an instance of
|
||||
* nsSampleImpl to the outside world. If we were to simply return
|
||||
* a pointer to data owned by this instance, and the client were to
|
||||
* free it, bad things would surely follow.
|
||||
* On the other hand, if we create a new copy of the data for our
|
||||
* client, and it turns out that client is implemented in JavaScript,
|
||||
* there would be no way to free the buffer. The solution to the
|
||||
* buffer ownership problem is the nsMemory singleton. Any buffer
|
||||
* returned by an XPCOM method should be allocated by the nsMemory.
|
||||
* This convention lets things like JavaScript reflection do their
|
||||
* job, and simplifies the way C++ clients deal with returned buffers.
|
||||
*/
|
||||
*aValue = (char*) nsMemory::Clone(mValue, strlen(mValue) + 1);
|
||||
if (! *aValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mValue) {
|
||||
/**
|
||||
* GetValue's job is to return data known by an instance of
|
||||
* nsSampleImpl to the outside world. If we were to simply return
|
||||
* a pointer to data owned by this instance, and the client were to
|
||||
* free it, bad things would surely follow.
|
||||
* On the other hand, if we create a new copy of the data for our
|
||||
* client, and it turns out that client is implemented in JavaScript,
|
||||
* there would be no way to free the buffer. The solution to the
|
||||
* buffer ownership problem is the nsMemory singleton. Any buffer
|
||||
* returned by an XPCOM method should be allocated by the nsMemory.
|
||||
* This convention lets things like JavaScript reflection do their
|
||||
* job, and simplifies the way C++ clients deal with returned buffers.
|
||||
*/
|
||||
*aValue = (char*)nsMemory::Clone(mValue, strlen(mValue) + 1);
|
||||
if (!*aValue) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
else {
|
||||
*aValue = nullptr;
|
||||
}
|
||||
return NS_OK;
|
||||
} else {
|
||||
*aValue = nullptr;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSampleImpl::SetValue(const char* aValue)
|
||||
{
|
||||
NS_PRECONDITION(aValue != nullptr, "null ptr");
|
||||
if (! aValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aValue != nullptr, "null ptr");
|
||||
if (!aValue) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (mValue) {
|
||||
nsMemory::Free(mValue);
|
||||
}
|
||||
if (mValue) {
|
||||
nsMemory::Free(mValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Another buffer passing convention is that buffers passed INTO your
|
||||
* object ARE NOT YOURS. Keep your hands off them, unless they are
|
||||
* declared "inout". If you want to keep the value for posterity,
|
||||
* you will have to make a copy of it.
|
||||
*/
|
||||
mValue = (char*) nsMemory::Clone(aValue, strlen(aValue) + 1);
|
||||
return NS_OK;
|
||||
/**
|
||||
* Another buffer passing convention is that buffers passed INTO your
|
||||
* object ARE NOT YOURS. Keep your hands off them, unless they are
|
||||
* declared "inout". If you want to keep the value for posterity,
|
||||
* you will have to make a copy of it.
|
||||
*/
|
||||
mValue = (char*)nsMemory::Clone(aValue, strlen(aValue) + 1);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSampleImpl::Poke(const char* aValue)
|
||||
{
|
||||
return SetValue((char*) aValue);
|
||||
return SetValue((char*)aValue);
|
||||
}
|
||||
|
||||
|
||||
static void GetStringValue(nsACString& aValue)
|
||||
static void
|
||||
GetStringValue(nsACString& aValue)
|
||||
{
|
||||
NS_CStringSetData(aValue, "GetValue");
|
||||
NS_CStringSetData(aValue, "GetValue");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSampleImpl::WriteValue(const char* aPrefix)
|
||||
{
|
||||
NS_PRECONDITION(aPrefix != nullptr, "null ptr");
|
||||
if (! aPrefix)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_PRECONDITION(aPrefix != nullptr, "null ptr");
|
||||
if (!aPrefix) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
printf("%s %s\n", aPrefix, mValue);
|
||||
printf("%s %s\n", aPrefix, mValue);
|
||||
|
||||
// This next part illustrates the nsEmbedString:
|
||||
nsEmbedString foopy;
|
||||
foopy.Append(char16_t('f'));
|
||||
foopy.Append(char16_t('o'));
|
||||
foopy.Append(char16_t('o'));
|
||||
foopy.Append(char16_t('p'));
|
||||
foopy.Append(char16_t('y'));
|
||||
|
||||
const char16_t* f = foopy.get();
|
||||
uint32_t l = foopy.Length();
|
||||
printf("%c%c%c%c%c %d\n", char(f[0]), char(f[1]), char(f[2]), char(f[3]), char(f[4]), l);
|
||||
|
||||
nsEmbedCString foopy2;
|
||||
GetStringValue(foopy2);
|
||||
// This next part illustrates the nsEmbedString:
|
||||
nsEmbedString foopy;
|
||||
foopy.Append(char16_t('f'));
|
||||
foopy.Append(char16_t('o'));
|
||||
foopy.Append(char16_t('o'));
|
||||
foopy.Append(char16_t('p'));
|
||||
foopy.Append(char16_t('y'));
|
||||
|
||||
//foopy2.AppendLiteral("foopy");
|
||||
const char* f2 = foopy2.get();
|
||||
uint32_t l2 = foopy2.Length();
|
||||
const char16_t* f = foopy.get();
|
||||
uint32_t l = foopy.Length();
|
||||
printf("%c%c%c%c%c %d\n",
|
||||
char(f[0]), char(f[1]), char(f[2]), char(f[3]), char(f[4]), l);
|
||||
|
||||
printf("%s %d\n", f2, l2);
|
||||
nsEmbedCString foopy2;
|
||||
GetStringValue(foopy2);
|
||||
|
||||
return NS_OK;
|
||||
//foopy2.AppendLiteral("foopy");
|
||||
const char* f2 = foopy2.get();
|
||||
uint32_t l2 = foopy2.Length();
|
||||
|
||||
printf("%s %d\n", f2, l2);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -35,69 +35,69 @@
|
|||
class nsSampleImpl MOZ_FINAL : public nsISample
|
||||
{
|
||||
public:
|
||||
nsSampleImpl();
|
||||
nsSampleImpl();
|
||||
|
||||
/**
|
||||
* This macro expands into a declaration of the nsISupports interface.
|
||||
* Every XPCOM component needs to implement nsISupports, as it acts
|
||||
* as the gateway to other interfaces this component implements. You
|
||||
* could manually declare QueryInterface, AddRef, and Release instead
|
||||
* of using this macro, but why?
|
||||
*/
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
/**
|
||||
* This macro expands into a declaration of the nsISupports interface.
|
||||
* Every XPCOM component needs to implement nsISupports, as it acts
|
||||
* as the gateway to other interfaces this component implements. You
|
||||
* could manually declare QueryInterface, AddRef, and Release instead
|
||||
* of using this macro, but why?
|
||||
*/
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
* This macro is defined in the nsISample.h file, and is generated
|
||||
* automatically by the xpidl compiler. It expands to
|
||||
* declarations of all of the methods required to implement the
|
||||
* interface. xpidl will generate a NS_DECL_[INTERFACENAME] macro
|
||||
* for each interface that it processes.
|
||||
*
|
||||
* The methods of nsISample are discussed individually below, but
|
||||
* commented out (because this macro already defines them.)
|
||||
*/
|
||||
NS_DECL_NSISAMPLE
|
||||
/**
|
||||
* This macro is defined in the nsISample.h file, and is generated
|
||||
* automatically by the xpidl compiler. It expands to
|
||||
* declarations of all of the methods required to implement the
|
||||
* interface. xpidl will generate a NS_DECL_[INTERFACENAME] macro
|
||||
* for each interface that it processes.
|
||||
*
|
||||
* The methods of nsISample are discussed individually below, but
|
||||
* commented out (because this macro already defines them.)
|
||||
*/
|
||||
NS_DECL_NSISAMPLE
|
||||
|
||||
/**
|
||||
* The following is an explanation of how the interface header
|
||||
* file expands to for a c++ implementation. NS_DELC_NSISAMPLE
|
||||
* takes care of defining the right c++ implementation.
|
||||
*
|
||||
* The following if provided for more understanding.
|
||||
*
|
||||
* NS_IMETHOD expands to the standard XPCOM return type. XPCOM methods
|
||||
* should never return any other type. The return value is used
|
||||
* behind the scenes by the XPConnect runtime to figure out if the call
|
||||
* failed in any way.
|
||||
* These methods were generated by "attribute string Value" in
|
||||
* nsISample.idl. When reflected into JavaScript, XPCOM will use these
|
||||
* calls as Getter/Setter ops, so that they can be called transparently
|
||||
* as "sample.Value='foo';" and "var val = sample.Value"
|
||||
*/
|
||||
/* NS_IMETHOD GetValue(char * *aValue); */
|
||||
/* NS_IMETHOD SetValue(char * aValue); */
|
||||
/**
|
||||
* The following is an explanation of how the interface header
|
||||
* file expands to for a c++ implementation. NS_DELC_NSISAMPLE
|
||||
* takes care of defining the right c++ implementation.
|
||||
*
|
||||
* The following if provided for more understanding.
|
||||
*
|
||||
* NS_IMETHOD expands to the standard XPCOM return type. XPCOM methods
|
||||
* should never return any other type. The return value is used
|
||||
* behind the scenes by the XPConnect runtime to figure out if the call
|
||||
* failed in any way.
|
||||
* These methods were generated by "attribute string Value" in
|
||||
* nsISample.idl. When reflected into JavaScript, XPCOM will use these
|
||||
* calls as Getter/Setter ops, so that they can be called transparently
|
||||
* as "sample.Value='foo';" and "var val = sample.Value"
|
||||
*/
|
||||
/* NS_IMETHOD GetValue(char** aValue); */
|
||||
/* NS_IMETHOD SetValue(char* aValue); */
|
||||
|
||||
/**
|
||||
* The const came from the "in" specifier in nsISample.idl. "in"
|
||||
* specifies that the value of this parameter is used only for input,
|
||||
* this method is not allowed to modify the contents of the buffer.
|
||||
*/
|
||||
/* NS_IMETHOD WriteValue(const char *aPrefix); */
|
||||
/**
|
||||
* The const came from the "in" specifier in nsISample.idl. "in"
|
||||
* specifies that the value of this parameter is used only for input,
|
||||
* this method is not allowed to modify the contents of the buffer.
|
||||
*/
|
||||
/* NS_IMETHOD WriteValue(const char* aPrefix); */
|
||||
|
||||
/**
|
||||
* nsISample.idl specifies all of its string types as string, instead
|
||||
* of wstring (wide string), the Unicode type. If the world were a
|
||||
* perfect place, all normal strings in XPCOM interfaces would be unicode.
|
||||
* If this type had been specified as wstring, it would appear as
|
||||
* char16_t * in C++, which is the NSPR type for unicode characters.
|
||||
*/
|
||||
/* NS_IMETHOD Poke(const char* aValue); */
|
||||
/**
|
||||
* nsISample.idl specifies all of its string types as string, instead
|
||||
* of wstring (wide string), the Unicode type. If the world were a
|
||||
* perfect place, all normal strings in XPCOM interfaces would be unicode.
|
||||
* If this type had been specified as wstring, it would appear as
|
||||
* char16_t * in C++, which is the NSPR type for unicode characters.
|
||||
*/
|
||||
/* NS_IMETHOD Poke(const char* aValue); */
|
||||
|
||||
private:
|
||||
~nsSampleImpl();
|
||||
~nsSampleImpl();
|
||||
|
||||
char* mValue;
|
||||
char* mValue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,8 +35,8 @@ NS_DEFINE_NAMED_CID(NS_SAMPLE_CID);
|
|||
// each entry has the form { CID, service, factoryproc, constructorproc }
|
||||
// where factoryproc is usually nullptr.
|
||||
static const mozilla::Module::CIDEntry kSampleCIDs[] = {
|
||||
{ &kNS_SAMPLE_CID, false, nullptr, nsSampleImplConstructor },
|
||||
{ nullptr }
|
||||
{ &kNS_SAMPLE_CID, false, nullptr, nsSampleImplConstructor },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
// Build a table which maps contract IDs to CIDs.
|
||||
|
@ -44,8 +44,8 @@ static const mozilla::Module::CIDEntry kSampleCIDs[] = {
|
|||
// cases an extension component may override the contract ID of a builtin gecko component
|
||||
// to modify or extend functionality.
|
||||
static const mozilla::Module::ContractIDEntry kSampleContracts[] = {
|
||||
{ NS_SAMPLE_CONTRACTID, &kNS_SAMPLE_CID },
|
||||
{ nullptr }
|
||||
{ NS_SAMPLE_CONTRACTID, &kNS_SAMPLE_CID },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
// Category entries are category/key/value triples which can be used
|
||||
|
@ -54,15 +54,15 @@ static const mozilla::Module::ContractIDEntry kSampleContracts[] = {
|
|||
// entries: this is just a sample of how you'd do it.
|
||||
// @see nsICategoryManager for information on retrieving category data.
|
||||
static const mozilla::Module::CategoryEntry kSampleCategories[] = {
|
||||
{ "my-category", "my-key", NS_SAMPLE_CONTRACTID },
|
||||
{ nullptr }
|
||||
{ "my-category", "my-key", NS_SAMPLE_CONTRACTID },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module kSampleModule = {
|
||||
mozilla::Module::kVersion,
|
||||
kSampleCIDs,
|
||||
kSampleContracts,
|
||||
kSampleCategories
|
||||
mozilla::Module::kVersion,
|
||||
kSampleCIDs,
|
||||
kSampleContracts,
|
||||
kSampleCategories
|
||||
};
|
||||
|
||||
// The following line implements the one-and-only "NSModule" symbol exported from this
|
||||
|
|
|
@ -22,88 +22,82 @@
|
|||
#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
|
||||
|
||||
int
|
||||
main(void)
|
||||
main()
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv;
|
||||
|
||||
XPCOMGlueStartup(nullptr);
|
||||
XPCOMGlueStartup(nullptr);
|
||||
|
||||
// Initialize XPCOM
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("ERROR: XPCOM intialization error [%x].\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -1;
|
||||
}
|
||||
// Initialize XPCOM
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("ERROR: XPCOM intialization error [%x].\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(servMan);
|
||||
nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(servMan);
|
||||
|
||||
// Create an instance of our component
|
||||
nsCOMPtr<nsISample> mysample;
|
||||
rv = manager->CreateInstanceByContractID(NS_SAMPLE_CONTRACTID,
|
||||
nullptr,
|
||||
NS_GET_IID(nsISample),
|
||||
getter_AddRefs(mysample));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("ERROR: Cannot create instance of component " NS_SAMPLE_CONTRACTID " [%x].\n"
|
||||
"Debugging hint:\n"
|
||||
"\tsetenv NSPR_LOG_MODULES nsComponentManager:5\n"
|
||||
"\tsetenv NSPR_LOG_FILE xpcom.log\n"
|
||||
"\t./nsTestSample\n"
|
||||
"\t<check the contents for xpcom.log for possible cause of error>.\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -2;
|
||||
}
|
||||
// Create an instance of our component
|
||||
nsCOMPtr<nsISample> mysample;
|
||||
rv = manager->CreateInstanceByContractID(NS_SAMPLE_CONTRACTID,
|
||||
nullptr,
|
||||
NS_GET_IID(nsISample),
|
||||
getter_AddRefs(mysample));
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("ERROR: Cannot create instance of component " NS_SAMPLE_CONTRACTID " [%x].\n"
|
||||
"Debugging hint:\n"
|
||||
"\tsetenv NSPR_LOG_MODULES nsComponentManager:5\n"
|
||||
"\tsetenv NSPR_LOG_FILE xpcom.log\n"
|
||||
"\t./nsTestSample\n"
|
||||
"\t<check the contents for xpcom.log for possible cause of error>.\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Call methods on our sample to test it out.
|
||||
rv = mysample->WriteValue("Inital print:");
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("ERROR: Calling nsISample::WriteValue() [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -3;
|
||||
}
|
||||
// Call methods on our sample to test it out.
|
||||
rv = mysample->WriteValue("Inital print:");
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("ERROR: Calling nsISample::WriteValue() [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -3;
|
||||
}
|
||||
|
||||
const char *testValue = "XPCOM defies gravity";
|
||||
rv = mysample->SetValue(testValue);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("ERROR: Calling nsISample::SetValue() [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -3;
|
||||
}
|
||||
printf("Set value to: %s\n", testValue);
|
||||
char *str;
|
||||
rv = mysample->GetValue(&str);
|
||||
const char* testValue = "XPCOM defies gravity";
|
||||
rv = mysample->SetValue(testValue);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("ERROR: Calling nsISample::SetValue() [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -3;
|
||||
}
|
||||
printf("Set value to: %s\n", testValue);
|
||||
char* str;
|
||||
rv = mysample->GetValue(&str);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("ERROR: Calling nsISample::GetValue() [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -3;
|
||||
}
|
||||
if (strcmp(str, testValue))
|
||||
{
|
||||
printf("Test FAILED.\n");
|
||||
return -4;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("ERROR: Calling nsISample::GetValue() [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
return -3;
|
||||
}
|
||||
if (strcmp(str, testValue)) {
|
||||
printf("Test FAILED.\n");
|
||||
return -4;
|
||||
}
|
||||
|
||||
NS_Free(str);
|
||||
NS_Free(str);
|
||||
|
||||
rv = mysample->WriteValue("Final print :");
|
||||
printf("Test passed.\n");
|
||||
|
||||
// All nsCOMPtr's must be deleted prior to calling shutdown XPCOM
|
||||
// as we should not hold references passed XPCOM Shutdown.
|
||||
servMan = 0;
|
||||
manager = 0;
|
||||
mysample = 0;
|
||||
|
||||
// Shutdown XPCOM
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
rv = mysample->WriteValue("Final print :");
|
||||
printf("Test passed.\n");
|
||||
|
||||
return 0;
|
||||
// All nsCOMPtr's must be deleted prior to calling shutdown XPCOM
|
||||
// as we should not hold references passed XPCOM Shutdown.
|
||||
servMan = 0;
|
||||
manager = 0;
|
||||
mysample = 0;
|
||||
|
||||
// Shutdown XPCOM
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче