first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / basis / definitions.h
1 #ifndef DEFINITIONS_GROUP
2 #define DEFINITIONS_GROUP
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : definitions                                                       *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 //! @file "definitions.h" Constants and objects used throughout HOOPLE.
19 /*! @file
20   Defines a set of useful universal constants (for our chosen universe) and
21   a set of aliases for convenient abstract and concrete data types.
22   This is the lowest-level header in hoople and should not include any others.
23 */
24
25 namespace basis {
26
27 //////////////
28
29 // Constants...
30
31 //! The value representing a pointer to nothing, or nothing itself.
32 #define NIL 0
33
34 //! A fundamental constant measuring the number of bits in a byte.
35 #define BITS_PER_BYTE 8
36
37 //! An approximation of the fundamental circular constant.
38 #define PI_APPROX 3.14159265358
39
40 //////////////
41
42 // Data Structures & Functions
43
44 //! This macro just eats what it's passed; it marks unused formal parameters.
45 #define formal(parameter)
46
47 //! A fairly important unit which is seldom defined...
48 typedef unsigned char abyte;
49 /* ridiculous!  all to shut microsoft up about ambiguous byte definitions,
50 which seems like a bug. 
51 struct byte {
52   byte(unsigned char b = 0) : c_data(b) {}
53 //  byte(char b) : c_data(b) {}
54   operator unsigned char() const { return c_data; }
55   operator char() const { return c_data; }
56   operator int() const { return c_data; }
57   operator unsigned int() const { return c_data; }
58   operator bool() const { return (bool)c_data; }
59   byte operator &(byte and_with) { return c_data & and_with; }
60   byte operator |(byte or_with) { return c_data & or_with; }
61   unsigned char c_data;
62 };
63 */
64
65 #if defined(UNICODE) && defined(__WIN32__)
66   //! the flexichar type is always appropriate to hold data for win32 calls.
67   typedef wchar_t flexichar;
68 #else
69   // this version simply defangs any conversions.
70   typedef char flexichar;
71 #endif
72
73 //! Abbreviated name for unsigned integers.
74 typedef unsigned int un_int;
75 //! Abbreviated name for unsigned short integers.
76 typedef unsigned short un_short;
77 //! Abbreviated name for unsigned long integers.
78 typedef unsigned long un_long;
79
80 // some maximum and minimum values that are helpful.
81 #ifndef MAXINT32
82   //! Maximum 32-bit integer value.
83   #define MAXINT32 0x7fffffff
84 #endif
85 #ifndef MININT32
86   //! Minimum 32-bit integer value.
87   #define MININT32 0x80000000
88 #endif
89 #ifndef MAXINT16
90   //! Maximum 32-bit integer value.
91   #define MAXINT16 0x7fff
92 #endif
93 #ifndef MININT16
94   //! Minimum 32-bit integer value.
95   #define MININT16 0x8000
96 #endif
97 #ifndef MAXCHAR
98   //! Maximum byte-based character value.
99   #define MAXCHAR 0x7f
100 #endif
101 #ifndef MINCHAR
102   //! Minimum byte-based character value.
103   #define MINCHAR 0x80
104 #endif
105 #ifndef MAXBYTE
106   //! Maximum unsigned byte value.
107   #define MAXBYTE 0xff
108 #endif
109 #ifndef MINBYTE
110   //! Minimum unsigned byte value.
111   #define MINBYTE 0x00
112 #endif
113
114 // Provide definitions for integers with platform independent specific sizes.
115 // Note that these may have to be adjusted for 64 bit platforms.
116 typedef char int8;
117 typedef unsigned char uint8;
118 typedef signed short int16;
119 typedef unsigned short uint16;
120 typedef signed int int32;
121 typedef unsigned int uint32;
122
123 //////////////
124
125 // useful time constants.
126
127 // the _ms suffix indicates that these are measured in milliseconds.
128 const int SECOND_ms = 1000;  //!< Number of milliseconds in a second.
129 const int MINUTE_ms = 60 * SECOND_ms;  //!< Number of milliseconds in a minute.
130 const int HOUR_ms = 60 * MINUTE_ms;  //!< Number of milliseconds in an hour.
131 const int DAY_ms = 24 * HOUR_ms;  //!< Number of milliseconds in a day.
132
133 // the _s suffix indicates that these are measured in seconds.
134 const int MINUTE_s = 60;  //!< Number of seconds in a minute.
135 const int HOUR_s = 60 * MINUTE_s;  //!< Number of seconds in an hour.
136 const int DAY_s = 24 * HOUR_s;  //!< Number of seconds in a day.
137
138 //////////////
139
140 // useful general constants.
141
142 const int KILOBYTE = 1024;  //!< Number of bytes in a kilobyte.
143 const int MEGABYTE = KILOBYTE * KILOBYTE;  //!< Number of bytes in a megabyte.
144 const int GIGABYTE = MEGABYTE * KILOBYTE;  //!< Number of bytes in a gigabyte.
145 const double TERABYTE = double(GIGABYTE) * double(KILOBYTE);
146 //double TERABYTE() { return double(GIGABYTE) * double(KILOBYTE); }
147   //!< Number of bytes in a terabyte.
148 //  /*!< Implemented as a function to avoid annoying link errors for double
149 //  floating point constants in some compilers. */
150
151 //////////////
152
153 // Super basic objects...
154
155 //! lowest level object for all hoople objects.  supports run-time type id.
156
157 class root_object
158 {
159 public:
160   virtual ~root_object() {}
161 };
162
163 //////////////
164
165 // compiler specific dumping ground for global settings...
166
167 #ifdef _MSC_VER
168   // turns off annoying complaints from visual c++.
169   #pragma warning(disable : 4251 4275 4003 4800 4355 4786 4290 4996 4407)
170   #pragma warning(error : 4172)
171     // 4251 and 4275 turn off warnings regarding statically linked code
172     //    not being marked with dll import/export flags.
173     // 4003 turns off warnings about insufficient number of parameters passed
174     //    to a macro.
175     // 4800 turns off the warning about conversion from int to bool not being
176     //    efficient.
177     // 4355 turns off the warning re 'this' used in base member init list.
178     // 4786 turns off the warning about 'identifier' truncated to 'number'
179     //    characters in the debug information which frequenly happens when
180     //    STL pair and set templates are expanded.
181     // 4172 is made an error because this warning is emitted for a dangerous
182     //    condition; the address of a local variable is being returned, making
183     //    the returned object junk in almost all cases.
184     // 4996 turns off warnings about deprecated functions, which are mostly
185     //    bullshit, since these are mainly the core posix functions.
186 #endif  // ms visual c++.
187
188 //////////////
189
190 } //namespace.
191
192 #endif // outer guard.
193