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

📄 object.h

📁 安装 H323需要的pwlib库
💻 H
📖 第 1 页 / 共 4 页
字号:
///////////////////////////////////////////////////////////////////////////////// Disable inlines when debugging for faster compiles (the compiler doesn't// actually inline the function with debug on any way).#ifndef P_USE_INLINES#ifdef _DEBUG#define P_USE_INLINES 0#else#define P_USE_INLINES 0#endif#endif#if P_USE_INLINES#define PINLINE inline#else#define PINLINE#endif///////////////////////////////////////////////////////////////////////////////// Declare the debugging support#ifndef P_USE_ASSERTS#define P_USE_ASSERTS 1#endif#if !P_USE_ASSERTS#define PAssert(b, m) (b)#define PAssert2(b, c, m) (b)#define PAssertOS(b) (b)#define PAssertNULL(p) (p)#define PAssertAlways(m)#define PAssertAlways2(c, m)#else // P_USE_ASSERTS/// Standard assert messages for the PAssert macro.enum PStandardAssertMessage {  PLogicError,              // A logic error occurred.  POutOfMemory,             // A new or malloc failed.  PNullPointerReference,    // A reference was made through a NULL pointer.  PInvalidCast,             // An invalid cast to descendant is required.  PInvalidArrayIndex,       // An index into an array was negative.  PInvalidArrayElement,     // A NULL array element object was accessed.  PStackEmpty,              // A Pop() was made of a stack with no elements.  PUnimplementedFunction,   // Funtion is not implemented.  PInvalidParameter,        // Invalid parameter was passed to a function.  POperatingSystemError,    // Error was returned by Operating System.  PChannelNotOpen,          // Operation attempted when channel not open.  PUnsupportedFeature,      // Feature is not supported.  PInvalidWindow,           // Access through invalid window.  PMaxStandardAssertMessage};#define __CLASS__ NULLvoid PAssertFunc(const char * file, int line, const char * className, PStandardAssertMessage msg);void PAssertFunc(const char * file, int line, const char * className, const char * msg);void PAssertFunc(const char * full_msg);inline bool PAssertFuncInline(bool b, const char * file, int line, const char * className, PStandardAssertMessage msg){  if (!b)     PAssertFunc(file, line, className, msg);  return b;}inline bool PAssertFuncInline(bool b, const char * file, int line, const char * className, const char * msg){  if (!b)     PAssertFunc(file, line, className, msg);  return b;}/** This macro is used to assert that a condition must be TRUE.If the condition is FALSE then an assert function is called with the sourcefile and line number the macro was instantiated on, plus the message describedby the #msg# parameter. This parameter may be either a standard valuefrom the #PStandardAssertMessage# enum or a literal string.*/#define PAssert(b, m) PAssertFuncInline((b), __FILE__,__LINE__,__CLASS__,(m))/** This macro is used to assert that a condition must be TRUE.If the condition is FALSE then an assert function is called with the sourcefile and line number the macro was instantiated on, plus the message describedby the #msg# parameter. This parameter may be either a standard valuefrom the #PStandardAssertMessage# enum or a literal string.The #c# parameter specifies the class name that the error occurred in*/#define PAssert2(b, c, m) PAssertFuncInline((b), __FILE__,__LINE__,(c),(m))/** This macro is used to assert that an operating system call succeeds.If the condition is FALSE then an assert function is called with the sourcefile and line number the macro was instantiated on, plus the messagedescribed by the #POperatingSystemError# value in the #PStandardAssertMessage#enum. */#define PAssertOS(b) PAssertFuncInline((b), __FILE__,__LINE__,__CLASS__,POperatingSystemError)/** This macro is used to assert that a pointer must be non-null.If the pointer is NULL then an assert function is called with the source fileand line number the macro was instantiated on, plus the message described bythe PNullPointerReference value in the #PStandardAssertMessage# enum.Note that this evaluates the expression defined by #ptr# twice. Toprevent incorrect behaviour with this, the macro will assume that the#ptr# parameter is an L-Value. */#define PAssertNULL(p) ((&(p)&&(p)!=NULL)?(p): \                     (PAssertFunc(__FILE__,__LINE__, __CLASS__, PNullPointerReference),(p)))/** This macro is used to assert immediately.The assert function is called with the source file and line number the macrowas instantiated on, plus the message described by the #msg# parameter. Thisparameter may be either a standard value from the #PStandardAssertMessage#enum or a literal string.*/#define PAssertAlways(m) PAssertFunc(__FILE__,__LINE__,__CLASS__,(m))/** This macro is used to assert immediately.The assert function is called with the source file and line number the macrowas instantiated on, plus the message described by the #msg# parameter. Thisparameter may be either a standard value from the #PStandardAssertMessage#enum or a literal string.*/#define PAssertAlways2(c, m) PAssertFunc(__FILE__,__LINE__,(c),(m))#endif // P_USE_ASSERTS/** Get the stream being used for error output.This stream is used for all trace output using the various trace functionsand macros.*/ostream & PGetErrorStream();/** Set the stream to be used for error output.This stream is used for all error output using the #PError# macro.*/void PSetErrorStream(ostream * strm /** New stream for error output */ );/** This macro is used to access the platform specific error output stream.This is to be used in preference to assuming #cerr# is always available. OnUnix platforms this {\bfis} #cerr# but for MS-Windows this is another streamthat uses the OutputDebugString() Windows API function. Note that a MS-DOS orWindows NT console application would still use #cerr#.The #PError# stream would normally only be used for debugging information asa suitable display is not always available in windowed environments.   The macro is a wrapper for a global variable #PErrorStream# which is a pointerto an #ostream#. The variable is initialised to #cerr# for all but MS-Windowsand NT GUI applications. An application could change this pointer to a#ofstream# variable of #PError# output is wished to be redirected to a file.*/#define PError (PGetErrorStream())///////////////////////////////////////////////////////////////////////////////// Debug and tracing#ifndef PTRACING#ifndef _DEBUG#define PTRACING 0#else#define PTRACING 1#endif#endif/**Class to encapsulate tracing functions.   This class does not require any instances and is only being used as a   method of grouping functions together in a name space.  */class PTrace{public:  /// Options for trace output.  enum Options {    /**Include PTrace::Block constructs in output       If this is bit is clear, all PTrace::Block output is inhibited       regardless of the trace level. If set, the PTrace::Block may occur       provided the trace level is greater than zero.    */    Blocks = 1,    /// Include date and time in all output    DateAndTime = 2,    /// Include (millisecond) timestamp in all output    Timestamp = 4,    /// Include identifier for thread trace is made from in all output    Thread = 8,    /// Include trace level in all output    TraceLevel = 16,    /// Include the file and line for the trace call in all output    FileAndLine = 32,    /// Include thread object pointer address in all trace output    ThreadAddress = 64,    /// Append to log file rather than resetting every time    AppendToFile = 128,    /** SystemLog flag for tracing within a PServiceProcess application. Must        be set in conjection with SetStream(new PSystemLog).      */    GMTTime = 256,    /** Output timestamps in GMT time rather than local time      */    SystemLogStream = 32768  };  /**Set the most common trace options.     If filename is not NULL then a PTextFile is created and attached the     trace output stream. This object is never closed or deleted until the     termination of the program.     A trace output of the program name version and OS is written as well.    */  static void Initialise(    unsigned level,    const char * filename = NULL,    unsigned options = Timestamp | Thread | Blocks  );  /** Set the trace options.  The PTRACE(), PTRACE_BLOCK() and PTRACE_LINE() macros output trace text that  may contain assorted values. These are defined by the Options enum.  Note this function OR's the bits included in the options parameter.  */  static void SetOptions(unsigned options /** New level for trace */ );  /** Clear the trace options.  The PTRACE(), PTRACE_BLOCK() and PTRACE_LINE() macros output trace text that  may contain assorted values. These are defined by the Options enum.  Note this function AND's the complement of the bits included in the options  parameter.  */  static void ClearOptions(unsigned options /** New level for trace */ );  /** Get the current trace options.  The PTRACE(), PTRACE_BLOCK() and PTRACE_LINE() macros output trace text that  may contain assorted values. These are defined by the Options enum.  */  static unsigned GetOptions();  /** Set the trace level.  The PTRACE() macro checks to see if its level is equal to or lower then the  level set by this function. If so then the trace text is output to the trace  stream.  */  static void SetLevel(unsigned level /** New level for trace */ );  /** Get the trace level.  The PTRACE() macro checks to see if its level is equal to or lower then the  level set by this function. If so then the trace text is output to the trace  stream.  */  static unsigned GetLevel();  /** Determine if the level may cause trace output.  This checks against the current global trace level set by #PSetTraceLevel#  for if the trace output may be emitted. This is used by the PTRACE macro.  */  static BOOL CanTrace(unsigned level /** Trace level to check */);  /** Set the stream to be used for trace output.  This stream is used for all trace output using the various trace functions  and macros.  */  static void SetStream(ostream * out /** New output stream from trace. */ );  /** Begin a trace output.  If the trace stream output is used outside of the provided macros, it  should be noted that a mutex is obtained on the call to #PBeginTrace# which  will prevent any other threads from using the trace stream until the  #PEndTrace# function is called.  So a typical usage would be:  \begin{verbatim}    ostream & s = PTrace::Begin(3, __FILE__, __LINE__);    s << "hello";    if (want_there)      s << " there";    s << '!' << PTrace::End();  \end{verbatim}  */  static ostream & Begin(    unsigned level,         /// Log level for output    const char * fileName,  /// Filename of source file being traced    int lineNum             /// Line number of source file being traced.  );  /** End a trace output.  If the trace stream output is used outside of the provided macros, the  #PEndTrace# function must be used at the end of the section of trace  output. A mutex is obtained on the call to #PBeginTrace# which will prevent  any other threads from using the trace stream until the PEndTrace. The  #PEndTrace# is used in a similar manner to #::endl# or #::flush#.  So a typical usage would be:  \begin{verbatim}    ostream & s = PTrace::Begin();    s << "hello";    if (want_there)      s << " there";    s << '!' << PTrace::End();  \end{verbatim}  */  static ostream & End(ostream & strm /** Trace output stream being completed */);  /** Class to trace Execution blocks.  This class is used for tracing the entry and exit of program blocks. Upon  construction it outputs an entry trace message and on destruction outputs an  exit trace message. This is normally only used from in the PTRACE_BLOCK macro.  */  class Block {    public:      /** Output entry trace message. */      Block(        const char * fileName, /// Filename of source file being traced        int lineNum,           /// Line number of source file being traced.        const char * traceName          /// String to be output with trace, typically it is the function name.       );      /// Output exit trace message.      ~Block();    private:      const char * file;      int          line;      const char * name;  };};#if !PTRACING#define PTRACE_PARAM(param)#define PTRACE_BLOCK(n)#define PTRACE_LINE()#define PTRACE(level, arg)#define PTRACE_IF(level, cond, args)#else/* Macro to conditionally declare a parameter to a function to avoid compiler   warning due that parameter only being used in a PTRACE */#define PTRACE_PARAM(param) param/** Trace an execution block.This macro creates a trace variable for tracking the entry and exit of programblocks. It creates an instance of the PTraceBlock class that will output atrace message at the line PTRACE_BLOCK is called and then on exit from thescope it is defined in.*/#define PTRACE_BLOCK(name) PTrace::Block __trace_block_instance(__FILE__, __LINE__, name)/** Trace the execution of a line.This macro outputs a trace of a source file line execution.*/#define PTRACE_LINE() \    if (!PTrace::CanTrace(1)) ; else \      PTrace::Begin(1, __FILE__, __LINE__) << __FILE__ << '(' << __LINE__ << ')' << PTrace::End/** Output trace.This macro outputs a trace of any information needed, using standard streamoutput operators. The output is only made if the trace level set by the#PSetTraceLevel# function is greater than or equal to the #level# argument.*/#define PTRACE(level, args) \    if (!PTrace::CanTrace(level)) ; else \      PTrace::Begin(level, __FILE__, __LINE__) << args << PTrace::End/** Output trace on condition.This macro outputs a trace of any information needed, using standard streamoutput operators. The output is only made if the trace level set by the#PSetTraceLevel# function is greater than or equal to the #level# argumentand the conditional is TRUE. Note the conditional is only evaluated if thetrace level is sufficient.*/#define PTRACE_IF(level, cond, args) \    if (!(PTrace::CanTrace(level)  && (cond))) ; else \      PTrace::Begin(level, __FILE__, __LINE__) << args << PTrace::End#endif#if PMEMORY_CHECK/** Memory heap checking class.This class implements the memory heap checking and validation functions. Itmaintains lists of allocated block so that memory leaks can be detected. Italso initialises memory on allocation and deallocation to help catch errorsinvolving the use of dangling pointers.*/class PMemoryHeap {  protected:    /// Initialise the memory checking subsystem.    PMemoryHeap();  public:    // Clear up the memory checking subsystem, dumping memory leaks.    ~PMemoryHeap();    /** Allocate a memory block.       This allocates a new memory block and keeps track of it. The memory       block is filled with the value in the #allocFillChar# member variable       to help detect uninitialised structures.       @return pointer to newly allocated memory block.     */    static void * Allocate(      size_t nSize,           /// Number of bytes to allocate.      const char * file,      /// Source file name for allocating function.      int line,               /// Source file line for allocating function.      const char * className  /// Class name for allocating function.    );    /** Allocate a memory block.       This allocates a new memory block and keeps track of it. The memory       block is filled with the value in the #allocFillChar# member variable       to help detect uninitialised structures.       @return pointer to newly allocated memory block.     */    static void * Allocate(      size_t count,       /// Number of items to allocate.      size_t iSize,       /// Size in bytes of each item.      const char * file,  /// Source file name for allocating function.      int line            /// Source file line for allocating function.    );    /** Change the size of an allocated memory block.       This allocates a new memory block and keeps track of it. The memory       block is filled with the value in the #allocFillChar# member variable       to help detect uninitialised structures.      @return pointer to reallocated memory block. Note this may      {\em not} be the same as the pointer passed into the function.     */    static void * Reallocate(      void * ptr,         /// Pointer to memory block to reallocate.      size_t nSize,       /// New number of bytes to allocate.      const char * file,  /// Source file name for allocating function.      int line            /// Source file line for allocating function.    );    /** Free a memory block.      The memory is deallocated, a warning is displayed if it was never      allocated. The block of memory is filled with the value in the      #freeFillChar# member variable.     */    static void Deallocate(      void * ptr,             /// Pointer to memory block to deallocate.      const char * className  /// Class name for deallocating function.    );    /** Validation result.     */    enum Validation {      Ok, Bad, Trashed    };    /** Validate the memory pointer.

⌨️ 快捷键说明

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