summaryrefslogtreecommitdiffstats
path: root/src/utils.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-30 11:31:56 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-30 11:31:56 +0100
commitf21352094c0949b643721ee5387fefae0cdab507 (patch)
treebae2813b66308d1478f1537fbd5acb9ec1af34b5 /src/utils.cpp
parentb073c0eb1e5bf676a24f225779cc31d3c9f21fd4 (diff)
downloaddabmux-f21352094c0949b643721ee5387fefae0cdab507.tar.gz
dabmux-f21352094c0949b643721ee5387fefae0cdab507.tar.bz2
dabmux-f21352094c0949b643721ee5387fefae0cdab507.zip
Move hexparse to utils and add default PRBS poly
Diffstat (limited to 'src/utils.cpp')
-rw-r--r--src/utils.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils.cpp b/src/utils.cpp
index 9976e88..f0df772 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -426,3 +426,29 @@ void printEnsemble(const shared_ptr<dabEnsemble> ensemble)
}
}
+long hexparse(const std::string& input)
+{
+ long value = 0;
+ errno = 0;
+
+ // Do not use strtol's base=0 because
+ // we do not want to accept octal.
+ if (input.find("0x") == 0) {
+ value = strtol(input.c_str() + 2, nullptr, 16);
+ }
+ else {
+ value = strtol(input.c_str(), nullptr, 10);
+ }
+
+ if ((value == LONG_MIN or value == LONG_MAX) and errno == ERANGE) {
+ throw out_of_range("hexparse: value out of range");
+ }
+ else if (value == 0 and errno != 0) {
+ stringstream ss;
+ ss << "hexparse: " << strerror(errno);
+ throw invalid_argument(ss.str());
+ }
+
+ return value;
+}
+