MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbsleep_int.cc
Go to the documentation of this file.
1 /*
2  * MBDyn (C) is a multibody analysis code.
3  * http://www.mbdyn.org
4  *
5  * Copyright (C) 1996-2017
6  *
7  * Pierangelo Masarati <masarati@aero.polimi.it>
8  * Paolo Mantegazza <mantegazza@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  */
30 
31 #include "mbconfig.h"
32 
33 #include <stdlib.h>
34 
35 #include "myassert.h"
36 #include "mbsleep.h"
37 
38 #ifdef HAVE_NANOSLEEP
39 std::ostream&
40 operator << (std::ostream& out, const mbsleep_t& t)
41 {
42  out << t.tv_sec;
43  if (t.tv_nsec) {
44  out << '.' << t.tv_nsec;
45  }
46  return out;
47 }
48 
49 bool
50 operator < (const mbsleep_t& t1, const mbsleep_t& t2)
51 {
52  if (t1.tv_sec != t2.tv_sec) {
53  return t1.tv_sec < t2.tv_sec;
54  }
55  return t1.tv_nsec < t2.tv_nsec;
56 }
57 
58 bool
59 operator > (const mbsleep_t& t1, const mbsleep_t& t2)
60 {
61  if (t1.tv_sec != t2.tv_sec) {
62  return t1.tv_sec > t2.tv_sec;
63  }
64  return t1.tv_nsec > t2.tv_nsec;
65 }
66 
67 bool
68 operator <= (const mbsleep_t& t1, const mbsleep_t& t2)
69 {
70  if (t1.tv_sec != t2.tv_sec) {
71  return t1.tv_sec <= t2.tv_sec;
72  }
73  return t1.tv_nsec <= t2.tv_nsec;
74 }
75 
76 bool
77 operator >= (const mbsleep_t& t1, const mbsleep_t& t2)
78 {
79  if (t1.tv_sec != t2.tv_sec) {
80  return t1.tv_sec >= t2.tv_sec;
81  }
82  return t1.tv_nsec >= t2.tv_nsec;
83 }
84 
85 bool
86 operator == (const mbsleep_t& t1, const mbsleep_t& t2)
87 {
88  return (t1.tv_sec == t2.tv_sec) && (t1.tv_nsec == t2.tv_nsec);
89 }
90 
91 bool
92 operator != (const mbsleep_t& t1, const mbsleep_t& t2)
93 {
94  return (t1.tv_sec != t2.tv_sec) || (t1.tv_nsec != t2.tv_nsec);
95 }
96 
97 bool
98 operator < (const mbsleep_t& t1, const long& t2)
99 {
100  if (t1.tv_sec != t2) {
101  return t1.tv_sec < t2;
102  }
103  // NOTE: we assume that tv_nsec >= 0
104  ASSERT(t1.tv_nsec >= 0);
105  return false;
106 }
107 
108 bool
109 operator > (const mbsleep_t& t1, const long& t2)
110 {
111  if (t1.tv_sec != t2) {
112  return t1.tv_sec > t2;
113  }
114  return t1.tv_sec > 0;
115 }
116 
117 bool
118 operator <= (const mbsleep_t& t1, const long& t2)
119 {
120  if (t1.tv_sec != t2) {
121  return t1.tv_sec < t2;
122  }
123  // NOTE: we assume that tv_nsec >= 0
124  ASSERT(t1.tv_nsec >= 0);
125  return t1.tv_sec == 0;
126 }
127 
128 bool
129 operator >= (const mbsleep_t& t1, const long& t2)
130 {
131  if (t1.tv_sec != t2) {
132  return t1.tv_sec > t2;
133  }
134  return t1.tv_sec > 0;
135 }
136 
137 bool
138 operator == (const mbsleep_t& t1, const long& t2)
139 {
140  return (t1.tv_sec == t2) && (t1.tv_nsec == 0);
141 }
142 
143 bool
144 operator != (const mbsleep_t& t1, const long& t2)
145 {
146  return (t1.tv_sec != t2) || (t1.tv_nsec != 0);
147 }
148 
149 #endif // HAVE_NANOSLEEP
GradientExpression< BoolExpr< FuncLessEqual, LhsExpr, RhsExpr > > operator<=(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2966
GradientExpression< BoolExpr< FuncNotEqualTo, LhsExpr, RhsExpr > > operator!=(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2970
GradientExpression< BoolExpr< FuncEqualTo, LhsExpr, RhsExpr > > operator==(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2969
unsigned long mbsleep_t
Definition: mbsleep.h:51
GradientExpression< BoolExpr< FuncGreaterEqual, LhsExpr, RhsExpr > > operator>=(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2968
GradientExpression< BoolExpr< FuncLessThan, LhsExpr, RhsExpr > > operator<(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2965
GradientExpression< BoolExpr< FuncGreaterThan, LhsExpr, RhsExpr > > operator>(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2967
std::ostream & operator<<(std::ostream &out, const FullMatrixHandler &m)
Definition: fullmh.cc:352
#define ASSERT(expression)
Definition: colamd.c:977