libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
util.cc File Reference
#include "config.h"
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <algorithm>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#include "Array.h"
#include "BaseType.h"
#include "Byte.h"
#include "Float32.h"
#include "Float64.h"
#include "Int16.h"
#include "Int32.h"
#include "Str.h"
#include "UInt16.h"
#include "UInt32.h"
#include "Int64.h"
#include "Int8.h"
#include "UInt64.h"
#include "Error.h"
#include "GNURegex.h"
#include "debug.h"
#include "util.h"
Include dependency graph for util.cc:

Go to the source code of this file.

Namespaces

namespace  libdap
 top level DAP object to house generic methods
 

Macros

#define BITLISTSIZE   16 /* bytes used for [chars] in compiled expr */
 
#define CHECK_BIT(tab, bit)
 

Functions

string libdap::D2type_name (Type t)
 Returns the type of the class instance as a string. Supports all DAP2 types and not the DAP4-only types. Also returns Url (DAP2) and not "URL" (DAP4) for the URL type.
 
string libdap::D4type_name (Type t)
 Returns the type of the class instance as a string. Supports all DAP4 types and not the DAP2-only types. Also returns URL (DAP4) and not "Url" (DAP2) for the URL type.
 
bool libdap::dir_exists (const string &dir)
 
void libdap::downcase (string &s)
 
double * libdap::extract_double_array (Array *a)
 
void libdap::extract_double_array (Array *a, vector< double > &dest)
 
double libdap::extract_double_value (BaseType *arg)
 
string libdap::extract_string_argument (BaseType *arg)
 
Type libdap::get_type (const char *name)
 
bool libdap::is_constructor_type (Type t)
 Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
 
bool libdap::is_host_big_endian ()
 Does this host use big-endian byte order?
 
bool libdap::is_integer_type (Type t)
 
bool libdap::is_quoted (const string &s)
 
bool libdap::is_simple_type (Type t)
 Returns true if the instance is a numeric, string or URL type variable.
 
bool libdap::is_vector_type (Type t)
 Returns true if the instance is a vector (i.e., array) type variable.
 
const char * libdap::libdap_name ()
 
const char * libdap::libdap_root ()
 
const char * libdap::libdap_version ()
 
string libdap::prune_spaces (const string &name)
 
string libdap::remove_quotes (const string &s)
 
void libdap::set_array_using_double (Array *dest, double *src, int src_len)
 
string libdap::systime ()
 
string libdap::type_name (Type t)
 
bool libdap::unique_names (vector< BaseType * > l, const string &var_name, const string &type_name, string &msg)
 
Integer to string conversion functions

Fast, safe conversions from long to a character representation which gets appended to a string. This method will take a long value 'val' and it will recursively divide it by 'base' in order to "extract" one by one the digits which compose it; these digits will be appended to the string str_val which will become the textual representation of 'val'. Please notice that the digits `‘extracted’' from ‘val’ will vary depending on the base chosen for the conversion; for example val=15 converted to base 10 will yield the digits (1,5), converted to base 16 will yield (F) and converted to base 2 will yield (1,1,1,1).

Parameters
valThe long value we which to convert to string.
baseA value in the range [2,36] which is the base to use while transforming the long value 'val' to its textual representation. Typical bases are 2 (binary), 10 (decimal) and 16 (hexadecimal).
str_valThis is the string that will hold the textual representation of 'val'. The string str_val should be pre-set to an empty string ("") otherwise the output of this function will just append the textual representation of val to whatever data is there; these feature may be useful if you wish to append a long value to a string s1 (just like operator+ does) without having to create a new string object s2 and then use string::operator+ between s1 and s2.
Returns
void. This method returns nothing however be aware that it will throw and exception of type std::invalid_argument if the parameter base is not in the valid range.
void libdap::append_long_to_string (long val, int base, string &str_val)
 
string libdap::long_to_string (long val, int base)
 
Double to string conversion functions

Conversions from double to a character representation which gets appended to a string. This function depends on the standard routine sprintf to convert a double to a textual representation which gets appended to the string 'str'.

Parameters
numThe double you wish to append to str.
strThe string where the textual representation of num will be appended.
Returns
void.
void libdap::append_double_to_string (const double &num, string &str)
 
string libdap::double_to_string (const double &num)
 
int libdap::glob (const char *c, const char *s)
 
string libdap::path_to_filename (string path)
 
Security functions
string libdap::dap_version ()
 
string libdap::open_temp_fstream (ofstream &f, const string &name_template, const string &suffix)
 
bool libdap::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 valid name. We define this as: Contains only printable characters; and Is less than 256 characters. If strict is true, test that the pathname consists of only letters, digits, and underscore, dash and dot characters instead of the more general case where a pathname can be composed of any printable characters.
 
bool libdap::size_ok (unsigned int sz, unsigned int nelem)
 sanitize the size of an array. Test for integer overflow when dynamically allocating an array.
 

Macro Definition Documentation

◆ BITLISTSIZE

#define BITLISTSIZE   16 /* bytes used for [chars] in compiled expr */

Definition at line 995 of file util.cc.

◆ CHECK_BIT

#define CHECK_BIT ( tab,
bit )
Value:
(tab[(bit) / 8] & (1 << ((bit) % 8)))

Definition at line 994 of file util.cc.