GeographicLib 2.1.2
|
Some utility routines for GeographicLib. More...
#include <GeographicLib/Utility.hpp>
Static Public Member Functions | |
static int | day (int y, int m=1, int d=1) |
static int | day (int y, int m, int d, bool check) |
static void | date (int s, int &y, int &m, int &d) |
static void | date (const std::string &s, int &y, int &m, int &d) |
static int | dow (int y, int m, int d) |
static int | dow (int s) |
template<typename T > | |
static T | fractionalyear (const std::string &s) |
template<typename T > | |
static std::string | str (T x, int p=-1) |
static std::string | trim (const std::string &s) |
static int | lookup (const std::string &s, char c) |
static int | lookup (const char *s, char c) |
template<typename T > | |
static T | val (const std::string &s) |
template<typename T > | |
static T | nummatch (const std::string &s) |
template<typename T > | |
static T | fract (const std::string &s) |
template<typename ExtT , typename IntT , bool bigendp> | |
static void | readarray (std::istream &str, IntT array[], size_t num) |
template<typename ExtT , typename IntT , bool bigendp> | |
static void | readarray (std::istream &str, std::vector< IntT > &array) |
template<typename ExtT , typename IntT , bool bigendp> | |
static void | writearray (std::ostream &str, const IntT array[], size_t num) |
template<typename ExtT , typename IntT , bool bigendp> | |
static void | writearray (std::ostream &str, std::vector< IntT > &array) |
static bool | ParseLine (const std::string &line, std::string &key, std::string &value, char equals='\0', char comment='#') |
static int | set_digits (int ndigits=0) |
template<> | |
bool | val (const std::string &s) |
Some utility routines for GeographicLib.
Example of use:
Definition at line 35 of file Utility.hpp.
|
static |
Convert a date to the day numbering sequentially starting with 0001-01-01 as day 1.
[in] | y | the year (must be positive). |
[in] | m | the month, Jan = 1, etc. (must be positive). Default = 1. |
[in] | d | the day of the month (must be positive). Default = 1. |
Definition at line 22 of file Utility.cpp.
Referenced by day().
|
static |
Convert a date to the day numbering sequentially starting with 0001-01-01 as day 1.
[in] | y | the year (must be positive). |
[in] | m | the month, Jan = 1, etc. (must be positive). Default = 1. |
[in] | d | the day of the month (must be positive). Default = 1. |
[in] | check | whether to check the date. |
GeographicErr | if the date is invalid and check is true. |
Definition at line 74 of file Utility.cpp.
|
static |
Given a day (counting from 0001-01-01 as day 1), return the date.
[in] | s | the sequential day number (must be positive) |
[out] | y | the year. |
[out] | m | the month, Jan = 1, etc. |
[out] | d | the day of the month. |
Definition at line 89 of file Utility.cpp.
Referenced by day().
|
static |
Given a date as a string in the format yyyy, yyyy-mm, or yyyy-mm-dd, return the numeric values for the year, month, and day. No checking is done on these values. The string "now" is interpreted as the present date (in UTC).
[in] | s | the date in string format. |
[out] | y | the year. |
[out] | m | the month, Jan = 1, etc. |
[out] | d | the day of the month. |
GeographicErr | is s is malformed. |
Definition at line 110 of file Utility.cpp.
|
inlinestatic |
Given the date, return the day of the week.
[in] | y | the year (must be positive). |
[in] | m | the month, Jan = 1, etc. (must be positive). |
[in] | d | the day of the month (must be positive). |
Definition at line 108 of file Utility.hpp.
References dow().
Referenced by dow().
|
inlinestatic |
Given the sequential day, return the day of the week.
[in] | s | the sequential day (must be positive). |
Definition at line 117 of file Utility.hpp.
|
inlinestatic |
Convert a string representing a date to a fractional year.
T | the type of the argument. |
[in] | s | the string to be converted. |
GeographicErr | if s can't be interpreted as a date. |
The string is first read as an ordinary number (e.g., 2010 or 2012.5); if this is successful, the value is returned. Otherwise the string should be of the form yyyy-mm or yyyy-mm-dd and this is converted to a number with 2010-01-01 giving 2010.0 and 2012-07-03 giving 2012.5. The string "now" is interpreted as the present date.
Definition at line 135 of file Utility.hpp.
|
inlinestatic |
Convert a object of type T to a string.
T | the type of the argument. |
[in] | x | the value to be converted. |
[in] | p | the precision used (default −1). |
std::bad_alloc | if memory for the string can't be allocated. |
If p ≥ 0, then the number fixed format is used with p bits of precision. With p < 0, there is no manipulation of the format, except that boolalpha
is used to represent bools as "true" and "false". There is an overload of this function if T is Math::real; this deals with inf and nan.
Definition at line 161 of file Utility.hpp.
Referenced by GeographicLib::MGRS::Check(), day(), GeographicLib::DMS::DecodeLatLon(), GeographicLib::UTMUPS::DecodeZone(), GeographicLib::DMS::Encode(), GeographicLib::UTMUPS::EncodeZone(), GeographicLib::MGRS::Forward(), GeographicLib::UTMUPS::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::GARS::Forward(), GeographicLib::Georef::Forward(), GeographicLib::GeoCoords::GeoRepresentation(), GeographicLib::OSGB::GridReference(), GeographicLib::SphericalEngine::coeff::readcoeffs(), GeographicLib::Georef::Reverse(), GeographicLib::MGRS::Reverse(), GeographicLib::UTMUPS::Reverse(), and GeographicLib::UTMUPS::StandardZone().
|
static |
Trim the white space from the beginning and end of a string.
[in] | s | the string to be trimmed |
Definition at line 149 of file Utility.cpp.
Referenced by ParseLine(), and val().
|
static |
Lookup up a character in a string.
[in] | s | the string to be searched. |
[in] | c | the character to look for. |
c is converted to upper case before search s. Therefore, it is intended that s should not contain any lower case letters.
Definition at line 160 of file Utility.cpp.
Referenced by GeographicLib::DMS::Decode(), GeographicLib::OSGB::GridReference(), GeographicLib::GARS::Reverse(), GeographicLib::Geohash::Reverse(), GeographicLib::Georef::Reverse(), and GeographicLib::MGRS::Reverse().
|
static |
Lookup up a character in a char*.
[in] | s | the char* string to be searched. |
[in] | c | the character to look for. |
c is converted to upper case before search s. Therefore, it is intended that s should not contain any lower case letters.
Definition at line 165 of file Utility.cpp.
|
inlinestatic |
Convert a string to type T.
T | the type of the return value. |
[in] | s | the string to be converted. |
GeographicErr | is s is not readable as a T. |
White space at the beginning and end of s is ignored.
Special handling is provided for some types.
If T is a floating point type, then inf and nan are recognized.
If T is bool, then s should either be string a representing 0 (false) or 1 (true) or one of the strings
case is ignored.
If T is std::string, then s is returned (with the white space at the beginning and end removed).
Definition at line 225 of file Utility.hpp.
|
inlinestatic |
Match "nan" and "inf" (and variants thereof) in a string.
T | the type of the return value (this should be a floating point type). |
[in] | s | the string to be matched. |
White space is not allowed at the beginning or end of s.
Definition at line 260 of file Utility.hpp.
|
inlinestatic |
Read a simple fraction, e.g., 3/4, from a string to an object of type T.
T | the type of the return value. |
[in] | s | the string to be converted. |
GeographicErr | is s is not readable as a fraction of type T. |
Definition at line 298 of file Utility.hpp.
|
inlinestatic |
Read data of type ExtT from a binary stream to an array of type IntT. The data in the file is in (bigendp ? big : little)-endian format.
ExtT | the type of the objects in the binary stream (external). |
IntT | the type of the objects in the array (internal). |
bigendp | true if the external storage format is big-endian. |
[in] | str | the input stream containing the data of type ExtT (external). |
[out] | array | the output array of type IntT (internal). |
[in] | num | the size of the array. |
GeographicErr | if the data cannot be read. |
Definition at line 321 of file Utility.hpp.
References GeographicLib::Math::bigendian.
|
inlinestatic |
Read data of type ExtT from a binary stream to a vector array of type IntT. The data in the file is in (bigendp ? big : little)-endian format.
ExtT | the type of the objects in the binary stream (external). |
IntT | the type of the objects in the array (internal). |
bigendp | true if the external storage format is big-endian. |
[in] | str | the input stream containing the data of type ExtT (external). |
[out] | array | the output vector of type IntT (internal). |
GeographicErr | if the data cannot be read. |
Definition at line 372 of file Utility.hpp.
|
inlinestatic |
Write data in an array of type IntT as type ExtT to a binary stream. The data in the file is in (bigendp ? big : little)-endian format.
ExtT | the type of the objects in the binary stream (external). |
IntT | the type of the objects in the array (internal). |
bigendp | true if the external storage format is big-endian. |
[out] | str | the output stream for the data of type ExtT (external). |
[in] | array | the input array of type IntT (internal). |
[in] | num | the size of the array. |
GeographicErr | if the data cannot be written. |
Definition at line 390 of file Utility.hpp.
References GeographicLib::Math::bigendian.
|
inlinestatic |
Write data in an array of type IntT as type ExtT to a binary stream. The data in the file is in (bigendp ? big : little)-endian format.
ExtT | the type of the objects in the binary stream (external). |
IntT | the type of the objects in the array (internal). |
bigendp | true if the external storage format is big-endian. |
[out] | str | the output stream for the data of type ExtT (external). |
[in] | array | the input vector of type IntT (internal). |
GeographicErr | if the data cannot be written. |
Definition at line 437 of file Utility.hpp.
|
static |
Parse a KEY [=] VALUE line.
[in] | line | the input line. |
[out] | key | the KEY. |
[out] | value | the VALUE. |
[in] | equals | character representing "equals" to separate KEY and VALUE, if NULL (the default) use first space character. |
[in] | comment | character to use as the comment character; if non-NULL, this character and everything after it is discarded; default is '#'. |
std::bad_alloc | if memory for the internal strings can't be allocated. |
The comment character (default is '#') and everything after it are discarded and the result trimmed of leading and trailing white space. Use the equals delimiter character (or, if it is NULL – the default, the first white space) to separate key and value. key and value are trimmed of leading and trailing white space. If key is empty, then value is set to "" and false is returned.
Definition at line 170 of file Utility.cpp.
References trim().
|
static |
Set the binary precision of a real number.
[in] | ndigits | the number of bits of precision. If ndigits is 0 (the default), then determine the precision from the environment variable GEOGRAPHICLIB_DIGITS. If this is undefined, use ndigits = 256 (i.e., about 77 decimal digits). |
This only has an effect when GEOGRAPHICLIB_PRECISION = 5. The precision should only be set once and before calls to any other GeographicLib functions. (Several functions, for example Math::pi(), cache the return value in a static local variable. The precision needs to be set before a call to any such functions.) In multi-threaded applications, it is necessary also to set the precision in each thread (see the example GeoidToGTX.cpp).
Definition at line 184 of file Utility.cpp.
References GeographicLib::Math::set_digits().
|
inlinestatic |
The specialization of Utility::val<T>() for bools.
[in] | s | the string to be converted. |
GeographicErr | is s is not readable as a T. |
s should either be string a representing 0 (false) or 1 (true) or one of the strings
case is ignored.
Definition at line 515 of file Utility.hpp.
References trim().