UNDER CONSTRUCTION
Reference
Home
Overview
Hardware
News
Download
License
Documentation
Reference
Help
FAQs
Contributing
Contact
Links

LowLevel.hpp

Go to the documentation of this file.
00001 #ifndef ___RSLIB_LOWLEVEL___
00002 #define ___RSLIB_LOWLEVEL___
00003  
00004  
00005  
00006 //---INCLUDE
00007 //------------------->
00008 #include <RSLib\Types.hpp>
00009 #include <memory>
00010  
00011  
00012 //---NAMESPACES
00013 //-------------->
00014 namespace RSLib{
00015  
00016  
00017  
00018 //---FUNCTION
00019 // Desc: Commodity version of ZeroObject
00020 // Note: needed to cope with <windows.h> include...
00021 //------------------------------------------------------->
00022 #ifndef ZeroMemory
00023 inline void ZeroMemory(PVOID ptr, UINT32 bytes)
00024 {
00025    memset((void*)ptr,0,(size_t)bytes);
00026 }
00027 #endif
00028 template <typename T> void ZeroObjectMemory(T& object)
00029 {
00030    ZeroMemory(&object,sizeof(T));
00031 }
00032 inline bool CompareMemory(const void * a,const void * b,UINT32 bytes)
00033 {
00034    return (memcmp(a,b,bytes) == 0);
00035 }
00036 #ifndef CopyMemory
00037 inline void CopyMemory(PVOID a,const void * b,UINT32 bytes)
00038 {
00039    memcpy(a,b,bytes);
00040 }
00041 #endif
00042  
00043  
00044 namespace LowLevel{
00045  
00046  
00047 //---CLASS
00048 // Name: MethodAddress
00049 // Desc: Used to retrieve address of a method
00050 //       The macro form allows for simpler code
00051 //--------------------------------------------->
00052 template <typename T> class MethodAddress
00053 {
00054    private:
00055    PVOID address;
00056    
00057    public:
00058    typedef VOID (T::*Method)(VOID);
00059    
00060    public:
00061    MethodAddress(Method method)  {address = ( *((PVOID*)(&method)) );}
00062    operator PVOID()  {return address;} 
00063 };
00064 #define METHOD_ADDRESS(class,method) RSLib::LowLevel::MethodAddress<class>( (RSLib::LowLevel::MethodAddress<class>::Method)class::method )
00065 #define OBJECT_ADDRESS(class,object) ((PVOID)&(object)) 
00066  
00067  
00068  
00069 //---MACROS
00070 // Desc: dwords/words/bytes extracting macros
00071 // Note: from MAKEWORD ... to HIBYTE are extracted from windows headers. others have been added
00072 //---------------------------------------------------------------------------------------------------------------->
00073 #ifndef MAKEWORD
00074    #define MAKEWORD(a, b)      ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8))
00075    #define LOWORD(l)           ((WORD)((DWORD_PTR)(l) & 0xffff))
00076    #define HIWORD(l)           ((WORD)((DWORD_PTR)(l) >> 16))
00077    #define LOBYTE(w)           ((BYTE)((DWORD_PTR)(w) & 0xff))
00078    #define HIBYTE(w)           ((BYTE)((DWORD_PTR)(w) >> 8))
00079 #endif 
00080 
00081 #define MAKEQWORD(a,b)       ( (((QWORD)a)<<32) | (((QWORD)b)&0xFFFFFFFF) )
00082 #define MAKEDWORD(a, b)      ( (((DWORD)a)<<16) | (((DWORD)b)&0xFFFF) )
00083 #define LODWORD(q)           ( (DWORD) (q & 0xFFFFFFFF) )
00084 #define HIDWORD(q)           ( (DWORD) (q >> 32) )
00085  
00086  
00087  
00088 //---MACROS
00089 // Desc: passing of references as optional parameters
00090 //----------------------------------------------------->
00091 #define NULL_REFERENCE(type)           (*((type*)NULL))
00092 #define VALID_REFERENCE(reference)     (&reference != NULL)
00093 #define INVALID_REFERENCE(reference)   (&reference == NULL)
00094  
00095  
00096  
00097 }//namespace LowLevel
00098 }//namespace RSLib
00099  
00100  
00101  
00102 #endif//___RSLIB_LOWLEVEL___
Last Updated on 2006/02/01 09:53:39 UTC info@haptiklibrary.org