libcyberradio 22.01.24
ConfigString.cpp
1/***************************************************************************
2 * \file ConfigString.cpp
3 * \brief Defines a string class that supports several non-string data
4 * types for value setting and retrieval.
5 * \author DA
6 * \copyright (c) 2018 CyberRadio Solutions, Inc. All rights reserved.
7 *
8 * \note Requires C++11 compiler support.
9 *
10 ***************************************************************************/
11
12#include "LibCyberRadio/Driver/ConfigString.h"
13//#include <iostream>
14
15
16namespace LibCyberRadio
17{
18 namespace Driver
19 {
20
22 {
23 //std::cout << "[ConfigString assign][in] string=\"" << s << "\"" << std::endl;
24 std::string::operator=( s );
25 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
26 return *this;
27 }
28
30 {
31 //std::cout << "[ConfigString assign][in] literal=\"" << s << "\"" << std::endl;
32 std::string::operator=( s );
33 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
34 return *this;
35 }
36
38 {
39 //std::cout << "[ConfigString assign][in] int=" << i << std::endl;
40 std::string::operator=( std::to_string(i) );
41 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
42 return *this;
43 }
44
46 {
47 //std::cout << "[ConfigString assign][in] uint=" << i << std::endl;
48 std::string::operator=( std::to_string(i) );
49 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
50 return *this;
51 }
52
54 {
55 //std::cout << "[ConfigString assign][in] long=" << l << std::endl;
56 std::string::operator=( std::to_string(l) );
57 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
58 return *this;
59 }
60
62 {
63 //std::cout << "[ConfigString assign][in] bool=" << (b ? "true" : "false") << std::endl;
64 std::string::operator=( b ? "1" : "0" );
65 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
66 return *this;
67 }
68
70 {
71 //std::cout << "[ConfigString assign][in] float=" << f << std::endl;
72 std::string::operator=( std::to_string(f) );
73 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
74 return *this;
75 }
76
78 {
79 //std::cout << "[ConfigString assign][in] dbl=" << f << std::endl;
80 std::string::operator=( std::to_string(f) );
81 //std::cout << "[ConfigString assign][out] string=\"" << *this << "\"" << std::endl;
82 return *this;
83 }
84
86 {
87 return std::stoi(*this);
88 }
89
90 unsigned int ConfigString::asUInt() const
91 {
92 return (unsigned int)std::stoul(*this);
93 }
94
96 {
97 return std::stol(*this);
98 }
99
101 {
102 int tmp = this->asInt();
103 return !(tmp == 0);
104 }
105
107 {
108 return std::stof(*this);
109 }
110
112 {
113 return std::stod(*this);
114 }
115
116 } // namespace Driver
117
118} // namespace LibCyberRadio
long asLong() const
Retrieves a value from this object.
ConfigString & operator=(const std::string &s)
Assigns a value to this object.
float asFloat() const
Retrieves a value from this object.
bool asBool() const
Retrieves a value from this object.
int asInt() const
Retrieves a value from this object.
double asDouble() const
Retrieves a value from this object.
unsigned int asUInt() const
Retrieves a value from this object.
ConfigString()
Constructs an empty ConfigString object.
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
Definition App.h:24