示例#1
0
CClass* CDecodeFlowType::readClassType ( const QDomElement& element)
{
  bool bOk = false;
  CClass* cl = NULL;
  
  QDomElement id = element.firstChildElement("id");
  QDomElement name = element.firstChildElement("name");
  QDomElement definition = element.firstChildElement("definition");
  QDomElement readOnly = element.firstChildElement("read-only");
  QDomElement values = element.firstChildElement("values");
  QDomElement type = element.firstChildElement("type");

  switch (type.text().toInt())
  {
    case CClass::VOID:
    {
      CVoid* v = new CVoid(name.text(), definition.text());
      v->setId(id.text().toInt(&bOk));
      v->setReadOnly((readOnly.text().toInt(&bOk)));
      cl = v;
      bOk = true;
    }
      break;
      
    case CClass::ENUMERATION:
    {
      CEnumeration* e = new CEnumeration(name.text(), definition.text());
      e->setId(id.text().toInt(&bOk));
      e->setReadOnly((readOnly.text().toInt(&bOk)));
      QDomElement data = values.firstChildElement("string");
      while (!data.isNull())
      {
        e->append(data.text());
        data = data.nextSiblingElement("string");
      }
      bOk = true;
      cl = e;
    }
      break;
    
    case CClass::NUMBER:
    {
      CNumber* n = new CNumber(name.text(), definition.text());
      n->setId(id.text().toInt(&bOk));
      n->setReadOnly((readOnly.text().toInt(&bOk)));
      QDomElement range = values.firstChildElement("range");
      if (!range.isNull())
      {
        Range r;
        r.begin = range.attribute("begin").toLongLong(&bOk);
        if (!bOk)
        {
          // try with uLongLong
          r.begin = range.attribute("begin").toULongLong(&bOk);
        }
        r.end = range.attribute("end").toLongLong(&bOk);
        if (!bOk)
        {
          // try with uLongLong
          r.end = range.attribute("end").toULongLong(&bOk);
        }
        r.beginName = range.attribute("begin-name");
        r.endName = range.attribute("end-name");
        n->insertRange(r);
        bOk = true;
      }
      else 
        bOk = false;
      
      cl = n;
    }
      break;
    
    case CClass::FLOAT:
    {
      CFloat* f = new CFloat(name.text(), definition.text());
      f->setId(id.text().toInt(&bOk));
      f->setReadOnly((readOnly.text().toInt(&bOk)));
      QDomElement range = values.firstChildElement("range");
      if (!range.isNull())
      {
        Range r;
        r.begin = range.attribute("begin").toDouble(&bOk);
        r.end = range.attribute("end").toDouble(&bOk);
        r.beginName = range.attribute("begin-name");
        r.endName = range.attribute("end-name");
        f->insertRange(r);
        bOk = true;
      }
      else 
        bOk = false;
      
      cl = f;
    }
      break;
      
    case CClass::CHAR:
    {
      CChar* c = new CChar(name.text(), definition.text());
      c->setId(id.text().toInt(&bOk));
      c->setReadOnly((readOnly.text().toInt(&bOk)));
      QDomElement range = values.firstChildElement("range");
      if (!range.isNull())
      {
        Range r;
        r.begin = range.attribute("begin").toInt(&bOk);
        r.end = range.attribute("end").toInt(&bOk);
        r.beginName = range.attribute("begin-name");
        r.endName = range.attribute("end-name");
        c->insertRange(r);
        bOk = true;
      }
      else 
        bOk = false;
      
      cl = c;
    }
      break;
      
    case CClass::STRING:
    {
      CString* s = new CString(name.text(), definition.text());
      s->setId(id.text().toInt(&bOk));
      s->setReadOnly((readOnly.text().toInt(&bOk)));
      QDomElement size = values.firstChildElement("size");
      if (!size.isNull())
      {
        s->setSize(size.text().toInt(&bOk));
        bOk = true;
      }
      else 
        bOk = false;
      
      cl = s;
    }
      break;
      
    case CClass::AGGREGATION:
    {
      CStructure* s = new CStructure(name.text(), definition.text());
      s->setId(id.text().toInt(&bOk));
      s->setReadOnly((readOnly.text().toInt(&bOk)));
      QDomElement structure = values.firstChildElement("structure");
      while (!structure.isNull() && !bOk)
      {
        Structure st;
        st.name = structure.attribute("name");
        st.classId = structure.attribute("type").toInt(&bOk);
        st.pClass = NULL;
        if (bOk == true)
        {
          s->insertField(st);
        }
        structure = structure.nextSiblingElement("structure");
      }      
      cl = s;
    }
      break;
      
    default:
      bOk = false;
      break;
  }
  
  if ((bOk == false) & (cl != NULL))
  {
    delete cl;
    cl = NULL;
  }
  
  return cl;
}