LCOV - code coverage report
Current view: top level - libreoffice/tools/inc/tools - solar.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 3 100.0 %
Date: 2012-12-27 Functions: 3 7 42.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _SOLAR_H
      21             : #define _SOLAR_H
      22             : 
      23             : #include <sal/types.h>
      24             : #include <osl/endian.h>
      25             : #include <comphelper/fileformat.h>
      26             : 
      27             : /** Intermediate type to solve type clash with Windows headers.
      28             :  Should be removed as soon as all code parts have been reviewed
      29             :  and the correct type is known. Most of the times ULONG is meant
      30             :  to be a 32-Bit unsigned integer type as sal_uInt32 is often
      31             :  used for data exchange or for similiar method args. */
      32             : typedef sal_uIntPtr    sal_uLong; /* Replaces type ULONG */
      33             : 
      34             : // misc. macros to leverage platform and compiler differences
      35             : 
      36             : #define DELETEZ( p )    ( delete p,p = 0 )
      37             : 
      38             : // solar binary types
      39             : 
      40             : /* Solar (portable) Binary (exchange) Type; OSI 6 subset
      41             :    always little endian;
      42             :    not necessarily aligned */
      43             : 
      44             : typedef sal_uInt8   SVBT8[1];
      45             : typedef sal_uInt8   SVBT16[2];
      46             : typedef sal_uInt8   SVBT32[4];
      47             : typedef sal_uInt8   SVBT64[8];
      48             : 
      49             : #ifdef __cplusplus
      50             : 
      51             : inline sal_uInt8  SVBT8ToByte  ( const SVBT8  p ) { return p[0]; }
      52             : inline sal_uInt16 SVBT16ToShort( const SVBT16 p ) { return (sal_uInt16)p[0]
      53             :                                                    + ((sal_uInt16)p[1] <<  8); }
      54             : inline sal_uInt32 SVBT32ToUInt32 ( const SVBT32 p ) { return (sal_uInt32)p[0]
      55             :                                                    + ((sal_uInt32)p[1] <<  8)
      56             :                                                    + ((sal_uInt32)p[2] << 16)
      57             :                                                    + ((sal_uInt32)p[3] << 24); }
      58             : #if defined OSL_LITENDIAN
      59             : inline double   SVBT64ToDouble( const SVBT64 p ) { double n;
      60             :                                                     ((sal_uInt8*)&n)[0] = p[0];
      61             :                                                     ((sal_uInt8*)&n)[1] = p[1];
      62             :                                                     ((sal_uInt8*)&n)[2] = p[2];
      63             :                                                     ((sal_uInt8*)&n)[3] = p[3];
      64             :                                                     ((sal_uInt8*)&n)[4] = p[4];
      65             :                                                     ((sal_uInt8*)&n)[5] = p[5];
      66             :                                                     ((sal_uInt8*)&n)[6] = p[6];
      67             :                                                     ((sal_uInt8*)&n)[7] = p[7];
      68             :                                                     return n; }
      69             : #else
      70             : inline double   SVBT64ToDouble( const SVBT64 p ) { double n;
      71             :                                                     ((sal_uInt8*)&n)[0] = p[7];
      72             :                                                     ((sal_uInt8*)&n)[1] = p[6];
      73             :                                                     ((sal_uInt8*)&n)[2] = p[5];
      74             :                                                     ((sal_uInt8*)&n)[3] = p[4];
      75             :                                                     ((sal_uInt8*)&n)[4] = p[3];
      76             :                                                     ((sal_uInt8*)&n)[5] = p[2];
      77             :                                                     ((sal_uInt8*)&n)[6] = p[1];
      78             :                                                     ((sal_uInt8*)&n)[7] = p[0];
      79             :                                                     return n; }
      80             : #endif
      81             : 
      82             : inline void     ByteToSVBT8  ( sal_uInt8   n, SVBT8 p ) { p[0] = n; }
      83             : inline void     ShortToSVBT16( sal_uInt16 n, SVBT16 p ) { p[0] = (sal_uInt8) n;
      84             :                                                       p[1] = (sal_uInt8)(n >>  8); }
      85             : inline void     UInt32ToSVBT32 ( sal_uInt32  n, SVBT32 p ) { p[0] = (sal_uInt8) n;
      86             :                                                       p[1] = (sal_uInt8)(n >>  8);
      87             :                                                       p[2] = (sal_uInt8)(n >> 16);
      88             :                                                       p[3] = (sal_uInt8)(n >> 24); }
      89             : #if defined OSL_LITENDIAN
      90             : inline void     DoubleToSVBT64( double n, SVBT64 p ) { p[0] = ((sal_uInt8*)&n)[0];
      91             :                                                        p[1] = ((sal_uInt8*)&n)[1];
      92             :                                                        p[2] = ((sal_uInt8*)&n)[2];
      93             :                                                        p[3] = ((sal_uInt8*)&n)[3];
      94             :                                                        p[4] = ((sal_uInt8*)&n)[4];
      95             :                                                        p[5] = ((sal_uInt8*)&n)[5];
      96             :                                                        p[6] = ((sal_uInt8*)&n)[6];
      97             :                                                        p[7] = ((sal_uInt8*)&n)[7]; }
      98             : #else
      99             : inline void     DoubleToSVBT64( double n, SVBT64 p ) { p[0] = ((sal_uInt8*)&n)[7];
     100             :                                                        p[1] = ((sal_uInt8*)&n)[6];
     101             :                                                        p[2] = ((sal_uInt8*)&n)[5];
     102             :                                                        p[3] = ((sal_uInt8*)&n)[4];
     103             :                                                        p[4] = ((sal_uInt8*)&n)[3];
     104             :                                                        p[5] = ((sal_uInt8*)&n)[2];
     105             :                                                        p[6] = ((sal_uInt8*)&n)[1];
     106             :                                                        p[7] = ((sal_uInt8*)&n)[0]; }
     107             : #endif
     108             : #endif
     109             : 
     110             : #ifndef __cplusplus
     111             : #ifndef min
     112             : #define min(a,b)    (((a) < (b)) ? (a) : (b))
     113             : #endif
     114             : #ifndef max
     115             : #define max(a,b)    (((a) > (b)) ? (a) : (b))
     116             : #endif
     117             : #endif
     118             : 
     119             : #ifdef __cplusplus
     120       79860 : template<typename T> inline T Min(T a, T b) { return (a<b?a:b); }
     121       79860 : template<typename T> inline T Max(T a, T b) { return (a>b?a:b); }
     122     1424997 : template<typename T> inline T Abs(T a) { return (a>=0?a:-a); }
     123             : #endif
     124             : 
     125             : #ifdef __cplusplus
     126             : #define EXTERN_C    extern "C"
     127             : #else
     128             : #define EXTERN_C
     129             : #endif
     130             : 
     131             : #define _LF     ((char)0x0A)
     132             : #define _CR     ((char)0x0D)
     133             : 
     134             : // pragmas
     135             : 
     136             : #if defined _MSC_VER
     137             : /* deletion of pointer to incomplete type '...'; no destructor called
     138             :  serious error, memory deleted without call of dtor */
     139             : #pragma warning( error: 4150 )
     140             : // warning C4002: too many actual parameters for macro
     141             : // warning C4003: not enough actual parameters for macro
     142             : #pragma warning(error : 4002 4003)
     143             : #endif
     144             : 
     145             : #define UniString       String
     146             : #define XubString       String
     147             : #define xub_StrLen      sal_uInt16
     148             : 
     149             : #define STRING_CONCAT3( s1, s2, s3 ) \
     150             :     s1 s2 s3
     151             : 
     152             : // dll file extensions
     153             : 
     154             : #if defined WNT
     155             : #define SVLIBRARY( Base ) \
     156             :     STRING_CONCAT3( Base, "lo", ".dll" )
     157             : #elif defined MACOSX
     158             : #define SVLIBRARY( Base ) \
     159             :     STRING_CONCAT3( "lib", Base, "lo.dylib" )
     160             : #elif defined UNX
     161             : #define SVLIBRARY( Base ) \
     162             :     STRING_CONCAT3( "lib", Base, "lo.so" )
     163             : #else
     164             :   #error unknown platform
     165             : #endif
     166             : 
     167             : #endif
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10