SenseDevSpec: add NULL checks stringify, ostream::<<
This commit is contained in:
@@ -15,33 +15,16 @@ std::vector<std::unique_ptr<ExtrospectorDeviceSpec>>
|
|||||||
std::vector<std::reference_wrapper<SenseDeviceSpec>>
|
std::vector<std::reference_wrapper<SenseDeviceSpec>>
|
||||||
DeviceManager::senseDeviceSpecs;
|
DeviceManager::senseDeviceSpecs;
|
||||||
|
|
||||||
std::ostream& operator<<(
|
|
||||||
std::ostream& os, const SenseDeviceSpec& spec)
|
|
||||||
{
|
|
||||||
os << "Device: " << spec.sensorType << ", Implexor: "
|
|
||||||
<< spec.implexor << ", API: " << spec.api
|
|
||||||
<< ", API Params: (";
|
|
||||||
for (auto it = spec.apiParams.begin(); it != spec.apiParams.end(); ++it) {
|
|
||||||
os << *it << (it + 1 == spec.apiParams.end() ? "" : " ");
|
|
||||||
}
|
|
||||||
os << "), Provider: " << spec.provider << ", Provider Params: (";
|
|
||||||
for (auto it = spec.providerParams.begin(); it != spec.providerParams.end(); ++it) {
|
|
||||||
os << *it << (it + 1 == spec.providerParams.end() ? "" : " ");
|
|
||||||
}
|
|
||||||
os << "), Device Selector: " << spec.deviceSelector << std::endl;
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string DeviceManager::stringifyDeviceSpecs(void)
|
const std::string DeviceManager::stringifyDeviceSpecs(void)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
for (const auto& spec : DeviceManager::interoceptorDeviceSpecs) {
|
for (const auto& spec : DeviceManager::interoceptorDeviceSpecs) {
|
||||||
oss << "Interoceptor " << *spec;
|
oss << "Interoceptor " << CSenseDeviceSpec(*spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& spec : DeviceManager::extrospectorDeviceSpecs) {
|
for (const auto& spec : DeviceManager::extrospectorDeviceSpecs) {
|
||||||
oss << "Extrospector " << *spec;
|
oss << "Extrospector " << CSenseDeviceSpec(*spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -23,6 +24,13 @@ struct SenseDeviceSpec
|
|||||||
|
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(
|
||||||
std::ostream& os, const SenseDeviceSpec& spec);
|
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
|
struct InteroceptorDeviceSpec : public SenseDeviceSpec
|
||||||
@@ -70,18 +78,50 @@ struct CSenseDeviceSpec
|
|||||||
free(provider);
|
free(provider);
|
||||||
free(deviceSelector);
|
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;
|
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;
|
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
|
#endif
|
||||||
|
|
||||||
char sensorType;
|
char sensorType;
|
||||||
@@ -93,6 +133,12 @@ struct CSenseDeviceSpec
|
|||||||
char *deviceSelector;
|
char *deviceSelector;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const CSenseDeviceSpec& spec)
|
||||||
|
{
|
||||||
|
os << spec.stringify();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user