Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Headers/DTSCPlusLibrary.h
/* |
File: DTSCPlusLibrary.h |
Contains: DTSCPlusLibrary.h contains all the global data and definitions needed when building |
more DTS C++ libraries. Every class should have this file included. |
DTSLibrary.h contains all the header information. |
Written by: |
Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/18/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
// Declare label for this header file |
#ifndef _DTSCPLUSLIBRARY_ |
#define _DTSCPLUSLIBRARY_ |
// _________________________________________________________________________________________________________ // |
// GLOBAL DEFINITIONS |
// TESTING, used for flagging that we use test code inside the classes and frameworks |
// TESTLEVEL0 - user friendly alerts as part of the application |
// TESTLEVEL1 - minor test level (detailed error message in alert box) |
// TESTLEVEL2 - semi-major test level (high level debuggers) |
// TESTLEVEL3 - major test level (low level debuggers) |
// future: TESTLOG1 - trigger a file log of information |
// TESTLOG2 - trigger a file log of information from a low level debugger |
#define TESTLEVEL3 |
// MPW C++, 1 = code for MPW C++ |
// #define MPWC++ |
// ZTC, 1 = code for ZTC |
// #define ZTC |
// SLM, code used with Shared Library Manager Support, 1 = true |
// #define SLM |
// _________________________________________________________________________________________________________ // |
// GENERAL INCLUDE FILES |
// Toolbox Include Files |
#ifndef __TYPES__ |
#include <Types.h> |
#endif |
#ifndef __STRING__ |
#include <String.h> |
#endif |
#ifndef __MEMORY__ |
#include <Memory.h> |
#endif |
#ifndef __DIALOGS__ |
#include <Dialogs.h> |
#endif |
#ifndef __APPLEEVENTS__ |
#include <AppleEvents.h> |
#endif |
// C++ library code |
#include <iostream.h> |
#include <stdlib.h> |
#include <StdIO.h> |
#include <stdarg.h> |
#ifdef SLM |
#include <LibraryManagerClasses.h> |
#endif |
// FUNCTION PROTOTYPES |
// I found out that these following former inlined functions were not inlined, |
// the linker screamed, so they now live in a .cp file (sigh), remember to include |
// the CPlusLibrary.cp file when using the other .cp files! |
short clen(char *cptr); |
void c2p(char *cptr); |
void p2c(StringPtr cptr); |
void Pstrcpy(StringPtr d, StringPtr s); |
void ConcatPStrings(Str255 first, Str255 second); |
Boolean CompareStr255(const Str255 *first, const Str255 *second); |
void vxdebugstr(char* format,...); |
void ErrorWindow(char* message); |
// INLINE FUNCTIONS |
// _________________________________________________________________________________________________________ // |
// 1: BASIC MANIPULATION INLINES |
// Min/Max functions, oh so useful. |
inline short Min(const short a, |
const short b) |
{ |
return a < b ? a : b; // Just returns the minimum of the two shorts. |
} // Min |
inline short Max(const short a, |
const short b) |
{ |
return a > b ? a : b; // Just returns the maximum of the two shorts. |
} // Max |
inline pascal Byte Decimal2BCD(Byte n) |
{ |
return ((n / 10) << 4) + (n % 10); |
} |
inline pascal Byte BCD2Decimal(Byte n) |
{ |
return ((n >> 4) * 10) + (n & 0x0f); |
} |
// extract hi word and lo word from a longword |
#define HiWrd(aLong) ((short) (((aLong) >> 16) & 0xFFFF)) |
#define LoWrd(aLong) ((short) ((aLong) & 0xFFFF)) |
// _________________________________________________________________________________________________________ // |
// MACROS AND DEBUGGING |
// ASSERT Function, used for testing conditions and flagging error states. |
// Example: vdebugstr("The error message from Foo is %i", fError); |
// We need to load in certain include files if we want to use the alert boxes for |
// high level ASSERT functions (we also need to include the GUIApplication.r file |
// into the project). |
#if (defined TESTLEVEL0 || defined TESTLEVEL1) |
#include "ApplicationResources.h" |
#endif |
// Define this flag if you want file and line information as part of the message. |
#define FILELINEINFO |
// fileinfo will keep track of the current file and line in a global. |
static char fileNameArray[32]; |
static char lineNumberArray[32]; |
#if (defined TESTLEVEL0 || defined TESTLEVEL1) |
inline void AlertUser(Str255 theMessage) |
{ |
short itemHit; |
if(!(AEInteractWithUser(kNoTimeOut, nil, nil))) // could we interact with the user? |
{ |
ParamText(theMessage, 0, 0,0); |
itemHit = Alert(kUserAlert, nil); |
} |
} |
#endif |
inline void fileinfo(char *file, int line) |
{ |
sprintf(fileNameArray, "File %s ", file); |
sprintf(lineNumberArray, " Line %d #", line); |
} |
// ASSERT MACROS |
// ASSERT, small (and quick assert), if assertion is false it will print out |
// a message |
// Use: ASSERT(false, "Problems with TSoundRecorder"); |
#if (defined TESTLEVEL0 || defined TESTLEVEL1) |
#define ASSERT(condition,debugMsg) do { \ |
if(condition == 0) \ |
{ \ |
AlertUser(debugMsg); \ |
} \ |
} while (0) \ |
#elif (defined TESTLEVEL2 || defined TESTLEVEL3) |
#define ASSERT(condition,debugMsg) do { \ |
if(condition == 0) \ |
{ \ |
DebugStr(debugMsg); \ |
} \ |
} while (0) |
#else |
#define ASSERT(condition,debugMsg) ((void) 0) |
#endif |
// VASSERT, if assertion is false it will print out file, line, message and possible variable |
// Use: VASSERT(false,("Problems with %d", anErr)); |
#if (defined TESTLEVEL0) |
##define VASSERT(condition,debugMsg) do { \ |
if(condition == 0) \ |
{ \ |
vxdebugstr debugMsg; \ |
} \ |
} while (0) |
#elif (defined TESTLEVEL1 || defined TESTLEVEL2 || defined TESTLEVEL3) |
#define VASSERT(condition,debugMsg) do { \ |
if(condition == 0) \ |
{ \ |
fileinfo(__FILE__, __LINE__); \ |
vxdebugstr debugMsg; \ |
} \ |
} while (0) |
#else |
#define (condition,debugMsg) ((void) 0) |
#endif |
// Option key triggered debug breaks: |
inline void ODebugger() |
// Drop into Debugger only if the option key is pressed. |
{ |
KeyMap k; |
GetKeys(k); |
if (((char*)k)[7] & 0x04) // check for option key in KeyMap |
Debugger(); |
} |
inline void ODebugStr(Str255 string) |
// Drop into DebugStr only if the option key is pressed. |
{ |
KeyMap k; |
GetKeys(k); |
if (((char*)k)[7] & 0x04) // check for option key in KeyMap |
DebugStr(string); |
} |
#endif |
// _________________________________________________________________________________________________________ // |
/* Change History (most recent last): |
No Init. Date Comment |
1 khs 9/10/92 New file |
2 khs 11/26/92 Added ASSERT macros and testing levels |
3 khs 1/14/93 Cleanup |
*/ |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14