Exemple #1
0
int _getClass(const int argc, const char **argv)
{
  if (argv[0]==0)
  {
    cerr << "Usage: cimop getClass|gc <class>" << endl;
    return 1;
  }

  CIMClass cldef;
  try
  {
    cldef = _c.getClass( _nameSpace, argv[0] );
  }
  catch (Exception& e)
  {
    cerr << /* "getClass: " << */ e.getMessage() << endl;
    return 1;
  }

  // Display the class definition
  // without qualifiers, for the moment

  // First the class name and superclass
  cout << "class " << cldef.getClassName().getString() << " : "
    << cldef.getSuperClassName().getString() << endl;
  cout << "{" << endl;
  
  // Now the properties
  // No qualifiers except [key], but specify type, array
  for (int i=0; i<cldef.getPropertyCount(); i++)
  {
    CIMProperty p = cldef.getProperty(i);
    cout << "  ";
    // output key, if required
    if (_isKey(p)) cout << "[ Key ] ";
    // prepare to output type, but
    // first, if type is "reference", find target class
    if (p.getType() == CIMTYPE_REFERENCE)
      cout << p.getReferenceClassName().getString() << " REF ";
    // output type
    else cout << cimTypeToString(p.getType()) << " ";
    // output name
    cout << p.getName().getString();
    // output array, if required
    if (p.isArray()) cout << "[]";
    // final eol
    cout << ";" << endl;
  }
  
  // need to do methods
  for (int i=0; i<cldef.getMethodCount(); i++)
  {
    CIMMethod m = cldef.getMethod(i);
    // output type
    cout << "  " << cimTypeToString(m.getType()) << " ";
    // output name
    cout << m.getName().getString() << "(";
    // output parameters
    // new line if there are any parameters
    for (int j=0; j<m.getParameterCount(); j++)
    {
      CIMParameter p = m.getParameter(j);
      // output IN/OUT qualifiers on a fresh line
      cout << endl << "    [ ";
      // loop through qualifiers looking for IN, OUT
      for (int k=0; k<p.getQualifierCount(); k++)
      {
        // when one found, output its value
        CIMQualifier q = p.getQualifier(k);
        if (q.getName().equal("in") ||
            q.getName().equal("out"))
        {
          cout << q.getName().getString() << " ";
        }
      }
      // Now the type
      cout << "] " << cimTypeToString(p.getType()) << " ";
      // finally the name
      cout << p.getName().getString();
      // array brackets
      if (p.isArray()) cout << "[]";
      // closing , on parameter if not last
      if (j != m.getParameterCount()-1) cout << ",";
    }
    // after last param, indent before closing paren

    // close paren
    cout << ")";
    // if (m.isArray()) cout << "[]";
    // finish output
    cout << ";" << endl;
  }
  
  // final brace and done
  cout << "};" << endl;

  return 0; 
}