/*
**  Copyright (C) 2012 Aldebaran Robotics
**  See COPYING for the license
*/
#include <cstring>

#include <qitype/signature.hpp>

namespace qi {

bool qi::Signature::isConvertibleTo(const qi::Signature& b) const
{
  if (size() != b.size())
    return false;
  static const char numeric[] = "bcCwWiIlLfd";
  static const char container[] = "[{(";
  Signature::iterator s = begin();
  Signature::iterator d = b.begin();
  for (;s!=end() && d!= b.end(); ++s,++d)
  {
    if (d.type() == Type_Dynamic)
      continue; // Dynamic can convert to whatever
    // Main switch on source sig
    if (strchr(numeric, s.type()))
    { // Numeric
      if (!strchr(numeric, d.type()))
        return false;
    }
    else if (strchr(container, s.type()))
    { // Container, list or map
      if (d.type() != s.type())
        return false; // Must be same container
      if (!s.children().isConvertibleTo(d.children()))
        return false; // Just check subtype compatibility
    }
    else
      if (d.type() != s.type())
        return false;
  }
  assert(s==end() && d==b.end()); // we allready exited on size mismatch
  return true;
}

Signature Signature::fromType(Signature::Type t)
{
  char res[2] = { (char)t, 0};
  return Signature(res);
}

}

/*
**  Copyright (C) 2012 Aldebaran Robotics
**  See COPYING for the license
*/
#include <cstring>

#include <qitype/signature.hpp>

namespace qi {

bool qi::Signature::isConvertibleTo(const qi::Signature& b) const
{
  if (size() != b.size())
    return false;
  static const char numeric[] = "bcCwWiIlLfd";
  static const char container[] = "[{";
  Signature::iterator s = begin();
  Signature::iterator d = b.begin();
  for (;s!=end() && d!= b.end(); ++s,++d)
  {
    if (d.type() == Type_Dynamic)
      continue; // Dynamic can convert to whatever
    // Main switch on source sig
    if (strchr(numeric, s.type()))
    { // Numeric
      if (!strchr(numeric, d.type()))
        return false;
    }
    else if (strchr(container, s.type()))
    { // Container, list or map
      if (d.type() != s.type())
        return false; // Must be same container
      if (!s.children().isConvertibleTo(d.children()))
        return false; // Just check subtype compatibility
    }
    else
      if (d.type() != s.type())
        return false;
  }
  assert(s==end() && d==b.end()); // we allready exited on size mismatch
  return true;
}

Signature Signature::fromType(Signature::Type t)
{
  char res[2] = { (char)t, 0};
  return Signature(res);
}

}

--- 
+++ 
@@ -13,7 +13,7 @@
   if (size() != b.size())
     return false;
   static const char numeric[] = "bcCwWiIlLfd";
-  static const char container[] = "[{";
+  static const char container[] = "[{(";
   Signature::iterator s = begin();
   Signature::iterator d = b.begin();
   for (;s!=end() && d!= b.end(); ++s,++d)
Signature::isConvertibleTo: Fix a lolbug, it never worked and returned true always.

Change-Id: I93ae42a1b36d175311b940af0baf9a4e3b61f83a
Reviewed-on: http://gerrit.aldebaran.lan:8080/7221
Reviewed-by: cgestes <ddb78fe00abb42f91254c16a0860e38eb0781789@aldebaran-robotics.com>
Tested-by: mnottale <e3ccf1b6558404e921a21fa09cebb1153b50ec36@aldebaran-robotics.com>
