Skip to content

Commit

Permalink
MNT: NUM_TERMINALS -> ArraySize
Browse files Browse the repository at this point in the history
Don't rely on generated size macro
  • Loading branch information
JJL772 committed Feb 4, 2022
1 parent 5ab7744 commit d984eec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ek9000App/src/devEK9000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ devEK9000Terminal* devEK9000Terminal::ProcessRecordName(const char* recname, int
}

void devEK9000Terminal::GetTerminalInfo(int termid, int& inp_size, int& out_size) {
for (int i = 0; i < NUM_TERMINALS; i++) {
for (int i = 0; i < ArraySize(g_pTerminalInfos); i++) {
if (g_pTerminalInfos[i]->m_nID == (uint32_t)termid) {
inp_size = g_pTerminalInfos[i]->m_nInputSize;
out_size = g_pTerminalInfos[i]->m_nOutputSize;
Expand Down Expand Up @@ -935,7 +935,7 @@ void ek9000ConfigureTerminal(const iocshArgBuf* args) {
}

int tid = 0;
for (int i = 0; i < NUM_TERMINALS; i++) {
for (int i = 0; i < ArraySize(g_pTerminalInfos); i++) {
if (strcmp(g_pTerminalInfos[i]->m_pString, type) == 0) {
tid = g_pTerminalInfos[i]->m_nID;
break;
Expand Down
2 changes: 1 addition & 1 deletion ek9000App/src/ekUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct iocshHandles_t {
std::vector<iocshHandles_t*> functions;

const STerminalInfoConst_t* util::FindTerminal(unsigned int id) {
for (unsigned int i = 0; i < NUM_TERMINALS; i++)
for (unsigned int i = 0; i < ArraySize(g_pTerminalInfos); i++)
if (g_pTerminalInfos[i]->m_nID == id)
return g_pTerminalInfos[i];
return NULL;
Expand Down
8 changes: 8 additions & 0 deletions ek9000App/src/ekUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ template <class MutexT> class CAutoLockWrapper {

#define AUTO_LOCK(x) CAutoLockWrapper<epicsMutex> __auto_lock(x)

/**
* Determine size of an array
*/
template<class T, size_t N>
size_t ArraySize(T(&arr)[N]) {
return N;
}

namespace util
{
/**
Expand Down
4 changes: 1 addition & 3 deletions ek9000App/src/scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@
header.add_define(name + "_INPUT_SIZE", str(insize))
header.add_init_struct("STerminalInfoConst_t", name + "_Info", name + "_STRING", name + "_ID",
name + "_OUTPUT_SIZE", name + "_INPUT_SIZE", static=True, const=True)
header.newlines(1)
header.add_define("NUM_TERMINALS", str(count))
header.newlines(1)
header.newlines(2)
header.add_array_variable("g_pTerminalInfos", "STerminalInfoConst_t*", vars, const=True, static=True)
except KeyError as e:
print("Malformed JSON:")
Expand Down

0 comments on commit d984eec

Please sign in to comment.