Salome HOME
Merge remote-tracking branch 'origin/master' into V9_dev
[modules/yacs.git] / src / engine / TypeCode.cxx
index fb1f7dacc295cb09e7b07633296a15aaf7b23a6d..f7c4774474b2a1a5575d51a67074d753ee8306ef 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -139,6 +139,11 @@ int TypeCode::isAdaptable(const TypeCode* tc) const
     }
 }
 
+std::string TypeCode::getPrintStr() const
+{
+  return id();
+}
+
 //! Check if this TypeCode can be used in place of tc
 /*!
  * this TypeCode is equivalent to tc if they have the same kind
@@ -200,6 +205,23 @@ const char *TypeCode::getKindRepr(DynType kind)
   return KIND_STR_REPR[(int)kind];
 }
 
+const TypeCode *TypeCode::subContentType(int lev) const
+{
+  if(lev<0)
+    throw YACS::Exception("subContentType: Invalid input val !");
+  if(lev==0)
+    return this;
+  const TypeCode *ret(this);
+  for(int i=0;i<lev;i++)
+    {
+      const TypeCode *cand(ret->contentType());
+      if(!cand)
+        throw YACS::Exception("subContentType : Invalid input val 2 !");
+      ret=cand;
+    }
+  return ret;
+}
+
 const char * TypeCode::getKindRepr() const
 {
   return KIND_STR_REPR[(int)_kind];
@@ -447,6 +469,12 @@ const char * TypeCodeSeq::shortName() const
   return _shortName.c_str();
 }
 
+std::string TypeCodeSeq::getPrintStr() const
+{
+  std::ostringstream oss; oss << "seq[" << contentType()->getPrintStr() << "]";
+  return oss.str();
+}
+
 const TypeCode * TypeCodeSeq::contentType() const throw(YACS::Exception)
 {
   return _content;
@@ -719,8 +747,17 @@ int TypeCodeStruct::isA(const TypeCode* tc) const
  */
 int TypeCodeStruct::isAdaptable(const TypeCode* tc) const
 {
-  if(_kind == tc->kind()) return isA(tc->id());
-  return 0;
+  if (_kind != tc->kind()) return 0;
+  if (_repoId == tc->id()) return 1;
+  int nMember = memberCount();
+  if (nMember != ((TypeCodeStruct*)tc)->memberCount()) return 0;
+  for (int i=0 ; i<nMember ; i++)
+    {
+      const char * name = memberName(i);
+      if (strcmp(memberName(i), ((TypeCodeStruct*)tc)->memberName(i)) != 0) return 0;
+      if (!memberType(i)->isAdaptable(((TypeCodeStruct*)tc)->memberType(i))) return 0;
+    }
+  return 1;
 }
 
 //! Check if this TypeCode can be used in place of tc