IOT-897:OCRepresentation can check attribute type
[platform/upstream/iotivity.git] / resource / include / OCRepresentation.h
index 687b64c..4d1d24a 100644 (file)
@@ -168,8 +168,16 @@ namespace OC
 
                 if(x!= m_values.end())
                 {
-                    val = boost::get<T>(x->second);
-                    return true;
+                    try
+                    {
+                        val = boost::get<T>(x->second);
+                        return true;
+                    }
+                    catch (boost::bad_get& e)
+                    {
+                        val = T();
+                        return false;
+                    }
                 }
                 else
                 {
@@ -193,7 +201,14 @@ namespace OC
                 auto x = m_values.find(str);
                 if(x != m_values.end())
                 {
-                    val = boost::get<T>(x->second);
+                    try
+                    {
+                        val = boost::get<T>(x->second);
+                    }
+                    catch (boost::bad_get& e)
+                    {
+                        return val;
+                    }
                 }
                 return val;
             }
@@ -250,7 +265,15 @@ namespace OC
                     template<typename T>
                     T getValue() const
                     {
-                        return boost::get<T>(m_values[m_attrName]);
+                        try
+                        {
+                            return boost::get<T>(m_values[m_attrName]);
+                        }
+                        catch (boost::bad_get& e)
+                        {
+                            T val = T();
+                            return val;
+                        }
                     }
 
                     std::string getValueToString() const;