genesis-3d_engine/Engine/foundation/util/win32/win32guid.h
zhongdaohuan 6e8fbca745 genesis-3d engine version 1.3.
match the genesis editor version 1.3.0.653.
2014-05-05 14:50:33 +08:00

154 lines
4.7 KiB
C++

#pragma once
/****************************************************************************
Copyright (c) 2006, Radon Labs GmbH
Copyright (c) 2011-2013,WebJet Business Division,CYOU
http://www.genesis-3d.com.cn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "core/types.h"
#include "util/string.h"
#include "core/sysfunc.h"
//------------------------------------------------------------------------------
namespace Win32
{
class Win32Guid
{
public:
/// override new operator
void* operator new(size_t s);
/// override delete operator
void operator delete(void* ptr);
/// constructor
Win32Guid();
/// copy constructor
Win32Guid(const Win32Guid& rhs);
/// construct from raw binary data as returned by AsBinary()
Win32Guid(const unsigned char* ptr, SizeT size);
/// assignement operator
void operator=(const Win32Guid& rhs);
/// assignment operator from string
void operator=(const Util::String& rhs);
/// equality operator
bool operator==(const Win32Guid& rhs) const;
/// inequlality operator
bool operator!=(const Win32Guid& rhs) const;
/// less-then operator
bool operator<(const Win32Guid& rhs) const;
/// less-or-equal operator
bool operator<=(const Win32Guid& rhs) const;
/// greater-then operator
bool operator>(const Win32Guid& rhs) const;
/// greater-or-equal operator
bool operator>=(const Win32Guid& rhs) const;
/// return true if the contained guid is valid (not NIL)
bool IsValid() const;
/// generate a new guid
void Generate();
/// construct from string representation
static Win32Guid FromString(const Util::String& str);
/// construct from binary representation
static Win32Guid FromBinary(const unsigned char* ptr, SizeT numBytes);
/// get as string
Util::String AsString() const;
/// get pointer to binary data
SizeT AsBinary(const unsigned char*& outPtr) const;
/// return the size of the binary representation in bytes
static SizeT BinarySize();
/// get a hash code (compatible with Util::HashTable)
IndexT HashCode() const;
private:
UUID uuid;
};
//------------------------------------------------------------------------------
/**
*/
__forceinline void*
Win32Guid::operator new(size_t size)
{
#if NEBULA3_DEBUG
n_assert(size == sizeof(Win32Guid));
#endif
#if NEBULA3_OBJECTS_USE_MEMORYPOOL
return Memory::ObjectPoolAllocator->Alloc(size);
#else
return Memory::Alloc(Memory::ObjectHeap, size);
#endif
}
//------------------------------------------------------------------------------
/**
*/
__forceinline void
Win32Guid::operator delete(void* ptr)
{
#if NEBULA3_OBJECTS_USE_MEMORYPOOL
return Memory::ObjectPoolAllocator->Free(ptr, sizeof(Win32Guid));
#else
return Memory::Free(Memory::ObjectHeap, ptr);
#endif
}
//------------------------------------------------------------------------------
/**
*/
inline
Win32Guid::Win32Guid()
{
Memory::Clear(&(this->uuid), sizeof(this->uuid));
}
//------------------------------------------------------------------------------
/**
*/
inline
Win32Guid::Win32Guid(const Win32Guid& rhs)
{
this->uuid = rhs.uuid;
}
//------------------------------------------------------------------------------
/**
*/
inline
Win32Guid::Win32Guid(const unsigned char* ptr, SizeT size)
{
n_assert((0 != ptr) && (size == sizeof(UUID)));
Memory::Copy(ptr, &this->uuid, sizeof(UUID));
}
//------------------------------------------------------------------------------
/**
*/
inline SizeT
Win32Guid::BinarySize()
{
return sizeof(UUID);
}
} // namespace Win32
//------------------------------------------------------------------------------