Blame util.h

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1994-1999
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//      jhrg,jimg       James Gallagher (jgallagher@gso.uri.edu)
Packit a4aae4
Packit a4aae4
// declarations for utility functions
Packit a4aae4
//
Packit a4aae4
// jhrg 9/21/94
Packit a4aae4
Packit a4aae4
#ifndef _util_h
Packit a4aae4
#define _util_h 1
Packit a4aae4
Packit a4aae4
#include <cstdio>
Packit a4aae4
#include <cmath>
Packit a4aae4
#include <vector>
Packit a4aae4
Packit a4aae4
#ifndef _basetype_h
Packit a4aae4
#include "BaseType.h"
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
using std::iostream;
Packit a4aae4
Packit a4aae4
namespace libdap
Packit a4aae4
{
Packit a4aae4
Packit a4aae4
class Array;
Packit a4aae4
Packit a4aae4
/** Is \e lhs equal to \e rhs? Use epsilon to determine equality. */
Packit a4aae4
inline bool double_eq(double lhs, double rhs, double epsilon = 1.0e-5)
Packit a4aae4
{
Packit a4aae4
    return fabs(lhs - rhs) < epsilon;
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
string extract_string_argument(BaseType *arg) ;
Packit a4aae4
double extract_double_value(BaseType *arg) ;
Packit a4aae4
double *extract_double_array(Array *a) ;
Packit a4aae4
void extract_double_array(Array *a, vector<double> &dest) ;
Packit a4aae4
void set_array_using_double(Array *dest, double *src, int src_len) ;
Packit a4aae4
Packit a4aae4
bool is_host_big_endian();
Packit a4aae4
Packit a4aae4
string prune_spaces(const string &);
Packit a4aae4
bool unique_names(vector<BaseType *> l, const string &var, const string &type, string &msg;;
Packit a4aae4
string systime();
Packit a4aae4
const char *libdap_root();
Packit a4aae4
extern "C" const char *libdap_version();
Packit a4aae4
extern "C" const char *libdap_name();
Packit a4aae4
Packit a4aae4
#ifdef WIN32
Packit a4aae4
void flush_stream(iostream ios, FILE *out);
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
void downcase(string &s);
Packit a4aae4
bool is_quoted(const string &s);
Packit a4aae4
string remove_quotes(const string &s);
Packit a4aae4
Packit a4aae4
Type get_type(const char *name);
Packit a4aae4
string D2type_name(Type t);
Packit a4aae4
string D4type_name(Type t);
Packit a4aae4
string type_name(Type t);
Packit a4aae4
bool is_simple_type(Type t);
Packit a4aae4
bool is_vector_type(Type t);
Packit a4aae4
bool is_constructor_type(Type t);
Packit a4aae4
bool is_integer_type(Type t);
Packit a4aae4
Packit a4aae4
bool dir_exists(const string &dir;;
Packit a4aae4
Packit a4aae4
// Jose Garcia
Packit a4aae4
/** @name Integer to string conversion functions
Packit a4aae4
   Fast, safe conversions from long to a character representation which gets
Packit a4aae4
   appended to a string. This method will take a long value 'val' and it will
Packit a4aae4
   recursively divide it by 'base' in order to "extract" one by one the
Packit a4aae4
   digits which compose it; these digits will be appended to the
Packit a4aae4
   string <tt>str_val</tt> which will become the textual representation of
Packit a4aae4
   'val'. Please notice that the digits ``extracted'' from `val' will vary
Packit a4aae4
   depending on the base chosen for the conversion; for example val=15
Packit a4aae4
   converted to base 10 will yield the digits (1,5), converted to base 16
Packit a4aae4
   will yield (F) and converted to base 2 will yield (1,1,1,1).
Packit a4aae4
Packit a4aae4
   @param val The long value we which to convert to string.
Packit a4aae4
Packit a4aae4
   @param base A value in the range [2,36] which is the base to use while
Packit a4aae4
   transforming the long value 'val' to its textual representation. Typical
Packit a4aae4
   bases are 2 (binary), 10 (decimal) and 16 (hexadecimal).
Packit a4aae4
Packit a4aae4
   @param str_val This is the string that will hold the textual
Packit a4aae4
   representation of 'val'. The string <tt>str_val</tt> should be
Packit a4aae4
   pre-set to an empty
Packit a4aae4
   string ("") otherwise the output of this function will just append the
Packit a4aae4
   textual representation of val to whatever data is there; these feature may
Packit a4aae4
   be useful if you wish to append a long value to a string s1 (just like
Packit a4aae4
   operator+ does) without having to create a new string object s2 and then
Packit a4aae4
   use string::operator+ between s1 and s2.
Packit a4aae4
Packit a4aae4
   @return void. This method returns nothing however be aware that it will
Packit a4aae4
   throw and exception of type <tt>std::invalid_argument</tt> if the parameter
Packit a4aae4
   base is not in the valid range. */
Packit a4aae4
//@{
Packit a4aae4
void append_long_to_string(long val, int base, string &str_val);
Packit a4aae4
string long_to_string(long val, int base = 10);
Packit a4aae4
//@}
Packit a4aae4
Packit a4aae4
// Jose Garcia
Packit a4aae4
/** @name Double to string conversion functions
Packit a4aae4
    Conversions from double to a character representation which gets appended
Packit a4aae4
    to a string. This function depends on the standard routine sprintf to
Packit a4aae4
    convert a double to a textual representation which gets appended to the
Packit a4aae4
    string 'str'.
Packit a4aae4
Packit a4aae4
    @param num The double you wish to append to str.
Packit a4aae4
Packit a4aae4
    @param str The string where the textual representation of num will be
Packit a4aae4
    appended.
Packit a4aae4
Packit a4aae4
    @return void. */
Packit a4aae4
//@{
Packit a4aae4
void append_double_to_string(const double &num, string &str);
Packit a4aae4
string double_to_string(const double &num);
Packit a4aae4
//@}
Packit a4aae4
Packit a4aae4
string path_to_filename(string path);
Packit a4aae4
int glob( const char *c, const char *s );
Packit a4aae4
time_t parse_time(const char * str, bool expand);
Packit a4aae4
bool size_ok(unsigned int sz, unsigned int nelem);
Packit a4aae4
bool pathname_ok(const string &path, bool strict = true);
Packit a4aae4
string dap_version();
Packit a4aae4
string open_temp_fstream(ofstream &f, const string &name_template, const string &suffix = "");
Packit a4aae4
Packit a4aae4
} // namespace libdap
Packit a4aae4
Packit a4aae4
#endif