match_strval > try_val_to_str
[wireshark-wip.git] / wsutil / nstime.h
blob41685fd09b28586ffcbb7ffa553ae86a091e36bb
1 /* nstime.h
2 * Definition of data structure to hold time values with nanosecond resolution
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef __NSTIME_H__
26 #define __NSTIME_H__
28 #include <time.h>
30 #include "ws_symbol_export.h"
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
36 /** @file
37 * Definition of data structure to hold time values with nanosecond resolution
40 /** data structure to hold time values with nanosecond resolution*/
41 typedef struct {
42 time_t secs;
43 int nsecs;
44 } nstime_t;
46 /* functions */
48 /** set the given nstime_t to zero */
49 WS_DLL_PUBLIC void nstime_set_zero(nstime_t *nstime);
51 /** is the given nstime_t currently zero? */
52 WS_DLL_PUBLIC gboolean nstime_is_zero(nstime_t *nstime);
54 /** set the given nstime_t to (0,maxint) to mark it as "unset"
55 * That way we can find the first frame even when a timestamp
56 * is zero (fix for bug 1056)
58 WS_DLL_PUBLIC void nstime_set_unset(nstime_t *nstime);
60 /* is the given nstime_t currently (0,maxint)? */
61 WS_DLL_PUBLIC gboolean nstime_is_unset(nstime_t *nstime);
63 /** duplicate the current time
65 * a = b
67 WS_DLL_PUBLIC void nstime_copy(nstime_t *a, const nstime_t *b);
69 /** calculate the delta between two times (can be negative!)
71 * delta = b-a
73 * Note that it is acceptable for two or more of the arguments to point at the
74 * same structure.
76 WS_DLL_PUBLIC void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a );
78 /** calculate the sum of two times
80 * sum = a+b
82 * Note that it is acceptable for two or more of the arguments to point at the
83 * same structure.
85 WS_DLL_PUBLIC void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
87 /** sum += a */
88 #define nstime_add(sum, a) nstime_sum(sum, sum, a)
90 /** sum -= a */
91 #define nstime_subtract(sum, a) nstime_delta(sum, sum, a)
93 /** compare two times are return a value similar to memcmp() or strcmp().
95 * a > b : > 0
96 * a = b : 0
97 * a < b : < 0
99 WS_DLL_PUBLIC int nstime_cmp (const nstime_t *a, const nstime_t *b );
101 /** converts nstime to double, time base is milli seconds */
102 WS_DLL_PUBLIC double nstime_to_msec(const nstime_t *nstime);
104 /** converts nstime to double, time base is seconds */
105 WS_DLL_PUBLIC double nstime_to_sec(const nstime_t *nstime);
107 #ifdef __cplusplus
109 #endif /* __cplusplus */
111 #endif /* __NSTIME_H__ */