0030679: Attached model hangs most of OCCT common functionality
[occt.git] / src / OSD / OSD.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
42cf5bc1 15#include <OSD.hxx>
7fd59977 16
7fd59977 17// Convert Real to CString in format e with 16 significant digits.
18// The decimal point character is always a period.
19// The conversion is independant from current locale database
20
21Standard_Boolean OSD::RealToCString(const Standard_Real aReal,
22 Standard_PCharacter& aString)
23{
24 char *p, *q ;
25
91322f44 26 if (Sprintf(aString,"%.17e",aReal) <= 0) //BUC60808
7fd59977 27 return Standard_False ;
28
7fd59977 29 // Suppress "e+00" and unsignificant 0's
30
302f96fb 31 p = strchr(aString,'e');
32 if (p) {
7fd59977 33 if (!strcmp(p,"e+00"))
34 *p = 0 ;
35 for (q = p-1 ; *q == '0' ; q--) ;
36 if (q != p-1) {
37 if (*q != '.') q++ ;
38 while (*p)
39 *q++ = *p++ ;
40 *q = 0 ;
41 }
42 }
43 return Standard_True ;
44}
45
46// Make the RealToCString reciprocal conversion.
47
48Standard_Boolean OSD::CStringToReal(const Standard_CString aString,
49 Standard_Real& aReal)
50{
7fd59977 51 char *endptr ;
91322f44 52 aReal = Strtod(aString, &endptr);
7fd59977 53 if (*endptr)
54 return Standard_False ;
55 return Standard_True;
56}
57
58//=======================================================================
59//function : OSDSecSleep
60//purpose : Cause the process to sleep during a amount of seconds
61//=======================================================================
62
57c28b61 63#ifdef _WIN32
5fecc495 64# include <windows.h>
7fd59977 65# define SLEEP(NSEC) Sleep(1000*(NSEC))
66#else
03155c18 67#include <unistd.h>
cda9a0d4 68# define SLEEP(NSEC) sleep(NSEC)
7fd59977 69#endif
70
71void OSD::SecSleep(const Standard_Integer aDelay)
72{
73 SLEEP(aDelay);
74}
75
76//=======================================================================
77//function : MilliSecSleep
78//purpose : Cause the process to sleep during a amount of milliseconds
79//=======================================================================
80
03155c18 81#ifdef _WIN32
7fd59977 82
83void OSD::MilliSecSleep(const Standard_Integer aDelay)
84{
85 Sleep(aDelay) ;
86}
87
88#else
89
03155c18 90#include <sys/time.h>
7fd59977 91
92void OSD::MilliSecSleep(const Standard_Integer aDelay)
93{
7fd59977 94 struct timeval timeout ;
95
96 timeout.tv_sec = aDelay / 1000 ;
97 timeout.tv_usec = (aDelay % 1000) * 1000 ;
98
96a95605 99 select(0,NULL,NULL,NULL,&timeout) ;
7fd59977 100}
101
102#endif