9 Commits

Author SHA1 Message Date
94672bba98 SimpleConfig: Put was setting key=key, not key=value. 2023-10-24 13:22:54 -07:00
33675c18ec Flags: show default value. 2023-10-24 12:12:17 -07:00
f76d524999 SimpleConfig: Add missing definition. 2023-10-23 21:51:43 -07:00
1bc8a9ad82 SimpleConfig: Add const char * key variants. 2023-10-23 21:47:33 -07:00
9a83cf6c08 Add option to set config values. 2023-10-23 21:09:56 -07:00
28238ba041 Install headers correctly. 2023-10-23 20:58:23 -07:00
044afb9a60 Darwin: don't build .pkg, build stgz and tgz packages. 2023-10-23 03:04:00 -07:00
8ba8dee78d Bump patch to cut new packages. 2023-10-22 15:18:56 -07:00
7f0a814b3f Vector: IsParallel now works.
There should be a devlog entry shortly describing this, but the
code for IsParallel wasn't working on arm64 (Linux or Darwin).
Floating point math is weird.
2023-10-22 15:18:40 -07:00
8 changed files with 173 additions and 22 deletions

View File

@@ -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" />

View File

@@ -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)

View File

@@ -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()

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -25,16 +25,16 @@
#include <regex>
#include <utility>
#include <vector>
#include <scsl/Flags.h>
#include <scsl/StringUtil.h>
#include <vector>
namespace scsl {
static const std::regex isFlag("^--?[a-zA-Z0-9][a-zA-Z0-9-_]*$",
std::regex_constants::nosubs|std::regex_constants::optimize);
std::regex_constants::nosubs | std::regex_constants::optimize);
std::string
Flags::ParseStatusToString(ParseStatus status)
@@ -82,7 +82,7 @@ Flags::Flags(std::string fName, std::string fDescription)
Flags::~Flags()
{
for (auto &flag : this->flags) {
for (auto &flag: this->flags) {
if (flag.second->Type == FlagType::String) {
delete flag.second->Value.s;
}
@@ -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) {
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";
@@ -382,7 +399,7 @@ Flags::Arg(size_t i)
Flag *
Flags::checkGetArg(std::string& fName, FlagType eType)
Flags::checkGetArg(std::string &fName, FlagType eType)
{
if (this->flags[fName] == nullptr) {
return nullptr;
@@ -455,5 +472,4 @@ Flags::GetString(std::string fName, std::string &flagValue)
}
} // namespace scsl
}// namespace scsl

View File

@@ -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()
{