\brief Return the list of units. * @throw FactoryException in case of error. * * @since 7.1 */
| 8962 | * @since 7.1 |
| 8963 | */ |
| 8964 | std::list<AuthorityFactory::UnitInfo> AuthorityFactory::getUnitList() const { |
| 8965 | std::string sql = "SELECT auth_name, code, name, type, conv_factor, " |
| 8966 | "proj_short_name, deprecated FROM unit_of_measure"; |
| 8967 | ListOfParams params; |
| 8968 | if (d->hasAuthorityRestriction()) { |
| 8969 | sql += " WHERE auth_name = ?"; |
| 8970 | params.emplace_back(d->authority()); |
| 8971 | } |
| 8972 | sql += " ORDER BY auth_name, code"; |
| 8973 | |
| 8974 | auto sqlRes = d->run(sql, params); |
| 8975 | std::list<AuthorityFactory::UnitInfo> res; |
| 8976 | for (const auto &row : sqlRes) { |
| 8977 | AuthorityFactory::UnitInfo info; |
| 8978 | info.authName = row[0]; |
| 8979 | info.code = row[1]; |
| 8980 | info.name = row[2]; |
| 8981 | const std::string &raw_category(row[3]); |
| 8982 | if (raw_category == "length") { |
| 8983 | info.category = info.name.find(" per ") != std::string::npos |
| 8984 | ? "linear_per_time" |
| 8985 | : "linear"; |
| 8986 | } else if (raw_category == "angle") { |
| 8987 | info.category = info.name.find(" per ") != std::string::npos |
| 8988 | ? "angular_per_time" |
| 8989 | : "angular"; |
| 8990 | } else if (raw_category == "scale") { |
| 8991 | info.category = |
| 8992 | info.name.find(" per year") != std::string::npos || |
| 8993 | info.name.find(" per second") != std::string::npos |
| 8994 | ? "scale_per_time" |
| 8995 | : "scale"; |
| 8996 | } else { |
| 8997 | info.category = raw_category; |
| 8998 | } |
| 8999 | info.convFactor = row[4].empty() ? 0 : c_locale_stod(row[4]); |
| 9000 | info.projShortName = row[5]; |
| 9001 | info.deprecated = row[6] == "1"; |
| 9002 | res.emplace_back(info); |
| 9003 | } |
| 9004 | return res; |
| 9005 | } |
| 9006 | |
| 9007 | // --------------------------------------------------------------------------- |
| 9008 |