MercuryUtil.h File Reference

#include "global.h"
#include "MercuryVector.h"

Go to the source code of this file.

Classes

class  InstanceCounter< T >
class  MAutoPtr< T >

Defines

#define PROPERRETURN   "\n"
#define CLASS_RTTI(CLASSNAME, PARENTCLASS)
#define ASSERT_M(COND, MESSAGE)   { if(!(COND)) { mercury_crash(MESSAGE); } }
#define ASSERT(COND)   ASSERT_M((COND), "Assertion \"" + MString( #COND ) + "\" failed in: " + ssprintf( "%s:%d", __FILE__, __LINE__ ) )
#define FAIL(MESSAGE)   mercury_crash( MESSAGE )

Functions

MString ConvertToCFormat (const MString &ncf)
 Convert string containing binary characters to C-style formatted string.
MString ConvertToUnformatted (const MString &cf)
 Convert a C-style formatted string into it's binary string equivalent.
void Sleep (float msec)
int nextPow2 (int x)
int makePow2 (int x)
long DumpFromFile (const MString &filename, char *&data)
 Dump data from a file into a char * and return the size of data. If -1 then there was an error opening the file.
bool DumpToFile (const MString &filename, const char *data, long bytes)
 Dump data into the file filename. bytes specifies the length of data. Returns true if successful, false else.
void FileToMString (const MString &filename, MString &data)
 Dump the contents of a file to data.
void MStringToFile (const MString &filename, const MString &data)
 Dump data into file.
bool FileExists (const MString &filename)
long BytesUntil (const char *strin, const char *termin, long start, long slen, long termlen)
 Bytes until desired terminal.
long BytesNUntil (const char *strin, const char *termin, long start, long slen, long termlen)
 Bytes until something other than a terminal.
template<typename T>
Clamp (const T &in, const T &min, const T &max)
 Clamp (will make sure in is between min and max.
void mercury_crash (const char *reason="Internal error")
 Force mercury to crash and write the reason at the top of the crashlog.
void SplitStrings (const MString &in, MVector< MString > &out, const char *termin, const char *whitespace, long termlen, long wslen)
 Split given string into other strings using delimiters from termin.
unsigned int Swap32 (unsigned int n)
unsigned short Swap16 (unsigned short n)
template<typename T>
void Destructor (T *t)
int GetAPrime (int ith)


Define Documentation

#define ASSERT ( COND   )     ASSERT_M((COND), "Assertion \"" + MString( #COND ) + "\" failed in: " + ssprintf( "%s:%d", __FILE__, __LINE__ ) )

Definition at line 68 of file MercuryUtil.h.

#define ASSERT_M ( COND,
MESSAGE   )     { if(!(COND)) { mercury_crash(MESSAGE); } }

Definition at line 67 of file MercuryUtil.h.

#define CLASS_RTTI ( CLASSNAME,
PARENTCLASS   ) 

Value:

virtual MString GetType() { return #CLASSNAME; } \
    virtual void GetAllTypes( MVector<MString> & vOut ) { vOut.push_back( #CLASSNAME ); PARENTCLASS::GetAllTypes( vOut ); } \
    virtual bool IsTypeOf( const MString & sType ) { if( sType == #CLASSNAME ) return true; return PARENTCLASS::IsTypeOf( sType ); }

Definition at line 20 of file MercuryUtil.h.

#define FAIL ( MESSAGE   )     mercury_crash( MESSAGE )

Definition at line 69 of file MercuryUtil.h.

#define PROPERRETURN   "\n"

Definition at line 15 of file MercuryUtil.h.


Function Documentation

long BytesNUntil ( const char *  strin,
const char *  termin,
long  start,
long  slen,
long  termlen 
)

Bytes until something other than a terminal.

Definition at line 173 of file MercuryUtil.cpp.

long BytesUntil ( const char *  strin,
const char *  termin,
long  start,
long  slen,
long  termlen 
)

Bytes until desired terminal.

Definition at line 163 of file MercuryUtil.cpp.

template<typename T>
T Clamp ( const T &  in,
const T &  min,
const T &  max 
) [inline]

Clamp (will make sure in is between min and max.

Definition at line 61 of file MercuryUtil.h.

MString ConvertToCFormat ( const MString ncf  ) 

Convert string containing binary characters to C-style formatted string.

Definition at line 26 of file MercuryUtil.cpp.

MString ConvertToUnformatted ( const MString cf  ) 

Convert a C-style formatted string into it's binary string equivalent.

Definition at line 57 of file MercuryUtil.cpp.

template<typename T>
void Destructor ( T *  t  )  [inline]

Definition at line 91 of file MercuryUtil.h.

long DumpFromFile ( const MString filename,
char *&  data 
)

Dump data from a file into a char * and return the size of data. If -1 then there was an error opening the file.

Definition at line 105 of file MercuryUtil.cpp.

bool DumpToFile ( const MString filename,
const char *  data,
long  bytes 
)

Dump data into the file filename. bytes specifies the length of data. Returns true if successful, false else.

Definition at line 128 of file MercuryUtil.cpp.

bool FileExists ( const MString filename  ) 

Definition at line 154 of file MercuryUtil.cpp.

void FileToMString ( const MString filename,
MString data 
)

Dump the contents of a file to data.

Definition at line 141 of file MercuryUtil.cpp.

int GetAPrime ( int  ith  ) 

Return a prime number. Note this is NOT sequential. The general(but not guarenteed) pattern is the next prime number that's roughly two times the last.

Definition at line 218 of file MercuryUtil.cpp.

int makePow2 ( int  x  )  [inline]

Definition at line 29 of file MercuryUtil.h.

void mercury_crash ( const char *  reason = "Internal error"  ) 

Force mercury to crash and write the reason at the top of the crashlog.

Definition at line 206 of file MercuryUtil.cpp.

void MStringToFile ( const MString filename,
const MString data 
)

Dump data into file.

Definition at line 149 of file MercuryUtil.cpp.

int nextPow2 ( int  x  )  [inline]

Definition at line 28 of file MercuryUtil.h.

void Sleep ( float  msec  ) 

Definition at line 9 of file MercuryUtil.cpp.

void SplitStrings ( const MString in,
MVector< MString > &  out,
const char *  termin,
const char *  whitespace,
long  termlen,
long  wslen 
)

Split given string into other strings using delimiters from termin.

Definition at line 190 of file MercuryUtil.cpp.

unsigned short Swap16 ( unsigned short  n  )  [inline]

Definition at line 85 of file MercuryUtil.h.

unsigned int Swap32 ( unsigned int  n  )  [inline]

Definition at line 77 of file MercuryUtil.h.


Hosted by SourceForge.net Logo