Skip to content

Commit bdc60d1

Browse files
committed
Slightly clean up api
1 parent 0b88469 commit bdc60d1

File tree

12 files changed

+116
-113
lines changed

12 files changed

+116
-113
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ make -j`nproc`
1111

1212
## Classes
1313
- **CPU** - Get CPU information.
14-
- **DoubleExtras** - Less, Greater, Equal, Between, Round, Split.
14+
- **Double** - Less, Greater, Equal, Between, Round, Split.
1515
- **Exec** - Run command and return stdout or mixed (stdout and stderr) and result code.
16-
- **KeyState** - Check for caps lock state.
16+
- **Keyboard** - Check for caps lock state.
1717
- **Serial** - Serial communication class.
18-
- **StringExtras** - LeftTrim, RightTrim, Trim.
18+
- **StringExtra** - LeftTrim, RightTrim, Trim.
1919
- **Timing** - Measuring time, cpu and real time.
2020

2121
## Template classes
2222
- **CSVWriter** - Write out comma-separated values.
23+
- **Singleton** - Singleton templace class.
2324
- **Timer** - Timeout thread on time or interval.
2425

2526
## Unixservice class

examples/double/main.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <iostream>
3333

3434
/* modern.cpp.core header */
35-
#include <DoubleExtras.h>
35+
#include <Double.h>
3636

3737
int main() {
3838

@@ -48,108 +48,108 @@ int main() {
4848
/* equals */
4949
std::cout << "----- Equal" << std::endl;
5050

51-
result = vx::doubleEqual( first, second );
51+
result = vx::equal( first, second );
5252
std::cout << first << " == " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
5353

54-
result = vx::doubleEqual( second, third );
54+
result = vx::equal( second, third );
5555
std::cout << second << " == " << third << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
5656

57-
result = vx::doubleEqual( third, fourth );
57+
result = vx::equal( third, fourth );
5858
std::cout << third << " == " << fourth << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
5959

6060
/* less */
6161
std::cout << "----- Less" << std::endl;
6262

63-
result = vx::doubleLess( first, second );
63+
result = vx::less( first, second );
6464
std::cout << first << " < " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
6565

66-
result = vx::doubleLess( second, third );
66+
result = vx::less( second, third );
6767
std::cout << second << " < " << third << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
6868

69-
result = vx::doubleLess( third, fourth );
69+
result = vx::less( third, fourth );
7070
std::cout << third << " < " << fourth << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
7171

72-
result = vx::doubleLess( first, second, true );
72+
result = vx::less( first, second, true );
7373
std::cout << first << " <= " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
7474

75-
result = vx::doubleLess( second, third, true );
75+
result = vx::less( second, third, true );
7676
std::cout << second << " <= " << third << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
7777

78-
result = vx::doubleLess( third, fourth, true );
78+
result = vx::less( third, fourth, true );
7979
std::cout << third << " <= " << fourth << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
8080

8181
/* greater */
8282
std::cout << "----- Greater" << std::endl;
8383

84-
result = vx::doubleGreater( first, second );
84+
result = vx::greater( first, second );
8585
std::cout << first << " > " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
8686

87-
result = vx::doubleGreater( second, third );
87+
result = vx::greater( second, third );
8888
std::cout << second << " > " << third << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
8989

90-
result = vx::doubleGreater( third, fourth );
90+
result = vx::greater( third, fourth );
9191
std::cout << third << " > " << fourth << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
9292

93-
result = vx::doubleGreater( first, second, true );
93+
result = vx::greater( first, second, true );
9494
std::cout << first << " >= " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
9595

96-
result = vx::doubleGreater( second, third, true );
96+
result = vx::greater( second, third, true );
9797
std::cout << second << " >= " << third << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
9898

99-
result = vx::doubleGreater( third, fourth, true );
99+
result = vx::greater( third, fourth, true );
100100
std::cout << third << " >= " << fourth << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
101101

102102
/* between */
103103
std::cout << "----- Between" << std::endl;
104104

105-
result = vx::doubleBetween( first, first, second );
105+
result = vx::between( first, first, second );
106106
std::cout << first << " > " << first << " && " << first << " < " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
107107

108-
result = vx::doubleBetween( second, first, second );
108+
result = vx::between( second, first, second );
109109
std::cout << second << " > " << first << " && " << second << " < " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
110110

111-
result = vx::doubleBetween( fourth, first, second );
111+
result = vx::between( fourth, first, second );
112112
std::cout << fourth << " > " << first << " && " << fourth << " < " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
113113

114-
result = vx::doubleBetween( first, first, second, true );
114+
result = vx::between( first, first, second, true );
115115
std::cout << first << " >= " << first << " && " << first << " <= " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
116116

117-
result = vx::doubleBetween( second, first, second, true );
117+
result = vx::between( second, first, second, true );
118118
std::cout << second << " >= " << first << " && " << second << " <= " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
119119

120-
result = vx::doubleBetween( fourth, first, second, true );
120+
result = vx::between( fourth, first, second, true );
121121
std::cout << fourth << " >= " << first << " && " << fourth << " <= " << second << " result: " << std::boolalpha << result << std::noboolalpha << std::endl;
122122

123123
/* round */
124124
std::cout << "----- Round" << std::endl;
125125

126126
double rounded = 0.0;
127-
rounded = vx::doubleRound( first, 2 );
127+
rounded = vx::round( first, 2 );
128128
std::cout << "round(2) " << first << " result: " << rounded << std::endl;
129129

130-
rounded = vx::doubleRound( second, 2 );
130+
rounded = vx::round( second, 2 );
131131
std::cout << "round(2) " << second << " result: " << rounded << std::endl;
132132

133-
rounded = vx::doubleRound( third, 5 );
133+
rounded = vx::round( third, 5 );
134134
std::cout << "round(5) " << third << " result: " << rounded << std::endl;
135135

136-
rounded = vx::doubleRound( fourth, 5 );
136+
rounded = vx::round( fourth, 5 );
137137
std::cout << "round(5) " << fourth << " result: " << rounded << std::endl;
138138

139139
/* split */
140140
std::cout << "----- Split" << std::endl;
141141

142142
std::pair<double, double> splited = {};
143-
splited = vx::doubleSplit( first );
143+
splited = vx::split( first );
144144
std::cout << "split " << first << " result: " << splited.first << " " << splited.second << std::endl;
145145

146-
splited = vx::doubleSplit( second );
146+
splited = vx::split( second );
147147
std::cout << "split " << second << " result: " << splited.first << " " << splited.second << std::endl;
148148

149-
splited = vx::doubleSplit( third );
149+
splited = vx::split( third );
150150
std::cout << "split " << third << " result: " << splited.first << " " << splited.second << std::endl;
151151

152-
splited = vx::doubleSplit( fourth );
152+
splited = vx::split( fourth );
153153
std::cout << "split " << fourth << " result: " << splited.first << " " << splited.second << std::endl;
154154

155155
return EXIT_SUCCESS;

source/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ add_library(${PROJECT_NAME}
3838
../README.md
3939
CPU.cpp
4040
CPU.h
41-
DoubleExtras.cpp
42-
DoubleExtras.h
41+
Double.cpp
42+
Double.h
4343
Exec.cpp
4444
Exec.h
45-
KeyState.cpp
46-
KeyState.h
47-
StringExtras.cpp
48-
StringExtras.h
45+
Keyboard.cpp
46+
Keyboard.h
47+
StringExtra.cpp
48+
StringExtra.h
4949
Timing.cpp
5050
Timing.h
5151
templates/CSVWriter.h
52-
templates/SingletonBase.h
52+
templates/Singleton.h
5353
templates/Timer.h
5454
${${PROJECT_NAME}_os_src}
5555
)
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@
3636
#include <vector>
3737

3838
/* local header */
39-
#include "DoubleExtras.h"
39+
#include "Double.h"
4040

4141
namespace vx {
4242

43-
bool doubleEqual( double _left,
44-
double _right ) {
43+
bool equal( double _left,
44+
double _right ) {
4545

4646
return ( std::fabs( _left - _right ) < std::numeric_limits<double>::epsilon() );
4747
}
4848

49-
bool doubleLess( double _left,
50-
double _right,
51-
bool _orEqual ) {
49+
bool less( double _left,
50+
double _right,
51+
bool _orEqual ) {
5252

5353
if ( std::fabs( _left - _right ) < std::numeric_limits<double>::epsilon() ) {
5454

@@ -57,9 +57,9 @@ namespace vx {
5757
return ( _left < _right );
5858
}
5959

60-
bool doubleGreater( double _left,
61-
double _right,
62-
bool _orEqual ) {
60+
bool greater( double _left,
61+
double _right,
62+
bool _orEqual ) {
6363

6464
if ( std::fabs( _left - _right ) < std::numeric_limits<double>::epsilon() ) {
6565

@@ -68,22 +68,22 @@ namespace vx {
6868
return ( _left > _right );
6969
}
7070

71-
bool doubleBetween( double _value,
72-
double _min,
73-
double _max,
74-
bool _orEqual ) {
71+
bool between( double _value,
72+
double _min,
73+
double _max,
74+
bool _orEqual ) {
7575

76-
return ( doubleGreater( _value, _min, _orEqual ) && doubleLess( _value, _max, _orEqual ) );
76+
return ( greater( _value, _min, _orEqual ) && less( _value, _max, _orEqual ) );
7777
}
7878

79-
double doubleRound( double _value,
80-
std::size_t _precision ) {
79+
double round( double _value,
80+
std::size_t _precision ) {
8181

8282
std::vector<double> v = { 1, 10, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8 };
8383
return std::floor( _value * v[ _precision ] + 0.5 ) / v[ _precision ];
8484
}
8585

86-
std::pair<double, double> doubleSplit( double _value ) {
86+
std::pair<double, double> split( double _value ) {
8787

8888
double integral = 0.0;
8989
double fraction = std::modf( _value, &integral );
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace vx {
4444
* @param _right The second value.
4545
* @return True, if _left and _right are equal - otherwise false.
4646
*/
47-
bool doubleEqual( double _left,
48-
double _right );
47+
bool equal( double _left,
48+
double _right );
4949

5050
/**
5151
* @brief Is _left less than _right or _orEqual?
@@ -55,9 +55,9 @@ namespace vx {
5555
* @return True, if _left is less than _right or _left and _right are equal and
5656
* _orEqual is set to true - otherwise false.
5757
*/
58-
bool doubleLess( double _left,
59-
double _right,
60-
bool _orEqual = false );
58+
bool less( double _left,
59+
double _right,
60+
bool _orEqual = false );
6161

6262
/**
6363
* @brief Is _left greater than _right or _orEqual?
@@ -67,9 +67,9 @@ namespace vx {
6767
* @return True, if _left is greater than _right or _left and _right are equal and
6868
* _orEqual is set to true - otherwise false.
6969
*/
70-
bool doubleGreater( double _left,
71-
double _right,
72-
bool _orEqual = false );
70+
bool greater( double _left,
71+
double _right,
72+
bool _orEqual = false );
7373

7474
/**
7575
* @brief Is _value between _min and _max or _orEqual.
@@ -79,24 +79,24 @@ namespace vx {
7979
* @param _orEqual Is _value == _min or _value == _max
8080
* @return True, if _value is between _min and _max _orEqual - otherwise false.
8181
*/
82-
bool doubleBetween( double _value,
83-
double _min,
84-
double _max,
85-
bool _orEqual = false );
82+
bool between( double _value,
83+
double _min,
84+
double _max,
85+
bool _orEqual = false );
8686

8787
/**
8888
* @brief Round a double _value by _precision. Rounded by default to two decimal places.
8989
* @param _value Value to round.
9090
* @param _precision Decimal places to round.
9191
* @return The rounded value.
9292
*/
93-
double doubleRound( double _value,
94-
std::size_t _precision = 2 );
93+
double round( double _value,
94+
std::size_t _precision = 2 );
9595

9696
/**
9797
* @brief Split a double _value to its integer and decimal places.
9898
* @param _value Value to split.
9999
* @return The integer and decimal places.
100100
*/
101-
std::pair<double, double> doubleSplit( double _value );
101+
std::pair<double, double> split( double _value );
102102
}

source/Exec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ namespace vx {
5959
#endif
6060
}
6161

62-
int result() { return m_resultCode; }
63-
6462
std::string exec( const std::string &_command ) {
6563

6664
std::array<char, bufferSize> buffer {};
@@ -81,4 +79,6 @@ namespace vx {
8179
}
8280
return result;
8381
}
82+
83+
int result() { return m_resultCode; }
8484
}

source/Exec.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
*/
3939
namespace vx {
4040

41+
/**
42+
* @brief Overload for close.
43+
* @param _file File handle to close.
44+
*/
45+
void close( std::FILE *_file );
46+
4147
/**
4248
* @brief Execute the external application and return the stdout output.
4349
* @param _command Command to run.
@@ -46,14 +52,8 @@ namespace vx {
4652
std::string exec( const std::string &_command );
4753

4854
/**
49-
* @brief result Exit code of the command.
50-
* @return The resultint code.
55+
* @brief Result Exit code of the command.
56+
* @return The result code.
5157
*/
5258
int result();
53-
54-
/**
55-
* @brief Overload for pclose.
56-
* @param _file File handle to close.
57-
*/
58-
void close( std::FILE *_file );
5959
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
#endif
3636

3737
/* local header */
38-
#include "KeyState.h"
38+
#include "Keyboard.h"
3939

4040
namespace vx {
4141

42-
bool KeyState::isCapsLockActive() {
42+
bool isCapsLockActive() {
4343

4444
bool isActive = false;
4545

0 commit comments

Comments
 (0)