Skip to content

Commit acb2679

Browse files
committed
Add instance (singleton) template base
Add timer example Fix documentation and naming typos
1 parent 696dca2 commit acb2679

File tree

12 files changed

+250
-38
lines changed

12 files changed

+250
-38
lines changed

cmake/find_package.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
#
3030

3131
find_package(Microsoft.GSL CONFIG)
32+
find_package(Threads REQUIRED)

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ add_subdirectory(command)
3434
add_subdirectory(cpuinfo)
3535
add_subdirectory(double)
3636
add_subdirectory(pipe)
37+
add_subdirectory(timer)

examples/timer/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# 1. Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
#
11+
# 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# this list of conditions and the following disclaimer in the documentation
13+
# and/or other materials provided with the distribution.
14+
#
15+
# 3. Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived from
17+
# this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
#
30+
31+
project(timer)
32+
33+
add_executable(${PROJECT_NAME}
34+
main.cpp
35+
)
36+
37+
target_link_libraries(${PROJECT_NAME} PRIVATE modern.cpp.core Threads::Threads)

examples/timer/main.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* 3. Neither the name of the copyright holder nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/* stl header */
32+
#include <iostream>
33+
34+
/* modern.cpp.core header */
35+
#include <Timer.h>
36+
37+
constexpr int intervallSeconds = 1;
38+
constexpr int secondsToMilliseconds = 1000;
39+
constexpr int exitSeconds = 15;
40+
41+
int main() {
42+
43+
int intervall = 1;
44+
bool stop = false;
45+
vx::Timer intervallTimer = vx::Timer();
46+
intervallTimer.setInterval( [&intervall, &stop]() {
47+
48+
std::cout << "Intervall: " << intervall << std::endl;
49+
intervall++;
50+
if ( intervall == exitSeconds ) {
51+
52+
stop = true;
53+
}
54+
}, intervallSeconds * secondsToMilliseconds );
55+
56+
while ( true ) {
57+
58+
/* Leave the app run infinity */
59+
if ( stop ) {
60+
61+
break;
62+
}
63+
}
64+
}

source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_library(${PROJECT_NAME}
4949
Timing.cpp
5050
Timing.h
5151
templates/CSVWriter.h
52+
templates/InstanceBase.h
5253
templates/Timer.h
5354
${${PROJECT_NAME}_os_src}
5455
)

source/CPU.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,68 +54,68 @@ namespace vx {
5454
unsigned int _subleaf = 0 );
5555

5656
/**
57-
* @brief Return stepping of cpu.
58-
* @return Stepping of cpu.
57+
* @brief Return stepping of CPU.
58+
* @return Stepping of CPU.
5959
*/
6060
inline unsigned int stepping() const { return m_leaf[0] & 0xF; }
6161

6262
/**
63-
* @brief Return model of cpu.
64-
* @return Model of cpu.
63+
* @brief Return model of CPU.
64+
* @return Model of CPU.
6565
*/
6666
inline unsigned int model() const { return ( m_leaf[0] >> 4 ) & 0xF; }
6767

6868
/**
69-
* @brief Return family of cpu.
70-
* @return Family of cpu.
69+
* @brief Return family of CPU.
70+
* @return Family of CPU.
7171
*/
7272
inline unsigned int family() const { return ( m_leaf[0] >> 8 ) & 0xF; }
7373

7474
/**
75-
* @brief Return type of cpu.
76-
* @return Type of cpu.
75+
* @brief Return type of CPU.
76+
* @return Type of CPU.
7777
*/
7878
inline unsigned int type() const { return ( m_leaf[0] >> 12 ) & 0x3; }
7979

8080
/**
81-
* @brief Return extended model of cpu.
82-
* @return Extended model of cpu.
81+
* @brief Return extended model of CPU.
82+
* @return Extended model of CPU.
8383
*/
8484
inline unsigned int extendedModel() const { return ( m_leaf[0] >> 16 ) & 0xF; }
8585

8686
/**
87-
* @brief Return extended family of cpu.
88-
* @return Extended family of cpu.
87+
* @brief Return extended family of CPU.
88+
* @return Extended family of CPU.
8989
*/
9090
inline unsigned int extendedFamily() const { return ( m_leaf[0] >> 20 ) & 0xFF; }
9191

9292
/**
93-
* @brief Does cpu support smx?
94-
* @return True, if the cpu supports smx - otherwise false.
93+
* @brief Does CPU support SMX?
94+
* @return True, if the CPU supports SMX - otherwise false.
9595
*/
9696
inline bool smxSupport() const { return ( m_leaf[2] >> 6 ) & 1; }
9797

9898
/**
99-
* @brief Does cpu support sgx?
100-
* @return True, if the cpu supports sgx - otherwise false.
99+
* @brief Does CPU support SGX?
100+
* @return True, if the CPU supports SGX - otherwise false.
101101
*/
102102
inline bool sgxSupport() const { return ( m_extendedLeaf[1] >> 2 ) & 0x1; }
103103

104104
/**
105-
* @brief Does cpu support sgx launch control?
106-
* @return True, if the cpu supports sgx launch control - otherwise false.
105+
* @brief Does CPU support SGX launch control?
106+
* @return True, if the CPU supports SGX launch control - otherwise false.
107107
*/
108108
inline bool sgxLaunchControlSupport() const { return ( m_extendedLeaf[2] >> 30 ) & 0x01; }
109109

110110
/**
111-
* @brief Does cpu support sgx version 1?
112-
* @return True, if the cpu supports sgx version 1 - otherwise false.
111+
* @brief Does CPU support SGX version 1?
112+
* @return True, if the CPU supports SGX version 1 - otherwise false.
113113
*/
114114
inline bool sgxVersion1Support() const { return m_sgxLeaf[0] & 0x1; }
115115

116116
/**
117-
* @brief Does cpu support sgx version 2?
118-
* @return True, if the cpu supports sgx version 2 - otherwise false.
117+
* @brief Does CPU support SGX version 2?
118+
* @return True, if the CPU supports SGX version 2 - otherwise false.
119119
*/
120120
inline bool sgxVersion2Support() const { return ( m_sgxLeaf[0] >> 1 ) & 0x1; }
121121

source/Exec.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
namespace vx {
4040

4141
/**
42-
* @brief Execute external application and return the stdout output.
42+
* @brief Execute the external application and return the stdout output.
4343
* @param _command Command to run.
4444
* @return Return the stdout output.
4545
*/
4646
std::string exec( const std::string &_command );
4747

4848
/**
49-
* @brief result Exit code of command.
50-
* @return The result code.
49+
* @brief result Exit code of the command.
50+
* @return The resultint code.
5151
*/
5252
int result();
5353

source/Serial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace vx {
9999

100100
/**
101101
* @brief Flush the serial port.
102-
* @return True, if fushing is successful - otherwise false.
102+
* @return True, if flushing is successful - otherwise false.
103103
*/
104104
bool flush() const;
105105

@@ -117,7 +117,7 @@ namespace vx {
117117
std::string read() const;
118118

119119
/**
120-
* @brief Descriptor of current device.
120+
* @brief Descriptor of the current device.
121121
* @return The descriptor of the serial device - -1 is not a valid descriptor.
122122
*/
123123
inline int descriptor() const { return m_descriptor; }

source/Timing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace vx {
8888
std::chrono::time_point<std::chrono::high_resolution_clock> m_start = {};
8989

9090
/**
91-
* @brief Clock to calculate the elapsed cpu time.
91+
* @brief Clock to calculate the elapsed CPU time.
9292
*/
9393
std::clock_t m_cpu = 0;
9494
};

source/templates/CSVWriter.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ namespace vx {
4949
/**
5050
* @brief Default constructor for CsvWriter.
5151
* @param _filename Filename for the csv file.
52-
* @param _delimeter Delimeter of values.
52+
* @param _delimiter Delimiter of values.
5353
* @param _linePrefix Prefix for every line.
5454
* @param _lineSuffix Suffix for every line.
5555
*/
5656
explicit CSVWriter( const std::string &_filename,
57-
const std::string &_delimeter = ",",
57+
const std::string &_delimiter = ",",
5858
const std::string &_linePrefix = {},
5959
const std::string &_lineSuffix = {} ) :
60-
m_filename( _filename ), m_delimeter( _delimeter ), m_linePrefix( _linePrefix ), m_lineSuffix( _lineSuffix ) {}
60+
m_filename( _filename ), m_delimiter( _delimiter ), m_linePrefix( _linePrefix ), m_lineSuffix( _lineSuffix ) {}
6161

6262
/**
6363
* @brief Write out the values.
@@ -71,13 +71,13 @@ namespace vx {
7171
file.open( m_filename, std::ios::app );
7272

7373
file << m_linePrefix;
74-
/* Iterate over the range and add each lement to file seperated by delimeter. */
74+
/* Iterate over the range and add each element to file separated by delimiter. */
7575
while ( _first != _last ) {
7676

7777
file << *_first;
7878
if ( ++_first != _last ) {
7979

80-
file << m_delimeter;
80+
file << m_delimiter;
8181
}
8282
}
8383
file << m_lineSuffix;
@@ -94,9 +94,9 @@ namespace vx {
9494
std::string m_filename = {};
9595

9696
/**
97-
* @brief Delimeter for values.
97+
* @brief Delimiter for values.
9898
*/
99-
std::string m_delimeter = {};
99+
std::string m_delimiter = {};
100100

101101
/**
102102
* @brief Prefix for every line.

0 commit comments

Comments
 (0)