⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.h

📁 mgcp协议源代码。支持多种编码:g711
💻 H
📖 第 1 页 / 共 5 页
字号:
                              sizeof(const char *) +                              sizeof(size_t) +                              sizeof(DWORD) +                              sizeof(WORD) +                              sizeof(BYTE))%8      };      Header     * prev;      Header     * next;      const char * className;      const char * fileName;      size_t       size;      DWORD        request;      WORD         line;      BYTE         flags;      char         guard[NumGuardBytes];      static char GuardBytes[NumGuardBytes];    };#pragma pack()    BOOL isDestroyed;    Header * listHead;    Header * listTail;    static DWORD allocationBreakpoint;    DWORD allocationRequest;    DWORD firstRealObject;    BYTE  flags;    char  allocFillChar;    char  freeFillChar;    DWORD currentMemoryUsage;    DWORD peakMemoryUsage;    DWORD currentObjects;    DWORD peakObjects;    DWORD totalObjects;    ostream * leakDumpStream;#if defined(_WIN32)    CRITICAL_SECTION mutex;#elif defined(P_PTHREADS)    pthread_mutex_t mutex;#endif};/** Allocate memory for the run time library.This version of free is used for data that is not to be allocated using thememory check system, ie will be free'ed inside the C run time library.*/inline void runtime_malloc(size_t bytes /** Size of block to allocate */ ) { malloc(bytes); }/** Free memory allocated by run time library.This version of free is used for data that is not allocated using thememory check system, ie was malloc'ed inside the C run time library.*/inline void runtime_free(void * ptr /** Memory block to free */ ) { free(ptr); }/** Override of system call for memory check system.This macro is used to allocate memory via the memory check system selectedwith the #PMEMORY_CHECK# compile time option. It will include the source fileand line into the memory allocation to allow the PMemoryHeap class to keeptrack of the memory block.*/#define malloc(s) PMemoryHeap::Allocate(s, __FILE__, __LINE__, NULL)/** Override of system call for memory check system.This macro is used to allocate memory via the memory check system selectedwith the #PMEMORY_CHECK# compile time option. It will include the source fileand line into the memory allocation to allow the PMemoryHeap class to keeptrack of the memory block.*/#define calloc(n,s) PMemoryHeap::Allocate(n, s, __FILE__, __LINE__)/** Override of system call for memory check system.This macro is used to allocate memory via the memory check system selectedwith the #PMEMORY_CHECK# compile time option. It will include the source fileand line into the memory allocation to allow the PMemoryHeap class to keeptrack of the memory block.*/#define realloc(p,s) PMemoryHeap::Reallocate(p, s, __FILE__, __LINE__)/** Override of system call for memory check system.This macro is used to deallocate memory via the memory check system selectedwith the #PMEMORY_CHECK# compile time option. It will include the source fileand line into the memory allocation to allow the PMemoryHeap class to keeptrack of the memory block.*/#define free(p) PMemoryHeap::Deallocate(p, NULL)/** Macro for overriding system default #new# operator.This macro is used to allocate memory via the memory check system selectedwith the PMEMORY_CHECK compile time option. It will include the source fileand line into the memory allocation to allow the PMemoryHeap class to keeptrack of the memory block.This macro could be used instead of the system #new# operator. Or you can placethe line\begin{verbatim}  #define new PNEW\end{verbatim}at the begining of the source file, after all declarations that use thePCLASSINFO macro.*/#define PNEW  new (__FILE__, __LINE__)#if !defined(_MSC_VER) || _MSC_VER<1200#define PSPECIAL_DELETE_FUNCTION#else#define PSPECIAL_DELETE_FUNCTION \    void operator delete(void * ptr, const char *, int) \      { PMemoryHeap::Deallocate(ptr, Class()); } \    void operator delete[](void * ptr, const char *, int) \      { PMemoryHeap::Deallocate(ptr, Class()); }#endif#define PNEW_AND_DELETE_FUNCTIONS \    void * operator new(size_t nSize, const char * file, int line) \      { return PMemoryHeap::Allocate(nSize, file, line, Class()); } \    void * operator new(size_t nSize) \      { return PMemoryHeap::Allocate(nSize, NULL, 0, Class()); } \    void operator delete(void * ptr) \      { PMemoryHeap::Deallocate(ptr, Class()); } \    void * operator new[](size_t nSize, const char * file, int line) \      { return PMemoryHeap::Allocate(nSize, file, line, Class()); } \    void * operator new[](size_t nSize) \      { return PMemoryHeap::Allocate(nSize, NULL, 0, Class()); } \    void operator delete[](void * ptr) \      { PMemoryHeap::Deallocate(ptr, Class()); } \    PSPECIAL_DELETE_FUNCTIONinline void * operator new(size_t nSize, const char * file, int line)  { return PMemoryHeap::Allocate(nSize, file, line, NULL); }inline void * operator new[](size_t nSize, const char * file, int line)  { return PMemoryHeap::Allocate(nSize, file, line, NULL); }#ifndef __GNUC__void * operator new(size_t nSize);void * operator new[](size_t nSize);void operator delete(void * ptr);void operator delete[](void * ptr);#if defined(_MSC_VER) && _MSC_VER>=1200inline void operator delete(void * ptr, const char *, int)  { PMemoryHeap::Deallocate(ptr, NULL); }inline void operator delete[](void * ptr, const char *, int)  { PMemoryHeap::Deallocate(ptr, NULL); }#endif#endif#else // _DEBUG#define PNEW new#define PNEW_AND_DELETE_FUNCTIONS#define runtime_malloc(s) malloc(s)#define runtime_free(p) free(p)#endif // _DEBUG/** Declare all the standard PWlib class information.This macro is used to provide the basic run-time typing capability neededby the library. All descendent classes from the #PObject# class requirethese functions for correct operation. Either use this macro or the#PDECLARE_CLASS# macro.The use of the #PDECLARE_CLASS# macro is no longer recommended for reasonsof compatibility with documentation systems.*/#define PCLASSINFO(cls, par) \  public: \    static const char * Class() \      { return #cls; } \    virtual const char * GetClass(unsigned ancestor = 0) const \      { return ancestor > 0 ? par::GetClass(ancestor-1) : cls::Class(); } \    virtual BOOL IsClass(const char * clsName) const \      { return strcmp(clsName, cls::Class()) == 0; } \    virtual BOOL IsDescendant(const char * clsName) const \      { return strcmp(clsName, cls::Class()) == 0 || \                                               par::IsDescendant(clsName); } \    virtual Comparison CompareObjectMemoryDirect(const PObject & obj) const \      { return (Comparison)memcmp(this, &obj, sizeof(cls)); } \    PNEW_AND_DELETE_FUNCTIONS/** Declare a class with PWLib class information.This macro is used to declare a new class with a single public ancestor. Itstarts the class declaration and then uses the #PCLASSINFO# macro toget all the run-time type functions.The use of this macro is no longer recommended for reasons of compatibilitywith documentation systems.*/#define PDECLARE_CLASS(cls, par) class cls : public par { PCLASSINFO(cls, par)#ifdef DOC_PLUS_PLUS} Match previous opening brace in doc++#endifclass PSerialiser;class PUnSerialiser;///////////////////////////////////////////////////////////////////////////////// The root of all evil ... umm classes/** Ultimate parent class for all objects in the class library.This provides functionality provided to all classes, eg run-time types,default comparison operations, simple stream I/O and serialisation support.*/class PObject {  protected:    /** Constructor for PObject, make protected so cannot ever create one on       its own.     */    PObject() { }  public:    /* Destructor required to get the "virtual". A PObject really has nothing       to destroy.     */    virtual ~PObject() { }  /**@name Run Time Type functions */  //@{    /** Get the name of the class as a C string. This is a static function which       returns the type of a specific class. It is primarily used as an       argument to the #IsClass()# or #IsDescendant()# functions.              When comparing class names, always use the #strcmp()#       function rather than comparing pointers. The pointers are not       necessarily the same over compilation units depending on the compiler,       platform etc.       The #PCLASSINFO# macro declares a version of this function for the       particular class.       @return pointer to C string literal.     */          static const char * Class() { return "PObject"; }    /** Get the current dynamic type of the object instance.       When comparing class names, always use the #strcmp()#       function rather than comparing pointers. The pointers are not       necessarily the same over compilation units depending on the compiler,       platform etc.       The #PCLASSINFO# macro declares an override of this function for       the particular class. The user need not implement it.       @return pointer to C string literal.     */    virtual const char * GetClass(      unsigned ancestor = 0      /** Level of ancestor to get the class name for. A value of zero is the         instances class name, one is its ancestor, two for the ancestors         ancestor etc.       */    ) const;    /** Determine if the dynamic type of the current instance is of the       specified class. The class name is usually provided by the       #Class()# static function of the desired class.           The #PCLASSINFO# macro declares an override of this function for       the particular class. The user need not implement it.       @return TRUE if object is of the class.     */    virtual BOOL IsClass(      const char * clsName    // Class name to compare against.    ) const;    /** Determine if the dynamic type of the current instance is a descendent of       the specified class. The class name is usually provided by the       #Class()# static function of the desired class.           The #PCLASSINFO# macro declares an override of this function for       the particular class. The user need not implement it.       @return TRUE if object is descended from the class.     */    virtual BOOL IsDescendant(      const char * clsName    // Ancestor class name to compare against.    ) const;  //@}  /**@name Comparison functions */  //@{    /** Result of the comparison operation performed by the #Compare()#       function.      */    enum Comparison {      LessThan = -1,      EqualTo = 0,      GreaterThan = 1    };    /** Compare the two objects and return their relative rank. This function is       usually overridden by descendent classes to yield the ranking according       to the semantics of the object.              The default function is to use the #CompareObjectMemoryDirect()#       function to do a byte wise memory comparison of the two objects.       @return       #LessThan#, #EqualTo# or #GreaterThan#       according to the relative rank of the objects.     */    virtual Comparison Compare(      const PObject & obj   // Object to compare against.    ) const;        /** Determine the byte wise comparison of two objects. This is the default       comparison operation for objects that do not explicitly override the       #Compare()# function.           The #PCLASSINFO# macro declares an override of this function for       the particular class. The user need not implement it.       @return       #LessThan#, #EqualTo# or #GreaterThan#       according to the result #memcpy()# function.     */    virtual Comparison CompareObjectMemoryDirect(      const PObject & obj   // Object to compare against.    ) const;    /** Compare the two objects.           @return       TRUE if objects are equal.     */    BOOL operator==(      const PObject & obj   // Object to compare against.    ) const { return Compare(obj) == EqualTo; }    /** Compare the two objects.           @return       TRUE if objects are not equal.     */    BOOL operator!=(      const PObject & obj   // Object to compare against.    ) const { return Compare(obj) != EqualTo; }    /** Compare the two objects.           @return       TRUE if objects are less than.     */    BOOL operator<(      const PObject & obj   // Object to compare against.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -