<< rep2.numberOfAttributes() << std::endl;
+ if(rep.isNULL("nullAttribute"))
+ {
+ std::cout << "\tnullAttribute is null." << std::endl;
+ }
+ else
+ {
+ std::cout << "\tnullAttribute is not null." << std::endl;
+ }
+
rep.getValue("light", myGarage.m_lightRep);
myGarage.m_lightRep.getValue("states", myGarage.m_lightStates);
m_garageRep.setValue("state", m_state);
m_garageRep.setValue("name", m_name);
+ // For demonstration purpose we are setting x to nullptr here.
+ // In reality it may happen else where.
+ int* x = nullptr;
+
+ // Check for nullptr and set null for that attribute
+ if(x == nullptr)
+ {
+ m_garageRep.setNULL("nullAttribute");
+ }
+
for(int i = 0; i <= 9; i++)
{
m_lightStates.push_back(i % 2 == 0);
#include <boost/variant.hpp>
#include "ocstack.h"
+#include <OCException.h>
namespace OC
{
return m_attributeMap.find(str) != m_attributeMap.end();
}
+ void setNULL(const std::string& str)
+ {
+ m_attributeMap[str] = "null";
+ }
+
+ bool isNULL(const std::string& str) const
+ {
+ auto x = m_attributeMap.find(str);
+
+ if(m_attributeMap.end() != x)
+ {
+ return x->second.compare("null") == 0;
+ }
+ else
+ {
+ std::ostringstream message;
+ message << "attribute: " << str << " doesn't exist\n";
+ throw OCException(message.str());
+ }
+
+ return false;
+ }
+
int numberOfAttributes() const
{
return m_attributeMap.size();
};
typedef boost::variant<
- // TODO NULL value to be implmented.
int,
double,
bool,
}
else
{
- // TODO Logging
- std::cout << "Array type should have atleast []\n";
+ throw OCException("Array type should have at least []");
}
}
}
else
{
- // TODO Logging
- std::cout << "Array type should have atleast []\n";
+ throw OCException("Array type should have at least []");
}
}
}
else
{
- // TODO Logging
- std::cout << "Array type should have atleast []\n";
+ throw OCException("Array type should have at least []");
}
}
}
else
{
- // TODO Logging
- std::cout << "Array type should have atleast []\n";
+ throw OCException("Array type should have at least []");
}
}
}
catch(boost::property_tree::json_parser::json_parser_error &e)
{
- //TODO: log this
- std::cout << "Parse error\n";
- return;
+ throw OCException("JSON parse error");
}
for(auto& item: payload)