Skip to content

Commit

Permalink
Support compiling static library with exceptions disabled (#144)
Browse files Browse the repository at this point in the history
* condition CMRC on exceptions being present
* string2float: Use throwing or non-throwing version, depending on exceptions support

Allows complication for the 4ms target architecture for their upcoming device. Addresses #142
  • Loading branch information
danngreen authored Jul 20, 2024
1 parent 466079a commit 096e0a7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/AirwinRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ std::string AirwinRegistry::documentationStringFor(int index)
auto fs = cmrc::awdoc_resources::get_filesystem();
auto doc = std::string("res/awpdoc/") + nm + ".txt";

#ifndef CMRC_NO_EXCEPTIONS
try
{
#endif
if (fs.is_file(doc))
{
auto fn = fs.open(doc);
return std::string(fn.begin(), fn.end());
}
#ifndef CMRC_NO_EXCEPTIONS
}
catch (std::exception &e)
{
}
#endif
return "";
}

Expand Down
51 changes: 39 additions & 12 deletions src/airwin_consolidated_base.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/*
* AirwinConsolidated - an adaptation of the airwindows effect suite
* for various open source clients
*
* This source released under the MIT License, found in ~/LICENSE.md.
*
* Copyright 2023 by the authors as described in the github transaction log
*/
* AirwinConsolidated - an adaptation of the airwindows effect suite
* for various open source clients
*
* This source released under the MIT License, found in ~/LICENSE.md.
*
* Copyright 2023 by the authors as described in the github transaction log
*/

#include "airwin_consolidated_base.h"
#include <string>
#include <iostream>

float AirwinConsolidatedBase::defaultSampleRate{0.f};

bool string2float(const char *txt, float &f)
{
try {
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
try
{
float v = std::stof(txt);
f = v;
return true;
Expand All @@ -24,6 +25,23 @@ bool string2float(const char *txt, float &f)
{
return false;
}
#else
char *pEnd = nullptr;
float v = std::strtof(txt, &pEnd);
if (pEnd == txt)
{
return false;
}
else if (v != INFINITY && v != -INFINITY && (v == HUGE_VALF || v == -HUGE_VALF))
{
return false;
}
else
{
f = v;
return true;
}
#endif
}

bool string2dBNorm(const char *txt, float &f)
Expand All @@ -35,18 +53,27 @@ bool string2dBNorm(const char *txt, float &f)
return true;
}

try {
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
try
{
float v = std::stof(txt);
// float2string ((float)(20.0 * log10 (value)), t, num);
// so db = 20 log10(v)
// v = 10^(db/20);
f = std::pow(10, v/20);
f = std::pow(10, v / 20);
return true;
}
catch (const std::exception &e)
{

return false;
}
#else
if (auto ok = string2float(txt, f))
{
f = std::pow(10, f / 20);
return true;
}
#endif
return false;
}
}

0 comments on commit 096e0a7

Please sign in to comment.