• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blues / note-arduino / 13523375661

25 Feb 2025 02:18PM CUT coverage: 90.526% (-4.3%) from 94.831%
13523375661

Pull #132

github

web-flow
Merge 94f998ff5 into 2efe3032e
Pull Request #132: WIP: Template Singleton `make_` functions

98 of 137 branches covered (71.53%)

Branch coverage included in aggregate %.

28 of 33 new or added lines in 3 files covered. (84.85%)

1 existing line in 1 file now uncovered.

332 of 338 relevant lines covered (98.22%)

15.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/NoteSerial_Arduino.cpp
1
#include "NoteSerial_Arduino.hpp"
2

3
#include "NoteDefines.h"
4

5
#ifndef NOTE_MOCK
6
#ifdef NOTE_ARDUINO_SOFTWARE_SERIAL_SUPPORT
7
#include <SoftwareSerial.h>
8
#endif
9
#else
10
#include "mock/mock-arduino.hpp"
11
#endif
12

13
// Template Meta-Programming (TMP) to extract the nested template type
14
template <typename nested_type>
15
struct ExtractNestedTemplateType {
16
    // Default case: no extraction
17
};
18
template <typename nested_type>
19
struct ExtractNestedTemplateType<MakeNoteSerial_ArduinoParameters<nested_type>> {
20
    using type = nested_type;
21
};
22

23
// Singleton instance of the NoteSerial_Arduino class
24
namespace instance {
25
    inline NoteSerial* & note_serial (void) {
7✔
26
        static NoteSerial* note_serial = nullptr;
27
        return note_serial;
7✔
28
    }
29
};
30

31
NoteSerial *
32
make_note_serial (
3✔
33
    nullptr_t
34
) {
35
    NoteSerial* & note_serial = instance::note_serial();
3✔
36
    if (note_serial) {
3!
37
        delete note_serial;
3!
38
        note_serial = nullptr;
3✔
39
    }
40
    return note_serial;
3✔
41
}
42

43
template <typename T>
44
NoteSerial *
45
make_note_serial (
4✔
46
    T & serial_parameters_
47
) {
48
    NoteSerial* & note_serial = instance::note_serial();
4✔
49
    if (!note_serial) {
4✔
50
        using serial_type = typename ExtractNestedTemplateType<T>::type;
51
        note_serial = new NoteSerial_Arduino<serial_type>(serial_parameters_.serial, serial_parameters_.baud_rate);
3!
52
    }
53

54
    return note_serial;
4✔
55
}
56

57
template <typename T>
58
NoteSerial_Arduino<T>::NoteSerial_Arduino
20✔
59
(
60
    T & serial_,
61
    size_t baud_rate_
62
) :
63
    _notecardSerial(serial_),
20✔
64
    _notecardSerialSpeed(baud_rate_)
20✔
65
{
66
    _notecardSerial.begin(_notecardSerialSpeed);
20!
67
}
20✔
68

69
template <typename T>
70
NoteSerial_Arduino<T>::~NoteSerial_Arduino (
20✔
71
    void
72
)
73
{
74
    _notecardSerial.end();
20✔
75
}
20✔
76

77
template <typename T>
78
size_t
79
NoteSerial_Arduino<T>::available (
2✔
80
    void
81
)
82
{
83
    return _notecardSerial.available();
2✔
84
}
85

86
template <typename T>
87
char
88
NoteSerial_Arduino<T>::receive (
2✔
89
    void
90
)
91
{
92
    return _notecardSerial.read();
2✔
93
}
94

95
template <typename T>
96
bool
97
NoteSerial_Arduino<T>::reset (
4✔
98
    void
99
)
100
{
101
    _notecardSerial.end();
4✔
102
    _notecardSerial.begin(_notecardSerialSpeed);
4✔
103

104
    return true;
4✔
105
}
106

107
template <typename T>
108
size_t
109
NoteSerial_Arduino<T>::transmit (
6✔
110
    uint8_t *buffer,
111
    size_t size,
112
    bool flush
113
)
114
{
115
    size_t result;
116
    result = _notecardSerial.write(buffer, size);
6✔
117
    if (flush) {
6✔
118
        _notecardSerial.flush();
5✔
119
    }
120
    return result;
6✔
121
}
122

123
// Explicitly instantiate the classes and methods for the supported types
124
template class NoteSerial_Arduino<HardwareSerial>;
125
template NoteSerial * make_note_serial<MakeNoteSerial_ArduinoParameters<HardwareSerial>>(MakeNoteSerial_ArduinoParameters<HardwareSerial> &);
126

127
#ifdef NOTE_ARDUINO_SOFTWARE_SERIAL_SUPPORT
128
template class NoteSerial_Arduino<SoftwareSerial>;
129
template NoteSerial * make_note_serial<MakeNoteSerial_ArduinoParameters<SoftwareSerial>>(MakeNoteSerial_ArduinoParameters<SoftwareSerial> &);
130
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc