1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salunx.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
35 #if defined SCO || defined LINUX || defined HPUX || defined FREEBSD || defined NETBSD
51 // -=-= #defines -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
52 #define capacityof(a) (sizeof(a)/sizeof(*a))
54 // -=-= inlines =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
55 inline long Divide( long nDividend
, long nDivisor
)
56 { return (nDividend
+ nDivisor
/2) / nDivisor
; }
58 inline long DPI( long pixel
, long mm
)
59 { return Divide( pixel
*254, mm
*10 ); }
61 // -=-= timeval =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
62 inline int operator >= ( const timeval
&t1
, const timeval
&t2
)
64 if( t1
.tv_sec
== t2
.tv_sec
)
65 return t1
.tv_usec
>= t2
.tv_usec
;
66 return t1
.tv_sec
> t2
.tv_sec
;
69 inline int operator > ( const timeval
&t1
, const timeval
&t2
)
71 if( t1
.tv_sec
== t2
.tv_sec
)
72 return t1
.tv_usec
> t2
.tv_usec
;
73 return t1
.tv_sec
> t2
.tv_sec
;
76 inline int operator == ( const timeval
&t1
, const timeval
&t2
)
78 if( t1
.tv_sec
== t2
.tv_sec
)
79 return t1
.tv_usec
== t2
.tv_usec
;
83 inline timeval
&operator -= ( timeval
&t1
, const timeval
&t2
)
85 if( t1
.tv_usec
< t2
.tv_usec
)
88 t1
.tv_usec
+= 1000000;
90 t1
.tv_sec
-= t2
.tv_sec
;
91 t1
.tv_usec
-= t2
.tv_usec
;
95 inline timeval
&operator += ( timeval
&t1
, const timeval
&t2
)
97 t1
.tv_sec
+= t2
.tv_sec
;
98 t1
.tv_usec
+= t2
.tv_usec
;
99 if( t1
.tv_usec
> 1000000 )
102 t1
.tv_usec
-= 1000000;
107 inline timeval
&operator += ( timeval
&t1
, ULONG t2
)
109 t1
.tv_sec
+= t2
/ 1000;
110 t1
.tv_usec
+= t2
? (t2
% 1000) * 1000 : 500;
111 if( t1
.tv_usec
> 1000000 )
114 t1
.tv_usec
-= 1000000;
119 inline timeval
operator + ( const timeval
&t1
, const timeval
&t2
)
125 inline timeval
operator + ( const timeval
&t1
, ULONG t2
)
131 inline timeval
operator - ( const timeval
&t1
, const timeval
&t2
)