Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 94672bba98 | |||
| 33675c18ec | |||
| f76d524999 | |||
| 1bc8a9ad82 | |||
| 9a83cf6c08 | |||
| 28238ba041 | |||
| 044afb9a60 | |||
| 8ba8dee78d | |||
| 7f0a814b3f |
3
.idea/codeStyles/Project.xml
generated
3
.idea/codeStyles/Project.xml
generated
@@ -7,6 +7,9 @@
|
||||
<option name="FUNCTION_BRACE_PLACEMENT" value="2" />
|
||||
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="2" />
|
||||
</Objective-C>
|
||||
<clangFormatSettings>
|
||||
<option name="ENABLED" value="true" />
|
||||
</clangFormatSettings>
|
||||
<files>
|
||||
<extensions>
|
||||
<pair source="cc" header="h" fileNamingConvention="PASCAL_CASE" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(scsl LANGUAGES CXX
|
||||
VERSION 1.0.0
|
||||
VERSION 1.1.3
|
||||
DESCRIPTION "Shimmering Clarity Standard Library")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
@@ -154,7 +154,7 @@ add_custom_target(deploy-docs
|
||||
configure_file(scsl.pc.in scsl.pc @ONLY)
|
||||
install(TARGETS scsl LIBRARY DESTINATION lib)
|
||||
install(TARGETS phonebook RUNTIME DESTINATION bin)
|
||||
install(FILES ${HEADER_FILES} DESTINATION include/scsl)
|
||||
install(DIRECTORY include/ DESTINATION include)
|
||||
install(FILES scslConfig.cmake DESTINATION share/scsl/cmake)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scsl.pc DESTINATION lib/pkgconfig)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
|
||||
if(LINUX)
|
||||
set(CPACK_GENERATOR "DEB;STGZ;TGZ")
|
||||
elseif(APPLE)
|
||||
set(CPACK_GENERATOR "productbuild")
|
||||
set(CPACK_GENERATOR "STGZ;TGZ")
|
||||
elseif(MSVC OR MSYS OR MINGW)
|
||||
set(CPACK_GENERATOR "NSIS;ZIP")
|
||||
else()
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace geom {
|
||||
/// and rotations in three dimensions.
|
||||
///
|
||||
/// Quaternions encode rotations in three-dimensional space. While
|
||||
/// technically a MakeQuaternion is comprised of a real element and a
|
||||
/// technically a Quaternion is comprised of a real element and a
|
||||
/// complex vector<3>, for the purposes of this library, it is modeled
|
||||
/// as a floating point 4D vector of the form <w, x, y, z>, where x, y,
|
||||
/// and z represent an Axis of rotation in R3 and w the Angle, in
|
||||
|
||||
@@ -193,8 +193,8 @@ public:
|
||||
T
|
||||
Angle(const Vector<T, N> &other) const
|
||||
{
|
||||
Vector<T, N> unitA = this->UnitVector();
|
||||
Vector<T, N> unitB = other.UnitVector();
|
||||
auto unitA = this->UnitVector();
|
||||
auto unitB = other.UnitVector();
|
||||
|
||||
// Can't compute angles with a zero vector.
|
||||
assert(!this->IsZero());
|
||||
@@ -214,12 +214,24 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
T angle = this->Angle(other);
|
||||
if (scmp::WithinTolerance(angle, (T) 0.0, this->epsilon)) {
|
||||
return true;
|
||||
}
|
||||
// If the two unit vectors are equal, the two vectors
|
||||
// lie on the same path.
|
||||
//
|
||||
// Context: this used to use Vector::Angle to check for
|
||||
// a zero angle between the two. However, the vagaries
|
||||
// of floating point math meant that while this worked
|
||||
// fine on Linux amd64 builds, it failed on Linux arm64
|
||||
// and MacOS builds. Parallel float vectors would have
|
||||
// an angle of ~0.0003 radians, while double vectors
|
||||
// would have an angle of +NaN. I suspect this is due to
|
||||
// tiny variations in floating point math, such that a dot
|
||||
// product of unit vectors would be just a hair over 1,
|
||||
// e.g. 1.000000001 - which would still fall outside the
|
||||
// domain of acos.
|
||||
auto unitA = this->UnitVector();
|
||||
auto unitB = other.UnitVector();
|
||||
|
||||
return false;
|
||||
return unitA == unitB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -110,6 +110,27 @@ public:
|
||||
/// \return The value stored under the key, or an empty string.
|
||||
static std::string GetGlobal(std::string &key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \note This operates on the global config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \return The value stored under the key, or an empty string.
|
||||
static std::string GetGlobal(const char *key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \note This operates on the global config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param defaultValue A default value to cache and use if no
|
||||
/// value is stored under the key.
|
||||
/// \return The value stored under the key, or the default
|
||||
/// value.
|
||||
static std::string GetGlobal(const char *key, const std::string &defaultValue);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \note This operates on the global config.
|
||||
@@ -121,6 +142,14 @@ public:
|
||||
/// \return The value stored under the key, or the default
|
||||
/// value.
|
||||
static std::string GetGlobal(std::string &key, const std::string &defaultValue);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
static void PutGlobal(std::string &key, const std::string &value);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
static void PutGlobal(const char *key, const std::string &value);
|
||||
#endif
|
||||
|
||||
/// \brief The constructor doesn't need any initialisation.
|
||||
@@ -163,6 +192,13 @@ public:
|
||||
/// \return The value stored under the key, or an empty string.
|
||||
std::string Get(std::string &key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \return The value stored under the key, or an empty string.
|
||||
std::string Get(const char *key);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
@@ -173,6 +209,31 @@ public:
|
||||
/// value.
|
||||
std::string Get(std::string &key, std::string defaultValue);
|
||||
|
||||
/// \brief Get the value stored for the key from the config.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param defaultValue A default value to cache and use if no
|
||||
/// value is stored under the key.
|
||||
/// \return The value stored under the key, or the default
|
||||
/// value.
|
||||
std::string Get(const char *key, std::string defaultValue);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param value The value to set.
|
||||
void Put(std::string &key, const std::string value);
|
||||
|
||||
/// \brief Set a configuration value. This will override any
|
||||
/// value set.
|
||||
///
|
||||
/// \param key The key to look up. See the class documentation
|
||||
/// for information on how this is used.
|
||||
/// \param value The value to set.
|
||||
void Put(const char *key, const std::string value);
|
||||
private:
|
||||
std::string envPrefix;
|
||||
std::map<std::string, std::string> vars;
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#include <regex>
|
||||
#include <utility>
|
||||
|
||||
#include <vector>
|
||||
#include <scsl/Flags.h>
|
||||
#include <scsl/StringUtil.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace scsl {
|
||||
@@ -300,7 +300,6 @@ Flags::Parse(int argc, char **argv, bool skipFirst)
|
||||
throw std::runtime_error("unhandled parse state");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ParseStatus::OK;
|
||||
@@ -313,26 +312,44 @@ Flags::Usage(std::ostream &os, int exitCode)
|
||||
os << this->name << ":\t";
|
||||
auto indent = this->name.size() + 7;
|
||||
|
||||
scstring::WriteTabIndented(os, description, 72 - indent, indent / 8, false);
|
||||
scstring::WriteTabIndented(os, this->description, 72 - indent,
|
||||
indent / 8, false);
|
||||
os << "\n\n";
|
||||
|
||||
for (const auto &pair: this->flags) {
|
||||
auto argDesc = pair.second->Description;
|
||||
if (!argDesc.empty()) {
|
||||
argDesc += ' ';
|
||||
}
|
||||
auto argLine = "\t" + pair.first;
|
||||
switch (pair.second->Type) {
|
||||
case FlagType::Boolean:
|
||||
argLine += "\t\t";
|
||||
argDesc += "(default=false)";
|
||||
break;
|
||||
case FlagType::Integer:
|
||||
argLine += " int\t\t";
|
||||
if (pair.second->Value.i != 0) {
|
||||
argDesc += "(default=" + std::to_string(pair.second->Value.i) + ")";
|
||||
}
|
||||
break;
|
||||
case FlagType::UnsignedInteger:
|
||||
argLine += " uint\t\t";
|
||||
if (pair.second->Value.u != 0) {
|
||||
argDesc += "(default=" + std::to_string(pair.second->Value.u) + ")";
|
||||
}
|
||||
break;
|
||||
case FlagType::SizeT:
|
||||
argLine += " size_t\t";
|
||||
if (pair.second->Value.size != 0) {
|
||||
argDesc += "(default=" + std::to_string(pair.second->Value.size) + ")";
|
||||
}
|
||||
break;
|
||||
case FlagType::String:
|
||||
argLine += " string\t";
|
||||
if (pair.second->Value.s != nullptr && !(pair.second->Value.s->empty())) {
|
||||
argDesc += "(default=" + *(pair.second->Value.s) + ")";
|
||||
}
|
||||
break;
|
||||
case FlagType::Unknown:
|
||||
// fallthrough
|
||||
@@ -347,8 +364,8 @@ Flags::Usage(std::ostream &os, int exitCode)
|
||||
|
||||
os << argLine;
|
||||
indent = argLine.size();
|
||||
scstring::WriteTabIndented(os, pair.second->Description,
|
||||
72-indent, (indent/8)+2, false);
|
||||
scstring::WriteTabIndented(os, argDesc, 72 - indent,
|
||||
(indent / 8) + 2, false);
|
||||
}
|
||||
|
||||
os << "\n";
|
||||
@@ -456,4 +473,3 @@ Flags::GetString(std::string fName, std::string &flagValue)
|
||||
|
||||
|
||||
}// namespace scsl
|
||||
|
||||
|
||||
@@ -83,6 +83,13 @@ SimpleConfig::GetGlobal(std::string &key)
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::GetGlobal(const char *key)
|
||||
{
|
||||
return globalConfig.Get(key);
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue)
|
||||
{
|
||||
@@ -90,6 +97,27 @@ SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue)
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::GetGlobal(const char *key, const std::string &defaultValue)
|
||||
{
|
||||
return globalConfig.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::PutGlobal(std::string &key, const std::string &value)
|
||||
{
|
||||
return globalConfig.Put(key, value);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::PutGlobal(const char *key, const std::string &value)
|
||||
{
|
||||
return globalConfig.Put(key, value);
|
||||
}
|
||||
|
||||
|
||||
SimpleConfig::SimpleConfig()
|
||||
{
|
||||
}
|
||||
@@ -153,6 +181,14 @@ SimpleConfig::Get(std::string &key)
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::Get(const char *key)
|
||||
{
|
||||
auto keyStr = std::string(key);
|
||||
return this->Get(keyStr, "");
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::Get(std::string &key, std::string defaultValue)
|
||||
{
|
||||
@@ -173,6 +209,29 @@ SimpleConfig::Get(std::string &key, std::string defaultValue)
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
SimpleConfig::Get(const char *key, std::string defaultValue)
|
||||
{
|
||||
auto keyStr = std::string(key);
|
||||
return this->Get(keyStr, std::move(defaultValue));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::Put(std::string &key, const std::string value)
|
||||
{
|
||||
this->vars[key] = std::move(value);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SimpleConfig::Put(const char *key, const std::string value)
|
||||
{
|
||||
auto keyStr = std::string(key);
|
||||
this->vars[std::move(keyStr)] = std::move(value);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
SimpleConfig::KeyList()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user