Home Libraries Author Links

basetype.h

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the SysToMath C Libraries package (LibStmC).
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Tom Michaelis, SysToMath.
00018  * Portions created by the Initial Developer are Copyright (C) 1990-2007
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /******************************************************************************
00038  *                            First Release 1990-10-13
00039  ******************************************************************************/
00040 
00041 
00082 #ifndef STM_BASETYPE_H
00083 #define STM_BASETYPE_H
00084 
00085 
00086 /* Include header files and macro definitions. */
00087 #include <stm/internal/_basetype.h>
00088 
00089 
00094 #ifdef STM_DOXYGEN
00095 
00100 #define __BIG_ENDIAN 4321
00101 
00104 #define __LITTLE_ENDIAN 1234
00105 
00108 #define __BYTE_ORDER __LITTLE_ENDIAN
00109 
00111 #endif  /* STM_DOXYGEN */
00112 
00113 
00119 typedef unsigned char StmByte;
00120 
00123 typedef unsigned char StmUint8;
00124 
00127 typedef signed char StmInt8;
00128 
00131 typedef StmByte *StmAddr;
00132 
00133 /* \} */
00134 
00135 
00141 typedef unsigned short int StmWord;
00142 
00145 typedef unsigned short int StmUint16;
00146 
00149 typedef short int StmInt16;
00150 
00151 /* \} */
00152 
00153 
00159 typedef unsigned int StmDword;
00160 
00163 typedef unsigned int StmUint32;
00164 
00167 typedef int StmInt32;
00168 
00169 /* \} */
00170 
00171 
00175 #ifdef __alpha
00176     typedef unsigned long int StmQword;
00177     typedef unsigned long int StmUint64;
00178     typedef long int StmInt64;
00179 
00180 #elif defined _MSC_VER && _MSC_VER < 1310
00181 
00182     typedef unsigned __int64 StmQword;
00183     typedef unsigned __int64 StmUint64;
00184     typedef __int64 StmInt64;
00185     typedef long intptr_t;
00186 
00187 #else
00188 
00191     typedef unsigned long long int StmQword;
00192 
00195     typedef unsigned long long int StmUint64;
00196 
00199     typedef long long int StmInt64;
00200 #endif
00201 
00202 /* \} */
00203 
00204 
00208 /* \{ */
00209 
00212 #define StmFalse 0
00213 
00216 #define StmTrue  1
00217 
00220 typedef int StmBool;
00221 
00222 /* \} */
00223 
00224 
00247 #define StmAbstractType(Type)                                                 \
00248 typedef struct Type##Impl_ Type##Impl_;                                       \
00249 typedef Type##Impl_ *Type;                                                    \
00250 typedef const Type##Impl_ *Const##Type;
00251 
00252 
00269 #define StmAbstractTypeDefine(Type)                                           \
00270 typedef Type##Impl_ *Type;                                                    \
00271 typedef const Type##Impl_ *Const##Type;
00272 
00273 /* \} */
00274 
00275 
00279 /* \{ */
00280 
00285 #define StmAlignUnits(n)     (((n) + sizeof (StmAlign) - 1) / sizeof (StmAlign))
00286 
00291 #define StmTypeAlignUnits(Type)  (StmAlignUnits (sizeof (Type)))
00292 
00295 typedef long StmAlign;
00296 
00297 /* \} */
00298 
00299 
00303 /* \{ */
00304 
00307 #define StmSizeofMember(agg, mem)  (sizeof (((agg *) NULL) -> mem))
00308 
00311 #define StmElements(vector)      (sizeof (vector) / sizeof (vector [0]))
00312 
00315 #define StmCharBits             CHAR_BIT
00316 
00319 #define StmByteBits             StmCharBits
00320 
00323 #define StmUshortBits           (sizeof (unsigned short int) * StmByteBits)
00324 
00327 #define StmShortBits            StmUshortBits
00328 
00331 #define StmUintBits             (sizeof (unsigned int) * StmByteBits)
00332 
00335 #define StmIntBits              StmUintBits
00336 
00339 #define StmUlongIntBits         (sizeof (unsigned long int) * StmByteBits)
00340 
00343 #define StmLongIntBits          StmUlongIntBits
00344 
00347 #define StmBytesForBits(n)      (((n) + StmByteBits - 1) / StmByteBits)
00348 
00351 #define StmTwoToThe(nth)        ((size_t) 1 << (nth))
00352 
00355 #define StmId(key)                                                             \
00356 (StmDword) (#key [0] ?                                                         \
00357             #key [1] ?                                                         \
00358             #key [2] ?                                                         \
00359             #key [3] ?                                                         \
00360             #key [3] + 256 * (#key [2] + 256 * (#key [1] + 256 * #key [0])) :  \
00361             #key [2] + 256 * (#key [1] + 256 * #key [0]) :                     \
00362             #key [1] + 256 * #key [0] :                                        \
00363             #key [0] :                                                         \
00364             0)
00365 
00368 #define StmIdx(key)                                                            \
00369 (StmDword) (key [0] ?                                                          \
00370             key [1] ?                                                          \
00371             key [2] ?                                                          \
00372             key [3] ?                                                          \
00373             key [3] + 256 * (key [2] + 256 * (key [1] + 256 * key [0])) :      \
00374             key [2] + 256 * (key [1] + 256 * key [0]) :                        \
00375             key [1] + 256 * key [0] :                                          \
00376             key [0] :                                                          \
00377             0)
00378 
00379 /* \} */
00380 
00381 
00416 /* \{ */
00417 
00421 #define StmDeclareFlagField(name, beginBit, bitLength)                         \
00422 name##Begin  = (beginBit),                                                     \
00423 name##Length = (bitLength),                                                    \
00424 name##End    = ((beginBit) + (bitLength)),                                     \
00425 name         = ((((size_t) 1 << (bitLength)) - 1) << (beginBit))
00426 
00429 #define StmGetFlagField(variable, name)                                        \
00430 (((variable) & name) >> name##Begin)
00431 
00434 #define StmSetFlagField(variable, name, value)                                 \
00435 do                                                                             \
00436 {                                                                              \
00437     (variable) &= ~name; (variable) |= ((value) << name##Begin) & name;        \
00438 }                                                                              \
00439 while (0)
00440 
00443 #define StmDeclareFlag(name, beginBit)                                         \
00444 StmDeclareFlagField (name, beginBit, 1)
00445 
00448 #define StmGetFlag(variable, name)                                             \
00449 (StmGetFlagField (variable, name))
00450 
00453 #define StmSetFlag(variable, name, value)                                      \
00454 StmSetFlagField (variable, name, (value))
00455 
00456 /* \} */
00457 
00458 
00462 #endif  /* STM_BASETYPE_H */

© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).