libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
util.h
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library 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 GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// (c) COPYRIGHT URI/MIT 1994-1999
27// Please read the full copyright statement in the file COPYRIGHT.
28//
29// Authors:
30// jhrg,jimg James Gallagher (jgallagher@gso.uri.edu)
31
32// declarations for utility functions
33//
34// jhrg 9/21/94
35
36#ifndef _util_h
37#define _util_h 1
38
39#include <cmath>
40#include <cstdio>
41#include <vector>
42
43#ifndef _basetype_h
44#include "BaseType.h"
45#endif
46
47using std::iostream;
48
49namespace libdap {
50
51class Array;
52
54inline bool double_eq(double lhs, double rhs, double epsilon = 1.0e-5) { return fabs(lhs - rhs) < epsilon; }
55
56string extract_string_argument(BaseType *arg);
57double extract_double_value(BaseType *arg);
58double *extract_double_array(Array *a);
59void extract_double_array(Array *a, vector<double> &dest);
60void set_array_using_double(Array *dest, double *src, int src_len);
61
63
64string prune_spaces(const string &);
65bool unique_names(vector<BaseType *> l, const string &var, const string &type, string &msg);
66string systime();
67const char *libdap_root();
68extern "C" const char *libdap_version();
69extern "C" const char *libdap_name();
70
71#ifdef WIN32
72void flush_stream(iostream ios, FILE *out);
73#endif
74
75void downcase(string &s);
76bool is_quoted(const string &s);
77string remove_quotes(const string &s);
78
79Type get_type(const char *name);
80string D2type_name(Type t);
81string D4type_name(Type t);
82string type_name(Type t);
83bool is_simple_type(Type t);
84bool is_vector_type(Type t);
85bool is_constructor_type(Type t);
86bool is_integer_type(Type t);
87
88bool dir_exists(const string &dir);
89
90// Jose Garcia
121void append_long_to_string(long val, int base, string &str_val);
122string long_to_string(long val, int base = 10);
124
125// Jose Garcia
139void append_double_to_string(const double &num, string &str);
140string double_to_string(const double &num);
142
143string path_to_filename(string path);
144int glob(const char *c, const char *s);
145time_t parse_time(const char *str, bool expand);
146bool size_ok(unsigned int sz, unsigned int nelem);
147bool pathname_ok(const string &path, bool strict = true);
148string dap_version();
149string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix = "");
150
151} // namespace libdap
152
153#endif
A multidimensional array of identical data types.
Definition Array.h:121
top level DAP object to house generic methods
Definition AISConnect.cc:30
string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix)
Definition util.cc:1214
const char * libdap_name()
Definition util.cc:517
string long_to_string(long val, int base)
Definition util.cc:946
bool size_ok(unsigned int sz, unsigned int nelem)
sanitize the size of an array. Test for integer overflow when dynamically allocating an array.
Definition util.cc:1138
string remove_quotes(const string &s)
Definition util.cc:562
void append_double_to_string(const double &num, string &str)
Definition util.cc:953
string path_to_filename(string path)
Definition util.cc:988
bool is_host_big_endian()
Does this host use big-endian byte order?
Definition util.cc:94
const char * libdap_version()
Definition util.cc:511
double extract_double_value(BaseType *arg)
Definition util.cc:395
string prune_spaces(const string &name)
Definition util.cc:451
string type_name(Type t)
Definition util.cc:753
void append_long_to_string(long val, int base, string &str_val)
Definition util.cc:919
void set_array_using_double(Array *dest, double *src, int src_len)
Definition util.cc:164
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
Definition util.cc:766
bool dir_exists(const string &dir)
Definition util.cc:912
bool pathname_ok(const string &path, bool strict)
Does the string name a potentially valid pathname? Test the given pathname to verify that it is a val...
Definition util.cc:1156
string double_to_string(const double &num)
Definition util.cc:962
bool double_eq(double lhs, double rhs, double epsilon=1.0e-5)
Definition util.h:54
void downcase(string &s)
Definition util.cc:544
string D2type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP2 types and not the DAP4-only typ...
Definition util.cc:644
const char * libdap_root()
Definition util.cc:505
string D4type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP4 types and not the DAP2-only typ...
Definition util.cc:688
string systime()
Definition util.cc:524
bool is_constructor_type(Type t)
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
Definition util.cc:848
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
Definition util.cc:805
bool is_integer_type(Type t)
Definition util.cc:888
time_t parse_time(const char *str, bool expand)
Definition util_mit.cc:144
int glob(const char *c, const char *s)
Definition util.cc:1049
string extract_string_argument(BaseType *arg)
Definition util.cc:118
ObjectType get_type(const string &value)
Definition mime_util.cc:300
double * extract_double_array(Array *a)
Definition util.cc:257
bool is_quoted(const string &s)
Definition util.cc:554
bool unique_names(vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
Definition util.cc:472
string dap_version()
Definition util.cc:1198