GeographicLib
1.21
|
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) throw () |
static int | day (int y, int m, int d, bool check) |
static void | date (int s, int &y, int &m, int &d) throw () |
static void | date (const std::string &s, int &y, int &m, int &d) |
static int | dow (int y, int m, int d) throw () |
static int | dow (int s) throw () |
template<typename T > | |
static T | fractionalyear (const std::string &s) |
template<typename T > | |
static std::string | str (T 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) throw () |
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) |
Some utility routines for GeographicLib.
Example of use:
// Example of using the GeographicLib::Utility class // $Id: 34856fc274a1db91814bb96768a6c8feee03dacc $ #include <iostream> #include <exception> #include <GeographicLib/Utility.hpp> using namespace std; using namespace GeographicLib; int main() { try { int d1 = Utility::day(1939, 9, 3), // Britain declares war on Germany d2 = Utility::day(1945, 8, 15); // Japan surrenders cout << d2 - d1 << "\n"; // Length of Second World War for Britain } catch (const exception& e) { cerr << "Caught exception: " << e.what() << "\n"; return 1; } return 0; }
static int GeographicLib::Utility::day | ( | int | y, |
int | m = 1 , |
||
int | d = 1 |
||
) | throw () [inline, 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 55 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.
[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. |
If check is true and the date is invalid an exception is thrown.
Definition at line 119 of file Utility.hpp.
static void GeographicLib::Utility::date | ( | int | s, |
int & | y, | ||
int & | m, | ||
int & | d | ||
) | throw () [inline, 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 142 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.
[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. |
Definition at line 173 of file Utility.hpp.
static int GeographicLib::Utility::dow | ( | int | y, |
int | m, | ||
int | d | ||
) | throw () [inline, static] |
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 212 of file Utility.hpp.
References dow().
Referenced by dow().
static int GeographicLib::Utility::dow | ( | int | s | ) | throw () [inline, static] |
Given the sequential day, return the day of the week.
[in] | s | the sequential day (must be positive). |
Definition at line 220 of file Utility.hpp.
static T GeographicLib::Utility::fractionalyear | ( | const std::string & | s | ) | [inline, static] |
Convert a string representing a date to a fractional year.
T | the type of the argument. |
[in] | s | the string to be converted. |
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 236 of file Utility.hpp.
static std::string GeographicLib::Utility::str | ( | T | x, |
int | p = -1 |
||
) | [inline, static] |
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). |
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 259 of file Utility.hpp.
Referenced by main().
static T GeographicLib::Utility::num | ( | const std::string & | s | ) | [inline, static] |
Convert a string to an object of type T.
T | the type of the return value. |
[in] | s | the string to be converted. |
Definition at line 275 of file Utility.hpp.
static T GeographicLib::Utility::nummatch | ( | const std::string & | s | ) | [inline, static] |
Match "nan" and "inf" (and variants thereof) in a string.
T | the type of the return value. |
[in] | s | the string to be matched. |
Definition at line 304 of file Utility.hpp.
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.
T | the type of the return value. |
[in] | s | the string to be converted. |
Definition at line 334 of file Utility.hpp.
static int GeographicLib::Utility::lookup | ( | const std::string & | s, |
char | c | ||
) | throw () [inline, 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 354 of file Utility.hpp.
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.
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. |
Definition at line 372 of file Utility.hpp.
References GeographicLib::Math::bigendian.
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.
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). |
Definition at line 418 of file Utility.hpp.
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.
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. |
Definition at line 435 of file Utility.hpp.
References GeographicLib::Math::bigendian.
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.
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). |
Definition at line 476 of file Utility.hpp.
bool GeographicLib::Utility::ParseLine | ( | const std::string & | line, |
std::string & | key, | ||
std::string & | val | ||
) | [static] |
Parse a KEY VALUE line.
[in] | line | the input line. |
[out] | key | the key. |
[out] | val | the value. |
A # character and everything after it are discarded. If the results 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.