Lolly 1.4.27
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
basic.hpp File Reference
#include "classdef.hpp"
#include "fast_alloc.hpp"
#include "minmax.hpp"
#include "tm_ostream.hpp"
#include <math.h>
Include dependency graph for basic.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  type_helper< T >
 Helper struct for type identification and initialization. More...
 

Macros

#define LESSGTR   <>
 Macro used for template specialization of less than and greater than operators.
 
#define MAX_SI   0x7fffffff
 
#define MIN_SI   0x80000000
 Macro defining the minimum value of a signed integer.
 
#define STACK_NEW_ARRAY(name, T, size)   T name[size]
 
#define STACK_DELETE_ARRAY(name)
 
#define USE_EXCEPTIONS
 Macro used to enable or disable the use of exceptions.
 
#define ASSERT(cond, msg)
 Macro used to assert that a condition is true, and throw an exception with an error message if the condition is false.
 
#define TM_FAILED(msg)    { tm_throw (msg); }
 Macro used to throw an exception with a specified error message.
 

Typedefs

typedef voidpointer
 
typedef unsigned int color
 

Enumerations

enum  display_control { INDENT , UNINDENT , HRULE , LF }
 Enumeration of display control options. More...
 

Functions

void tm_failure (const char *msg)
 Function used to handle a TM failure by displaying an error message and exiting the program.
 
void tm_throw (const char *msg)
 Function used to throw an exception with a specified error message.
 
void handle_exceptions ()
 Function used to handle exceptions by displaying and clearing the exception message.
 
int hash (int i)
 Hashes an integer.
 
int hash (long int i)
 Hashes a long integer.
 
int hash (DI i)
 Hashes a double integer.
 
int hash (unsigned int i)
 Hashes an unsigned integer.
 
int hash (unsigned long int i)
 Hashes an unsigned long integer.
 
int hash (DN i)
 Hashes a double number.
 
int hash (float x)
 Hashes a float number.
 
int hash (double x)
 Hashes a double number.
 
int copy (int x)
 Returns a copy of an integer.
 
SI as_int (double x)
 Converts a double to a signed integer, rounding to the nearest integer.
 
double tm_round (double x)
 Rounds a double to the nearest integer.
 
int hash (pointer ptr)
 Computes a hash value for a pointer.
 
tm_ostreamoperator<< (tm_ostream &out, display_control ctrl)
 Output operator for display control options.
 
int new_type_identifier ()
 Generates a new type identifier.
 

Variables

string the_exception
 Global variable used to store the current exception message.
 

Detailed Description

defines basic types and macros used throughout the kernel.

Author
Joris van der Hoeven
Date
1999

Definition in file basic.hpp.

Macro Definition Documentation

◆ LESSGTR

#define LESSGTR   <>

Macro used for template specialization of less than and greater than operators.

Definition at line 22 of file basic.hpp.

◆ MAX_SI

#define MAX_SI   0x7fffffff

Definition at line 27 of file basic.hpp.

◆ MIN_SI

#define MIN_SI   0x80000000

Macro defining the minimum value of a signed integer.

Definition at line 32 of file basic.hpp.

◆ STACK_NEW_ARRAY

#define STACK_NEW_ARRAY ( name,
T,
size )   T name[size]

Definition at line 43 of file basic.hpp.

◆ STACK_DELETE_ARRAY

#define STACK_DELETE_ARRAY ( name)

Definition at line 44 of file basic.hpp.

◆ USE_EXCEPTIONS

#define USE_EXCEPTIONS

Macro used to enable or disable the use of exceptions.

Definition at line 50 of file basic.hpp.

◆ ASSERT

#define ASSERT ( cond,
msg )
Value:
{ \
if (!(cond)) tm_throw (msg); \
}
void tm_throw(const char *msg)
Function used to throw an exception with a specified error message.
Definition basic.cpp:27
The list class represents a linked list.
Definition list.hpp:48

Macro used to assert that a condition is true, and throw an exception with an error message if the condition is false.

Definition at line 85 of file basic.hpp.

85#define ASSERT(cond, msg) \
86 { \
87 if (!(cond)) tm_throw (msg); \
88 }

◆ TM_FAILED

#define TM_FAILED ( msg)     { tm_throw (msg); }

Macro used to throw an exception with a specified error message.

Definition at line 93 of file basic.hpp.

93#define TM_FAILED(msg) \
94 { tm_throw (msg); }

Typedef Documentation

◆ pointer

Definition at line 24 of file basic.hpp.

◆ color

Definition at line 25 of file basic.hpp.

Enumeration Type Documentation

◆ display_control

Enumeration of display control options.

Enumerator
INDENT 
UNINDENT 
HRULE 
LF 

Definition at line 287 of file basic.hpp.

287{ INDENT, UNINDENT, HRULE, LF };
@ UNINDENT
Definition basic.hpp:287
@ LF
Definition basic.hpp:287
@ HRULE
Definition basic.hpp:287
@ INDENT
Definition basic.hpp:287

Function Documentation

◆ tm_failure()

void tm_failure ( const char * msg)

Function used to handle a TM failure by displaying an error message and exiting the program.

Parameters
msgThe error message to display.

◆ tm_throw()

void tm_throw ( const char * msg)

Function used to throw an exception with a specified error message.

Parameters
msgThe error message to throw with the exception.

Definition at line 27 of file basic.cpp.

27 {
29 // the_report = get_crash_report (msg);
30 cout << "Throwing " << msg << LF;
31 cout << "-------------------------------------------------\n";
32 cout << the_report << LF;
33 cout << "-------------------------------------------------\n";
34 throw string (msg);
35}
string the_exception
Global variable used to store the current exception message.
Definition basic.cpp:22
string the_report
Definition basic.cpp:23
tm_ostream & cout

◆ handle_exceptions()

void handle_exceptions ( )

Function used to handle exceptions by displaying and clearing the exception message.

Note
if catching an exception throwed by tm_throw, this function must be appended after catch(){...} block.

Definition at line 38 of file basic.cpp.

38 {
39 if (N (the_exception) != 0) {
40 // formatted arg (verbatim_to_tree (the_report, false, "utf-8"));
41 // failed_error << "Exception, " << the_exception << arg << LF;
42 the_exception= "";
43 the_report = "";
44 }
45}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170

◆ hash() [1/9]

int hash ( int i)
inline

Hashes an integer.

Parameters
iThe integer to hash.
Returns
The hashed value of the integer.

Definition at line 151 of file basic.hpp.

151 {
152 return i;
153}

◆ hash() [2/9]

int hash ( long int i)
inline

Hashes a long integer.

Parameters
iThe long integer to hash.
Returns
The hashed value of the long integer.

Definition at line 162 of file basic.hpp.

162 {
163 return (int) i;
164}

◆ hash() [3/9]

int hash ( DI i)
inline

Hashes a double integer.

Parameters
iThe double integer to hash.
Returns
The hashed value of the double integer.

Definition at line 173 of file basic.hpp.

173 {
174 return (int) i;
175}

◆ hash() [4/9]

int hash ( unsigned int i)
inline

Hashes an unsigned integer.

Parameters
iThe unsigned integer to hash.
Returns
The hashed value of the unsigned integer.

Definition at line 184 of file basic.hpp.

184 {
185 return i;
186}

◆ hash() [5/9]

int hash ( unsigned long int i)
inline

Hashes an unsigned long integer.

Parameters
iThe unsigned long integer to hash.
Returns
The hashed value of the unsigned long integer.

Definition at line 195 of file basic.hpp.

195 {
196 return (int) i;
197}

◆ hash() [6/9]

int hash ( DN i)
inline

Hashes a double number.

Parameters
xThe double number to hash.
Returns
The hashed value of the double number.

Definition at line 206 of file basic.hpp.

206 {
207 return (int) i;
208}

◆ hash() [7/9]

int hash ( float x)
inline

Hashes a float number.

Parameters
xThe float numberto hash.
Returns
The hashed value of the float number.

Definition at line 217 of file basic.hpp.

217 {
218 union {
219 int n;
220 float d;
221 } u;
222 u.d= x;
223 return u.n & 0xffffffff;
224}

◆ hash() [8/9]

int hash ( double x)
inline

Hashes a double number.

Parameters
xThe double number to hash.
Returns
The hashed value of the double number.

Definition at line 233 of file basic.hpp.

233 {
234 union {
235 DI n;
236 double d;
237 } u;
238 u.d= x;
239 return (int) (u.n ^ (u.n >> 32));
240}
long long int DI
Definition minmax.hpp:16

◆ copy()

int copy ( int x)
inline

Returns a copy of an integer.

Parameters
xThe integer to copy.
Returns
A copy of the integer.

Definition at line 249 of file basic.hpp.

249 {
250 return x;
251}

◆ as_int()

SI as_int ( double x)
inline

Converts a double to a signed integer, rounding to the nearest integer.

Parameters
xThe double to convert.
Returns
The converted signed integer.

Definition at line 261 of file basic.hpp.

261 {
262 return (SI) floor (x + 0.5);
263}
int SI
Definition minmax.hpp:10

◆ tm_round()

double tm_round ( double x)
inline

Rounds a double to the nearest integer.

Parameters
xThe double to round.
Returns
The rounded double.

Definition at line 272 of file basic.hpp.

272 {
273 return floor (x + 0.5);
274}

◆ hash() [9/9]

int hash ( pointer ptr)

Computes a hash value for a pointer.

Parameters
ptrThe pointer to hash.
Returns
The hash value.

Definition at line 17 of file basic.cpp.

17 {
18 return ((int) ((intptr_t) ptr)) + (((int) ((intptr_t) ptr)) % 19);
19}

◆ operator<<()

Output operator for display control options.

Parameters
outThe output stream to write to.
ctrlThe display control option.
Returns
The output stream.

Definition at line 61 of file basic.cpp.

62 {
63 int i;
64 switch (ctrl) {
65 case INDENT:
66 out << " ";
68 break;
69 case UNINDENT:
70 out << "\b\b";
72 break;
73 case HRULE:
74 for (i= current_indent; i < 78; i++)
75 out << "-";
76 case LF:
77 out << "\n";
78 for (i= 0; i < current_indent; i++)
79 out << " ";
80 break;
81 }
82 return out;
83}
static int current_indent
Definition basic.cpp:59

◆ new_type_identifier()

int new_type_identifier ( )

Generates a new type identifier.

Returns
The new type identifier.

Definition at line 53 of file basic.cpp.

53 {
54 static int id= 0;
55 id--;
56 return id;
57}

Variable Documentation

◆ the_exception

string the_exception
extern

Global variable used to store the current exception message.

Definition at line 22 of file basic.cpp.