GeographicLib::Utility Class Reference
Some utility routines for GeographicLib.
More...
#include <GeographicLib/Utility.hpp>
List of all members.
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 | str (Math::real x, int p=-1) |
template<typename T > |
static T | num (const std::string &s) |
template<typename T > |
static T | nummatch (const std::string &s) |
template<typename T > |
static T | fract (const std::string &s) |
static int | lookup (const std::string &s, char c) |
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 &val) |
static int | set_digits (int ndigits=0) |
Detailed Description
Some utility routines for GeographicLib.
Example of use:
#include <iostream>
#include <exception>
#include <GeographicLib/Utility.hpp>
using namespace std;
using namespace GeographicLib;
int main() {
try {
int
d1 = Utility::day(1939, 9, 3),
d2 = Utility::day(1945, 8, 15);
cout << d2 - d1 << "\n";
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
return 0;
}
Definition at line 33 of file Utility.hpp.
Member Function Documentation
static int GeographicLib::Utility::day |
( |
int |
y, |
|
|
int |
m = 1 , |
|
|
int |
d = 1 | |
|
) |
| | [inline, static] |
Convert a date to the day numbering sequentially starting with 0001-01-01 as day 1.
- Parameters:
-
[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. |
- Returns:
- the sequential day number.
Definition at line 58 of file Utility.hpp.
static int GeographicLib::Utility::day |
( |
int |
y, |
|
|
int |
m, |
|
|
int |
d, |
|
|
bool |
check | |
|
) |
| | [inline, static] |
Convert a date to the day numbering sequentially starting with 0001-01-01 as day 1.
- Parameters:
-
[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. |
- Exceptions:
-
- Returns:
- the sequential day number.
Definition at line 121 of file Utility.hpp.
static void GeographicLib::Utility::date |
( |
int |
s, |
|
|
int & |
y, |
|
|
int & |
m, |
|
|
int & |
d | |
|
) |
| | [inline, static] |
Given a day (counting from 0001-01-01 as day 1), return the date.
- Parameters:
-
[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 144 of file Utility.hpp.
static void GeographicLib::Utility::date |
( |
const std::string & |
s, |
|
|
int & |
y, |
|
|
int & |
m, |
|
|
int & |
d | |
|
) |
| | [inline, 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.
- Parameters:
-
[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. |
- Exceptions:
-
Definition at line 176 of file Utility.hpp.
static int GeographicLib::Utility::dow |
( |
int |
y, |
|
|
int |
m, |
|
|
int |
d | |
|
) |
| | [inline, static] |
Given the date, return the day of the week.
- Parameters:
-
[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). |
- Returns:
- the day of the week with Sunday, Monday--Saturday = 0, 1--6.
Definition at line 216 of file Utility.hpp.
References dow().
Referenced by dow().
static int GeographicLib::Utility::dow |
( |
int |
s |
) |
[inline, static] |
Given the sequential day, return the day of the week.
- Parameters:
-
[in] | s | the sequential day (must be positive). |
- Returns:
- the day of the week with Sunday, Monday--Saturday = 0, 1--6.
Definition at line 225 of file Utility.hpp.
template<typename T >
static T GeographicLib::Utility::fractionalyear |
( |
const std::string & |
s |
) |
[inline, static] |
Convert a string representing a date to a fractional year.
- Template Parameters:
-
| T | the type of the argument. |
- Parameters:
-
[in] | s | the string to be converted. |
- Exceptions:
-
- Returns:
- the fractional year.
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.
Definition at line 242 of file Utility.hpp.
template<typename T >
static std::string GeographicLib::Utility::str |
( |
T |
x, |
|
|
int |
p = -1 | |
|
) |
| | [inline, static] |
Convert a object of type T to a string.
- Template Parameters:
-
| T | the type of the argument. |
- Parameters:
-
[in] | x | the value to be converted. |
[in] | p | the precision used (default 1). |
- Exceptions:
-
| std::bad_alloc | if memory for the string can't be allocated. |
- Returns:
- the string representation.
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.
Definition at line 266 of file Utility.hpp.
Referenced by GeographicLib::DMS::Decode(), GeographicLib::DMS::DecodeLatLon(), GeographicLib::UTMUPS::DecodeZone(), GeographicLib::DMS::Encode(), GeographicLib::UTMUPS::EncodeZone(), GeographicLib::UTMUPS::Forward(), GeographicLib::MGRS::Forward(), GeographicLib::Geohash::Forward(), GeographicLib::OSGB::GridReference(), GeographicLib::SphericalEngine::coeff::readcoeffs(), GeographicLib::UTMUPS::Reverse(), GeographicLib::MGRS::Reverse(), and GeographicLib::UTMUPS::StandardZone().
static std::string GeographicLib::Utility::str |
( |
Math::real |
x, |
|
|
int |
p = -1 | |
|
) |
| | [inline, static] |
Convert a Math::real object to a string.
- Parameters:
-
[in] | x | the value to be converted. |
[in] | p | the precision used (default 1). |
- Exceptions:
-
| std::bad_alloc | if memory for the string can't be allocated. |
- Returns:
- the string representation.
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. This is an overload of str<T> which deals with inf and nan.
Definition at line 284 of file Utility.hpp.
References GeographicLib::Math::isfinite().
template<typename T >
static T GeographicLib::Utility::num |
( |
const std::string & |
s |
) |
[inline, static] |
Convert a string to an object of type T.
- Template Parameters:
-
| T | the type of the return value. |
- Parameters:
-
[in] | s | the string to be converted. |
- Exceptions:
-
- Returns:
- object of type T
Definition at line 301 of file Utility.hpp.
template<typename T >
static T GeographicLib::Utility::nummatch |
( |
const std::string & |
s |
) |
[inline, static] |
Match "nan" and "inf" (and variants thereof) in a string.
- Template Parameters:
-
| T | the type of the return value. |
- Parameters:
-
[in] | s | the string to be matched. |
- Returns:
- appropriate special value (, nan) or 0 if none is found.
Definition at line 331 of file Utility.hpp.
template<typename T >
static T GeographicLib::Utility::fract |
( |
const std::string & |
s |
) |
[inline, static] |
Read a simple fraction, e.g., 3/4, from a string to an object of type T.
- Template Parameters:
-
| T | the type of the return value. |
- Parameters:
-
[in] | s | the string to be converted. |
- Exceptions:
-
- Returns:
- object of type T
Definition at line 362 of file Utility.hpp.
static int GeographicLib::Utility::lookup |
( |
const std::string & |
s, |
|
|
char |
c | |
|
) |
| | [inline, static] |
template<typename ExtT , typename IntT , bool bigendp>
static void GeographicLib::Utility::readarray |
( |
std::istream & |
str, |
|
|
IntT |
array[], |
|
|
size_t |
num | |
|
) |
| | [inline, static] |
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.
- Template Parameters:
-
| 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. |
- Parameters:
-
[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. |
- Exceptions:
-
Definition at line 401 of file Utility.hpp.
References GeographicLib::Math::bigendian.
template<typename ExtT , typename IntT , bool bigendp>
static void GeographicLib::Utility::readarray |
( |
std::istream & |
str, |
|
|
std::vector< IntT > & |
array | |
|
) |
| | [inline, static] |
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.
- Template Parameters:
-
| 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. |
- Parameters:
-
[in] | str | the input stream containing the data of type ExtT (external). |
[out] | array | the output vector of type IntT (internal). |
- Exceptions:
-
Definition at line 453 of file Utility.hpp.
template<typename ExtT , typename IntT , bool bigendp>
static void GeographicLib::Utility::writearray |
( |
std::ostream & |
str, |
|
|
const IntT |
array[], |
|
|
size_t |
num | |
|
) |
| | [inline, static] |
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.
- Template Parameters:
-
| 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. |
- Parameters:
-
[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. |
- Exceptions:
-
Definition at line 471 of file Utility.hpp.
References GeographicLib::Math::bigendian.
template<typename ExtT , typename IntT , bool bigendp>
static void GeographicLib::Utility::writearray |
( |
std::ostream & |
str, |
|
|
std::vector< IntT > & |
array | |
|
) |
| | [inline, static] |
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.
- Template Parameters:
-
| 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. |
- Parameters:
-
[out] | str | the output stream for the data of type ExtT (external). |
[in] | array | the input vector of type IntT (internal). |
- Exceptions:
-
Definition at line 518 of file Utility.hpp.
bool GeographicLib::Utility::ParseLine |
( |
const std::string & |
line, |
|
|
std::string & |
key, |
|
|
std::string & |
val | |
|
) |
| | [static] |
Parse a KEY VALUE line.
- Parameters:
-
[in] | line | the input line. |
[out] | key | the key. |
[out] | val | the value. |
- Exceptions:
-
| std::bad_alloc | if memory for the internal strings can't be allocated. |
- Returns:
- whether a key was found.
A # character and everything after it are discarded. If the result is just white space, the routine returns false (and key and val are not set). Otherwise the first token is taken to be the key and the rest of the line (trimmed of leading and trailing white space) is the value.
Definition at line 22 of file Utility.cpp.
int GeographicLib::Utility::set_digits |
( |
int |
ndigits = 0 |
) |
[static] |
Set the binary precision of a real number.
- Parameters:
-
[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). |
- Returns:
- the resulting number of bits of precision.
This only has an effect when GEOGRAPHICLIB_PRECISION == 5.
Definition at line 48 of file Utility.cpp.
The documentation for this class was generated from the following files: