File: common.hh

package info (click to toggle)
xtide 2.9.5-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,996 kB
  • ctags: 2,141
  • sloc: cpp: 20,379; sh: 1,044; makefile: 224; yacc: 114; lex: 58
file content (192 lines) | stat: -rw-r--r-- 5,000 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// $Id: common.hh 2833 2007-12-01 01:27:02Z flaterco $
	
// Global includes for xtide, tide, and xttpd.

/*  Copyright (C) 2007  David Flater.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


// Need to define this to get inttypes.h to define the macros.
// SUSV3 says nothing about it; intttypes.h blames C99.
#define __STDC_FORMAT_MACROS

// Under Visual C++ 2008 Express Edition, this is needed to get M_PI etc.
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <sys/types.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_IO_H
#include <io.h>
#endif

#if HAVE_INTTYPES_H
#include <inttypes.h>
#elif HAVE_STDINT_H
#include <stdint.h>
#endif

// If we still didn't get the macros, take a guess.
#ifndef SCNx8
#define SCNx8 "hhx"
#endif


/*
  "Inevitably, the programmed validity checks of the defensive
  programming approach will result in run-time overheads and, where
  performance demands are critical, many checks are often removed from
  the operational software; their use is restricted to the testing
  phase where they can identify the misuse of components by faulty
  designs.  In the context of producing complex systems which can
  never be fully tested, this tendency to remove the protection
  afforded by programmed validity checks is most regrettable and is
  not recommended here." ---M. R. Moulding, "Designing for high
  integrity:  The software fault tolerance approach," Section 3.4.  In
  C. T. Sennett, ed., High-Integrity Software, Plenum Press, New York
  and London, 1989.
*/
#ifdef NDEBUG
#ifdef USE_PRAGMA_MESSAGE
#pragma message("WARNING:  NDEBUG is defined.  This configuration is unsupported and discouraged.")
#else
#warning NDEBUG is defined.  This configuration is unsupported and discouraged.
#endif
#endif

// In cases where the program relies on side-effects from what would
// be an assert expression, the following macro is used to ensure that
// the expression will be evaluated even if asserts are disabled.
#ifndef require
#define require(expr) {       \
  bool requireExpr ((expr));  \
  assert (requireExpr);       \
}
#endif


#ifdef UseGnuAttributes

#define unusedParameter  __attribute__ ((unused))
#define warnUnusedResult __attribute__ ((warn_unused_result))

#else

#define unusedParameter
#define warnUnusedResult

#endif


#include <assert.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <png.h>
#include <limits.h>

#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
// Syslog will not be called, but the following must be stubbed out.
#define LOG_ERR     3
#define LOG_WARNING 4
#define LOG_NOTICE  5
#define LOG_INFO    6
#endif


#include <set>
#include <list>
#include <algorithm>
#include <memory>
#include "SafeVector.hh"
#include "BetterMap.hh"


#if PNG_LIBPNG_VER < 96
#error Sorry, you must have libpng version 0.96 or newer.
#endif


// This must be done before including the XTide headers.
// The new configure script promises that we will have an int64_t.
// (YAY.)
#ifdef TIME_WORKAROUND
#define time_t int64_t
#endif

// A date is encoded as Year * 10000 + Month [1, 12] * 100 + Day [1, 31].
typedef unsigned long date_t;

// Since XTide now roams outside of the minimal 1970 to 2037 epoch,
// 32 bits no longer suffice.
typedef int64_t interval_rep_t;

typedef char const *                constCharPointer;
typedef char const * const          constString;
typedef char const * const *        constStringPointer;
typedef char const * const * const  constStringArray;


#if HAVE_LIBDSTR
#include <Dstr>
#else
#include "Dstr.hh"
#endif

#include "ModeFormat.hh"
#include "Units.hh"
#include "PredictionValue.hh"
#include "Configurable.hh"
#include "Errors.hh"
#include "Global.hh"
#include "Nullable.hh"
#include "MetaField.hh"
#include "NullablePredictionValue.hh"
#include "Colors.hh"
#include "Settings.hh"
#include "Amplitude.hh"
#include "Year.hh"
#include "Angle.hh"
#include "CurrentBearing.hh"
#include "Speed.hh"
#include "Interval.hh"
#include "NullableInterval.hh"
#include "Offsets.hh"
#include "Timestamp.hh"
#include "Date.hh"
#include "Coordinates.hh"
#include "StationRef.hh"
#include "Constituent.hh"
#include "ConstituentSet.hh"
#include "StationIndex.hh"
#include "TideEvent.hh"
#include "TideEventsOrganizer.hh"
#include "Station.hh"


#define DAYSECONDS 86400
#define HOURSECONDS 3600

// Cleanup2006 Done