/* $Id$ */
/** @file
* MS COM / XPCOM Abstraction Layer - Guid class declaration.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___VBox_com_Guid_h
#define ___VBox_com_Guid_h
/* Make sure all the stdint.h macros are included - must come first! */
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif
{
typedef enum GuidState_t
{
} GuidState_t;
/**
* Helper class that represents the UUID type and hides platform-specific
* implementation details.
*/
{
Guid()
{
::RTUuidClear(&mUuid);
dbg_refresh();
}
{
dbg_refresh();
}
{
if (isZero())
dbg_refresh();
}
{
if (isZero())
dbg_refresh();
}
/**
* Construct a GUID from a string.
*
* @param that The UUID string. Can be with or without the curly
* brackets. Empty strings are translated to a zero
* GUID, and strings which are not confirming to
* valid GUID string representations are marked as
* invalid.
*/
{
}
/**
* Construct a GUID from a BSTR.
*
* @param that The UUID BSTR. Can be with or without the curly
* brackets. Empty strings are translated to a zero
* GUID, and strings which are not confirming to
* valid GUID string representations are marked as
* invalid.
*/
{
}
/**
* Construct a GUID from a Utf8Str.
*
* @param that The UUID Utf8Str. Can be with or without the curly
* brackets. Empty strings are translated to a zero
* GUID, and strings which are not confirming to
* valid GUID string representations are marked as
*/
{
}
/**
* Construct a GUID from a RTCString.
*
* @param that The UUID RTCString. Can be with or without the curly
* brackets. Empty strings are translated to a zero
* GUID, and strings which are not confirming to
* valid GUID string representations are marked as
*/
{
}
/**
* Construct a GUID from a Bstr.
*
* @param that The UUID Bstr. Can be with or without the curly
* brackets. Empty strings are translated to a zero
* GUID, and strings which are not confirming to
* valid GUID string representations are marked as
*/
{
}
{
dbg_refresh();
return *this;
}
{
if (isZero())
dbg_refresh();
return *this;
}
{
if (isZero())
dbg_refresh();
return *this;
}
{
{
::RTUuidClear(&mUuid);
}
else
{
if (RT_FAILURE(rc))
{
::RTUuidClear(&mUuid);
}
else if (isZero())
}
dbg_refresh();
return *this;
}
{
{
::RTUuidClear(&mUuid);
}
else
{
if (RT_FAILURE(rc))
{
::RTUuidClear(&mUuid);
}
else if (isZero())
}
dbg_refresh();
return *this;
}
{
}
{
}
{
}
void create()
{
::RTUuidCreate(&mUuid);
dbg_refresh();
}
void clear()
{
::RTUuidClear(&mUuid);
dbg_refresh();
}
/**
* Convert the GUID to a string.
*
* @returns String object containing the formatted GUID.
* @throws std::bad_alloc
*/
{
if (mGuidState == GUID_INVALID)
{
/* What to return in case of wrong Guid */
return Utf8Str("00000000-0000-0000-0000-00000000000");
}
}
/**
* Like toString, but encloses the returned string in curly brackets.
*
* @returns String object containing the formatted GUID in curly brackets.
* @throws std::bad_alloc
*/
{
if (mGuidState == GUID_INVALID)
{
/* What to return in case of wrong Guid */
return Utf8Str("{00000000-0000-0000-0000-00000000000}");
}
buf[0] = '{';
}
/**
* Convert the GUID to a string.
*
* @returns Bstr object containing the formatted GUID.
* @throws std::bad_alloc
*/
{
if (mGuidState == GUID_INVALID)
{
/* What to return in case of wrong Guid */
return Bstr("00000000-0000-0000-0000-00000000000");
}
}
bool isValid() const
{
return mGuidState != GUID_INVALID;
}
bool isZero() const
{
return mGuidState == GUID_ZERO;
}
/**
* To directly copy the contents to a GUID, or for passing it as an input
* parameter of type (const GUID *), the compiler converts. */
{
}
/**
* To pass instances to printf-like functions.
*/
{
}
#if !defined(VBOX_WITH_XPCOM)
/** To assign instances to OUT_GUID parameters from within the interface
* method. */
{
if (pguid)
return *this;
}
/** To pass instances as OUT_GUID parameters to interface methods. */
{
}
#else
/** To assign instances to OUT_GUID parameters from within the
* interface method */
{
if (ppGuid)
return *this;
}
/**
* Internal helper class for asOutParam().
*
* This takes a GUID reference in the constructor and copies the mUuid from
* the method to that instance in its destructor.
*/
{
: ptr(0),
{
}
~GuidOutParam()
{
{
outer.dbg_refresh();
}
}
};
/** to pass instances as OUT_GUID parameters to interface methods */
#endif
/**
* Static immutable empty (zero) object. May be used for comparison purposes.
*/
{
{
::RTUuidClear(&mUuid);
}
else
{
if (RT_FAILURE(rc))
{
::RTUuidClear(&mUuid);
}
else if (isZero())
}
dbg_refresh();
}
{
{
::RTUuidClear(&mUuid);
}
else
{
if (RT_FAILURE(rc))
{
::RTUuidClear(&mUuid);
}
else if (isZero())
}
dbg_refresh();
}
/**
* Refresh the debug-only UUID string.
*
* In debug code, refresh the UUID string representatino for debugging;
* must be called every time the internal uuid changes; compiles to nothing
* in release code.
*/
inline void dbg_refresh()
{
#ifdef DEBUG
switch (mGuidState)
{
case GUID_ZERO:
case GUID_NORMAL:
break;
default:
break;
}
#endif
}
/** The UUID. */
#ifdef DEBUG
/** String representation of mUuid for printing in the debugger. */
/** Another string variant for the debugger, points to szUUID. */
const char *m_pcszUUID;
#endif
};
} /* namespace com */
#endif /* !___VBox_com_Guid_h */