Skip to content
Snippets Groups Projects
Commit 2dc541dc authored by Pep Martí Saumell's avatar Pep Martí Saumell
Browse files

[improvement] Added template for printing arrays

parent ac03ff9a
No related branches found
No related tags found
3 merge requests!20new tag,!19new tag,!13Resolve "Templatize prints from utils.h"
...@@ -17,10 +17,20 @@ ...@@ -17,10 +17,20 @@
namespace GnssUtils namespace GnssUtils
{ {
void print(std::string& _msg); void print(std::string& _msg);
void printArray(std::string _name, int* _array, int size);
void printArray(std::string _name, unsigned char* _array, int size); template <typename T, size_t size>
void printArray(std::string _name, double* _array, int size); void printArray(std::string name, T (&array)[size])
void printArray(std::string _name, float* _array, int size); {
std::cout << name << ": [";
for (int ii = 0; ii < size; ++ii)
{
std::cout << array[ii];
if (ii == size - 1)
std::cout << "] \n";
else
std::cout << ",";
}
}
template <typename T> template <typename T>
inline bool addToArray(const T& new_element, T*& array, int& n, int& nmax) inline bool addToArray(const T& new_element, T*& array, int& n, int& nmax)
......
...@@ -163,15 +163,15 @@ static void Observations::print(obsd_t& _obs) ...@@ -163,15 +163,15 @@ static void Observations::print(obsd_t& _obs)
GnssUtils::print(msg); GnssUtils::print(msg);
std::cout << "Time [s]: " << _obs.time.time << " + " << _obs.time.sec << "\n"; std::cout << "Time [s]: " << _obs.time.time << " + " << _obs.time.sec << "\n";
std::cout << "Time valid: " << _obs.timevalid << std::endl; std::cout << "Time valid: " << _obs.timevalid << std::endl;
printArray("SNR: ", _obs.SNR, ARRAY_SIZE(_obs.SNR)); printArray<unsigned char, ARRAY_SIZE(_obs.SNR)>("SNR: ", _obs.SNR);
printArray("LLI: ", _obs.LLI, ARRAY_SIZE(_obs.LLI)); printArray<unsigned char, ARRAY_SIZE(_obs.LLI)>("LLI: ", _obs.LLI);
printArray("code: ", _obs.code, ARRAY_SIZE(_obs.code)); printArray<unsigned char, ARRAY_SIZE(_obs.code)>("code: ", _obs.code);
printArray("code: ", _obs.qualL, ARRAY_SIZE(_obs.qualL)); printArray<unsigned char, ARRAY_SIZE(_obs.qualL)>("code: ", _obs.qualL);
printArray("code: ", _obs.qualP, ARRAY_SIZE(_obs.qualP)); printArray<unsigned char, ARRAY_SIZE(_obs.qualP)>("code: ", _obs.qualP);
printf("Freq. channel: %uc \n", _obs.freq); printf("Freq. channel: %uc \n", _obs.freq);
printArray("L: ", _obs.L, ARRAY_SIZE(_obs.L)); printArray<double, ARRAY_SIZE(_obs.L)>("L: ", _obs.L);
printArray("P: ", _obs.P, ARRAY_SIZE(_obs.P)); printArray<double, ARRAY_SIZE(_obs.P)>("P: ", _obs.P);
printArray("D: ", _obs.D, ARRAY_SIZE(_obs.D)); printArray<float, ARRAY_SIZE(_obs.D)>("D: ", _obs.D);
} }
void Observations::printBySat(const int& _sat_number) void Observations::printBySat(const int& _sat_number)
......
...@@ -9,58 +9,6 @@ void print(std::string& _msg) ...@@ -9,58 +9,6 @@ void print(std::string& _msg)
std::cout << msg << "\n"; std::cout << msg << "\n";
} }
void printArray(std::string _name, int* _array, int size)
{
std::cout << _name << ": [";
for (int ii = 0; ii < size; ++ii)
{
std::cout << _array[ii];
if (ii == size - 1)
std::cout << "] \n";
else
std::cout << ",";
}
}
void printArray(std::string _name, unsigned char* _array, int size)
{
std::cout << _name << ": [";
for (int ii = 0; ii < size; ++ii)
{
std::cout << (int)(_array[ii]);
if (ii == size - 1)
std::cout << "] \n";
else
std::cout << ",";
}
}
void printArray(std::string _name, double* _array, int size)
{
std::cout << _name << ": [";
for (int ii = 0; ii < size; ++ii)
{
std::cout << _array[ii];
if (ii == size - 1)
std::cout << "] \n";
else
std::cout << ",";
}
}
void printArray(std::string _name, float* _array, int size)
{
std::cout << _name << ": [";
for (int ii = 0; ii < size; ++ii)
{
std::cout << _array[ii];
if (ii == size - 1)
std::cout << "] \n";
else
std::cout << ",";
}
}
} // namespace GnssUtils } // namespace GnssUtils
bool operator==(const gtime_t& time1, const gtime_t& time2) bool operator==(const gtime_t& time1, const gtime_t& time2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment