summaryrefslogtreecommitdiff
path: root/Transceiver/TCIProtocol.hpp
blob: 9dd2b3ddabfa4f37aa949849df3e5b512d7e27a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef TCI_PROTOCOL_HPP__
#define TCI_PROTOCOL_HPP__

#include <QString>
#include <QtGlobal>

namespace TciProtocol
{
  inline bool parse_frequency (QString const& text, quint64 * frequency)
  {
    if (!frequency || text.isEmpty ())
      {
        return false;
      }

    for (auto const character : text)
      {
        if (character < QLatin1Char {'0'} || character > QLatin1Char {'9'})
          {
            return false;
          }
      }

    bool ok {false};
    auto const parsed = text.toULongLong (&ok, 10);
    if (!ok)
      {
        return false;
      }

    *frequency = parsed;
    return true;
  }

  inline bool frequency_difference_exceeds (quint64 lhs, quint64 rhs, quint64 threshold)
  {
    return lhs > rhs ? lhs - rhs > threshold : rhs - lhs > threshold;
  }
}

#endif