SenseDevSpec: add NULL checks stringify, ostream::<<
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -23,6 +24,13 @@ struct SenseDeviceSpec
|
||||
|
||||
friend std::ostream& operator<<(
|
||||
std::ostream& os, const SenseDeviceSpec& spec);
|
||||
|
||||
bool operator==(const SenseDeviceSpec& other) const
|
||||
{
|
||||
return sensorType == other.sensorType &&
|
||||
provider == other.provider &&
|
||||
deviceSelector == other.deviceSelector;
|
||||
}
|
||||
};
|
||||
|
||||
struct InteroceptorDeviceSpec : public SenseDeviceSpec
|
||||
@@ -70,18 +78,50 @@ struct CSenseDeviceSpec
|
||||
free(provider);
|
||||
free(deviceSelector);
|
||||
|
||||
for (size_t i = 0; apiParams[i] != nullptr; ++i)
|
||||
if (apiParams)
|
||||
{
|
||||
free(apiParams[i]);
|
||||
for (size_t i = 0; apiParams[i] != nullptr; ++i) {
|
||||
free(apiParams[i]);
|
||||
}
|
||||
}
|
||||
delete[] apiParams;
|
||||
|
||||
for (size_t i = 0; providerParams[i] != nullptr; ++i)
|
||||
if (providerParams)
|
||||
{
|
||||
free(providerParams[i]);
|
||||
for (size_t i = 0; providerParams[i] != nullptr; ++i) {
|
||||
free(providerParams[i]);
|
||||
}
|
||||
}
|
||||
delete[] providerParams;
|
||||
}
|
||||
|
||||
std::string stringify() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Device: " << sensorType << ", Implexor: "
|
||||
<< (implexor ? implexor : "NULL") << ", API: "
|
||||
<< (api ? api : "NULL") << ", API Params: (";
|
||||
if (apiParams)
|
||||
{
|
||||
for (size_t i = 0; apiParams[i] != nullptr; ++i)
|
||||
{
|
||||
os << apiParams[i] << (apiParams[i + 1] == nullptr ? "" : " ");
|
||||
}
|
||||
}
|
||||
os << "), Provider: " << (provider ? provider : "NULL")
|
||||
<< ", Provider Params: (";
|
||||
if (providerParams)
|
||||
{
|
||||
for (size_t i = 0; providerParams[i] != nullptr; ++i)
|
||||
{
|
||||
os << providerParams[i] << (providerParams[i + 1] == nullptr ? "" : " ");
|
||||
}
|
||||
}
|
||||
os << "), Device Selector: "
|
||||
<< (deviceSelector ? deviceSelector : "NULL") << std::endl;
|
||||
|
||||
return os.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
char sensorType;
|
||||
@@ -93,6 +133,12 @@ struct CSenseDeviceSpec
|
||||
char *deviceSelector;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const CSenseDeviceSpec& spec)
|
||||
{
|
||||
os << spec.stringify();
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user